|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ( C2 U+ m9 _3 k! V0 }' N5 B
To query for an Item and retrieve its structure you build the query as the structure
* S8 I% e+ K3 E% r) F2 e% J Zyou want returned. Use the IOM methods to add the relationships you want and 6 ^0 Z- q3 G: n9 y5 \8 g
build the structure in the Item. The server will return the structure that follows the
% T5 \ ^! |- ?+ N' E. E7 c, J; p$ O, Brequest structure.
. |( x5 y% N t' C& RThis recipe illustrates several related concepts together, which are how to get a set
3 ?% w' v6 d( U9 }of Items from an Item and how to iterate over the set, plus how to get the related 1 l x4 V- s* z3 M: Z+ ]$ E) h
Item from the relationship Item.
# w O) ^ Q& J0 U. M8 w/ MJavaScript 1 ?9 h! _' ? x5 J: ?
var innovator = this.newInnovator();
& ^& M, u9 ~, H3 x2 @. I * J9 D: a" ?& ]- Q
// Set up the query Item.
- P# U! I* R, j0 J$ `( J6 Kvar qryItem = this.newItem("Part","get");
; [) q& D# j$ d6 ?8 E: S) nqryItem.setAttribute("select","item_number,description,cost"); ' S* J( r6 \1 P$ C
qryItem.setID(myId); 5 E, t1 c* S) z8 u& W
2 N j- h0 Y, \: t8 Z# I// Add the BOM structure.
+ K3 \5 r9 N4 R3 c# f( |var bomItem = this.newItem("Part BOM","get"); ( q9 b. g$ ?8 Y( K* c
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 8 h9 T h' l; _2 x0 ?. A
qryItem.addRelationship(bomItem);
5 M& |, ?2 }) E9 e4 D& G0 X! N+ }
7 [ Z' a4 w' L: k1 _// Perform the query.
! z g7 J) G# a4 G+ l' i0 P% Jvar results = qryItem.apply();
/ I1 h% U9 l; b# m; C; x + \- R- {+ S2 v
// Test for an error. 9 H$ M8 p4 `" M* S) d! @
if (results.isError()) { . g3 v: m& r3 P3 Y4 \) p0 `8 b
top.aras.AlertError("Item not found: " + results.getErrorDetail());
4 |0 U, N D9 D9 w3 f g5 r return;
$ J# J5 x0 @; E ~3 l% D- K}
1 [6 K) a( o1 C9 w! @; i
9 Y0 Y0 N" x3 T+ v) K5 u9 w$ W9 m// Get a handle to the BOM Items.
# T9 c" y: n. R# k+ q# `var bomItems = results.getRelationships();
5 h2 c; R3 m/ p! b' T* L* K- svar count = bomItems.getItemCount(); 8 v8 S: V# N: R$ u5 H9 _- f
! S& `% [; u, V+ \
// Create the results content.
1 s! b! d. s" k8 |var content = "<table border='1'>" +
% w8 ~7 e$ M% i" `! b "<tr>" + 6 z2 B3 t! @5 C4 h6 v
"<td>Part Number</td>" +
+ u- }$ J* [4 J; X( w$ V "<td>Description</td>" +
! @5 L; I8 r3 H "<td>Cost</td>" + 4 ?( ]% N- b" M# e" v& E
"<td>Quantity</td>" + 7 |3 X. j) e; ?9 y, y v7 S9 t
"</tr>";
# f, ^7 d! H5 K
. k" x s' [. c" a1 O2 S// Iterate over the BOM Items.
8 c7 \; F- C4 j5 p; m' ~for (var i=0; i<count; ++i)
3 t" s6 {4 ?8 @- ]! J{ 1 ?; ~6 u5 j' A3 a# l- [
// Get a handle to the relationship Item by index. * e2 |2 ]* N: c4 I
var bom = bomItems.getItemByIndex(i);
6 M# A4 w# G$ w: a8 s// Get a handle to the related Item for this relationship Item. % g5 ]3 n/ M7 H) p* R( M% ]
var bomPart = bom.getRelatedItem(); , U/ T, @8 Z* b, @ E6 `* Y# L( c' ?
5 m% m6 Q4 U8 Y/ U, }6 i9 H content += "<tr>" +
7 I/ _( k: L& K' c "<td>" + bomPart.getProperty("item_number") + "</td>" + ! K$ q$ B, k; k% E u7 P3 |
"<td>" + bomPart.getProperty("description") + "</td>" + - }6 v; o, w8 [$ H% M, ~
"<td>" + bomPart.getProperty("cost") + "</td>" + " A$ Q- S/ _2 q9 `# z
"<td>" + bom.getProperty("quantity") + "</td>" +
% Q! x: d7 o* _% s% }) _! d, U! Q "</tr>"; # D7 t5 C! S% b4 d. R9 X( ]
}
1 y) V6 h7 a6 G8 Z/ x! N h7 u! ]5 Dreturn content + "</table>";; v5 |1 n& U; h) h/ Q! d$ s
# w5 W# Y2 V- D
) U0 g0 h3 g7 A8 `; Y! f# {
: A; b* {5 E: R0 O
" w; V0 v) @/ q9 d5 F3 sC# . Q9 h* V+ i* w# o8 b
Innovator innovator = this.newInnovator(); ; U9 E) Y e5 M1 T" z- z
7 c1 Q! v; }1 d. u, q* y7 u// Set up the query Item.
5 }9 Y; q4 L& o( CItem qryItem = this.newItem("Part","get"); 9 B+ H7 ^$ O: K3 p3 a
qryItem.setAttribute("select","item_number,description,cost"); ( k" o4 i, h3 ] ^1 r S4 s0 T& T
qryItem.setID(myId);
, h3 u k" c$ i9 h
# f4 h4 ~! Z+ N5 w// Add the BOM structure.
8 S" F0 `% P0 {& x9 \6 ]9 ~Item bomItem = this.newItem("Part BOM","get");
2 `( O- O' p: V% n- V6 Z! A, QbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ( E1 i$ Z6 d8 j3 W/ s- p
qryItem.addRelationship(bomItem); & }2 q/ S- A; [! F( A
) k# \/ u" B5 S! Q
// Perform the query.
8 _1 u$ U1 p. |8 nItem results = qryItem.apply(); ; m5 O1 t1 A/ P9 ?9 }
4 r3 E9 c9 g! o2 {8 g/ g0 o// Test for an error.
+ T. k. C5 p+ |* Oif (results.isError()) { ! U3 m! L6 p% h4 |! a: [, t) i
return innovator.newError("Item not found: " + results.getErrorDetail());
$ i' l' n6 F5 @; z$ }- `5 V} 5 r, {4 T" U {- ^3 Z, ^
) x+ Q/ R4 S2 \' u5 }
// Get a handle to the BOM Items. 9 h5 h. }1 R0 p2 t7 Q; i+ C" o
Item bomItems = results.getRelationships(); " r. g1 S' b R- |' z+ \
int count = bomItems.getItemCount();
1 d2 M0 b! ^. E3 jint i; ; D' x. _* f. l3 J/ z u
# q# B* Y( e+ L# z
// Create the results content.
2 y# o8 a) b0 R2 dstring content = "<table border='1'>" + 1 s8 n% a, m+ o' k: @
"<tr>" + 5 }$ X4 M( x) }$ @( N6 ?
"<td>Part Number</td>" +
4 s, q# R# E v0 ] "<td>Description</td>" + - }* w) @& F# k, c
"<td>Cost</td>" + 5 n/ l/ T1 X: p% }. K
"<td>Quantity</td>" +
# b& P0 T0 l. p$ w/ o "</tr>"; / R& c8 C0 E0 D, r
7 a6 {) Z e/ x// Iterate over the BOM Items. b( I/ `5 U ~% b0 v% ~# ?$ @% L
for (i=0; i<count; ++i)
[6 t6 N3 d7 n{ ) x0 e% f& G* B. @9 `
// Get a handle to the relationship Item by index. ; W, t6 c4 v% n% Y2 M$ d" U: N
Item bom = bomItems.getItemByIndex(i);
$ V5 t( H4 v3 `6 E ]$ J9 l// Get a handle to the related Item for this relationship Item.
0 l7 {2 ]6 N2 l3 @ Item bomPart = bom.getRelatedItem();
9 W0 a4 E) D: T9 c2 ]4 d5 W
9 i* U& O5 l) D4 d content += "" + ! h, x X& |9 o) b( y' m) h
"<tr>" + 1 W! X) \" T" W/ ?, B @
"<td>" + bomPart.getProperty("item_number") + "</td>" +
; x& g X% L0 p+ d1 @. x "<td>" + bomPart.getProperty("description") + "</td>" +
" u, F1 i+ g1 S: c "<td>" + bomPart.getProperty("cost") + "</td>" + % a' W' p7 r2 x! A
"<td>" + bom.getProperty("quantity") + "</td>" +
& O9 b, X1 x- _% k( D "</tr>"; m) U; W- ^9 U. D. B& X$ ?& F
}
' c" U0 [2 ?* M; F' A/ h9 Xcontent += "</table>";
$ O$ @/ x* j& Y! K6 M, k+ \" h
1 P* R0 ^' {. {return innovator.newResult(content); - u# M& y. x0 D$ O& b6 ~
$ z- Y$ A# N( [! K& G! W* n! K
! y: _, X3 \6 k% _5 z: K0 L
6 i4 M: f# {/ [9 P1 C% j# E& z8 b! p; O
2 k9 ~0 {8 ^' y* o
0 M" L# o3 @* ~( `7 D* ~
* S8 p0 p8 j7 \6 G% o Page 46
' \* m1 j3 W6 \" v$ r, q7 n % z9 k( F* b- b. r( g: h) P6 h
Copyright 2007
0 v( `1 k8 c( i, y' vAras Corporation.
9 I, `; [4 x$ R$ o, `, \1 \ W( x/ _All Rights Reserved.
3 M* n9 u5 S, J. R3 p8 fVB.Net $ M% M# m! Q6 r z
Dim innovator As Innovator = Me.newInnovator() 3 l S, s8 J l/ V
@- R+ I* p4 G% G, N
' Set up the query Item.
: c: Z" X: y: O4 A* @8 ~Dim qryItem As Item = Me.newItem("Part","get") % O! }! ?% z& `8 E1 k9 W
qryItem.setAttribute("select","item_number,description,cost") 8 s) H, l# p4 _& p$ `8 G3 J+ u
qryItem.setID(myId)
1 e# ]* w% p# |" o % Q) s& n8 X: w# y* j* |- A3 v `
' Add the BOM structure.
) o& R2 Q6 g, L2 Q& b2 K |Dim bomItem As Item = Me.newItem("Part BOM","get")
% @2 K; z% K: }bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
4 J, v, l! o: O6 N: v) l; zqryItem.addRelationship(bomItem) ' D" J/ J6 L) P2 X
6 o, j/ R. w6 {5 E* i6 R6 D' Perform the query. 3 q) t5 V$ y1 u1 ^
Dim results As Item = qryItem.apply() & z5 _$ y6 ?% _0 j1 a- H
! [. H8 v, H6 C( m" x
' Test for an error.
# @% ~6 r# x' \# C# q" ^7 R' FIf results.isError() Then
7 M" e! h) r& y Return innovator.newError(results.getErrorDetail())
7 L1 w% t" K, q) UEnd If
Q% b3 `3 v9 { 7 H, M* F% b2 A/ X/ E
' Get a handle to the BOM Items. 0 \4 {" Z( R0 p- R/ T3 G
Dim bomItems As Item = results.getRelationships() - F6 S+ ]7 X7 U4 Z# x5 S- R
Dim count As Integer = bomItems.getItemCount()
( y' x) D d4 H: ^Dim i As Integer
+ J3 @0 Q1 b. t& A3 W7 \ 1 E- g4 Y, ^" S! t4 i
' Create the results content. # q/ ~) b/ l) p9 v4 D3 D
Dim content As String = "<table border='1'>" + _
; j# j8 _) |; Q, _! ] "<tr>" + _ 6 @% y8 m( X: f: ^3 O- ]7 ^
"<td>Part Number</td>" + _ 4 d( {* B4 x: t! K3 Q Q, n0 F
"<td>Description</td>" + _ % o( M/ S4 [( m( S
"<td>Cost</td>" + _
G2 u/ u/ e# h _# b "<td>Quantity</td>" + _
5 \* T1 L9 B' ]* u3 n' S% u "</tr>"
6 o" [9 `% ]! X# P8 H" |; M
9 Y' p. O k) F' Iterate over the BOM Items
6 t) Q5 v+ l. I5 N& h3 o) oFor i = 0 To count - 1
4 X, N" ]( M1 g1 S) B4 L9 R0 D' Get a handle to the relationship Item by index. 2 O; S5 `' U E: N; j6 r. E8 x. I+ V
Dim bom As Item = bomItems.getItemByIndex(i)
0 X l; }: T w. @ 5 x( Y7 O3 v t% v
' Get a handle to the related Item for this relationship Item.
$ ~; Z$ m# t% U; j; E0 U9 x Dim bomPart As Item = bom.getRelatedItem()
6 M9 g$ b4 q% [
6 k" S$ [; I$ J' U9 q( A- i$ l content += _ 7 W! f& [/ U9 E, s" \, D0 a* V8 A
"<tr>" + _ 3 i1 c+ k( [/ A
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 3 _# P8 A3 g' Q9 k$ C
"<td>" + bomPart.getProperty("description") + "</td>" + _ 1 R. }3 t6 }5 F& r. d& f
"<td>" + bomPart.getProperty("cost") + "</td>" + _
& V+ ~# Z7 Q T "<td>" + bom.getProperty("quantity") + "</td>" + _
; J, O0 c! S/ \ "</tr>"
# P5 t0 o9 N) L0 i' }& MNext
8 C( i: C0 K9 z: M$ Y/ p Ncontent += "</table>" . U3 v2 i) x/ Q+ S
, v H/ r* _/ S3 | M( [+ D, ~8 t
Return innovator.newResult(content) 8 w0 m6 L2 _5 c0 Y
. S3 L% O" x6 y" B v2 V
|
|