|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
% I' T4 O, [0 R: s& YTo query for an Item and retrieve its structure you build the query as the structure
+ c. l; [3 w+ C5 O" s- ^you want returned. Use the IOM methods to add the relationships you want and
" s2 M0 r/ e ~6 x9 f. t7 Obuild the structure in the Item. The server will return the structure that follows the v5 d: j }$ J) h
request structure. 8 }0 {. S: H1 }9 M. _/ E. S1 h
This recipe illustrates several related concepts together, which are how to get a set 8 X2 V5 g! E3 a" c( P# q1 _
of Items from an Item and how to iterate over the set, plus how to get the related 5 h9 P$ |1 w* }3 _
Item from the relationship Item.
% ^* m$ Q7 L6 ?" yJavaScript * l5 i, g5 m& W2 E+ @, j" k
var innovator = this.newInnovator(); 3 P0 M/ g( M4 n) u# s5 |5 }
5 X( e0 o/ N% G) O
// Set up the query Item. y; J/ d5 K% }: f- j
var qryItem = this.newItem("Part","get"); / m+ x0 l4 D$ |! ^4 H- ^
qryItem.setAttribute("select","item_number,description,cost"); 0 N! I: S8 m6 m% l/ B. D8 S
qryItem.setID(myId);
* M6 S7 q1 b. S: L) r7 e8 h 3 D9 i' r' s: q
// Add the BOM structure. / ^; b( u4 E; E
var bomItem = this.newItem("Part BOM","get"); * V" U- r' v# n3 W# y
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
+ d: | c6 w( ^$ q ]$ V3 zqryItem.addRelationship(bomItem);
& G- M$ ^: W' H, | : I, y# y! ]- _, G6 O/ g. ]
// Perform the query.
r$ W- P) z2 a8 J! d; Yvar results = qryItem.apply();
8 B0 e9 s; `& I+ t
& F9 G, L; z* l* R# s+ \; ~5 ?, l) o// Test for an error.
/ f! l5 J3 x$ p) Dif (results.isError()) {
! F( @0 |% |% }/ i" f top.aras.AlertError("Item not found: " + results.getErrorDetail()); - T9 k7 n1 D, l- `; \' \+ e# ^3 }
return; ( j* G$ P$ t$ J- g
} 1 x, B$ r3 y/ p& ?, @" A$ g X% R
2 I) C9 L$ y9 d" M. t( a3 q$ F// Get a handle to the BOM Items. * ]$ u4 f Y0 s. G& U% f8 b0 ~
var bomItems = results.getRelationships();
3 x% [% u5 C1 Z4 u! ?) cvar count = bomItems.getItemCount(); 6 }5 e+ {+ H/ t% x) n; v
; u' s+ `* _) @// Create the results content.
* n# {0 y4 o8 v- a$ Z# [var content = "<table border='1'>" + + Y5 L2 t$ ^' j3 U+ C3 ]
"<tr>" + 4 U2 C, r) D5 P; s
"<td>Part Number</td>" + " m5 ]1 V3 I$ t% F+ P& Q$ T
"<td>Description</td>" +
" r+ ?, }; c. a" Z; f "<td>Cost</td>" +
/ C% a5 o. _& w* ^: ?7 g4 B- Q "<td>Quantity</td>" +
& c7 k0 ]: g; a3 L/ o. W "</tr>";
0 n. [6 J: n+ ?$ s( k5 E% Q 5 t' b6 w% s2 n- j$ t- y
// Iterate over the BOM Items. 5 v4 W8 i8 l, G W
for (var i=0; i<count; ++i) `- d: E; @4 j& ]5 v
{
8 C' X7 c B$ }8 S4 `2 o0 T& _0 Z& V// Get a handle to the relationship Item by index. / A- C. O, d5 A9 c& O( I/ ]
var bom = bomItems.getItemByIndex(i);
& ^4 h" W1 r& q// Get a handle to the related Item for this relationship Item. # n* a* ~1 b' w9 n! j
var bomPart = bom.getRelatedItem(); + l b& B6 R( Z, F
: c6 V" P" e2 P content += "<tr>" +
8 l7 Y8 v5 e/ u "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 W% ^9 m! j4 Q! a7 I9 C. m: O' B "<td>" + bomPart.getProperty("description") + "</td>" +
1 }/ t1 T, [- l2 Q5 t "<td>" + bomPart.getProperty("cost") + "</td>" +
7 N2 s1 v, o8 t7 C3 j0 b' c7 f. i "<td>" + bom.getProperty("quantity") + "</td>" +
' o& F+ |6 n3 l4 h W4 o "</tr>"; 1 U( C( O; {! x7 O4 ^
}
1 H Y0 H* Z* n+ f2 Qreturn content + "</table>";# j, b9 X' @% G, z
6 B3 r7 J0 J+ P; u
* G7 q5 | M2 g
2 O' K1 Q& S( C+ J; ]- [! D+ V: G& [1 |/ Y
C# + ]* n9 ~* |) E s# s' ]6 K4 M2 B
Innovator innovator = this.newInnovator();
6 {" E: F+ B* D
5 i! s1 r! D; \0 O% x \7 e* N// Set up the query Item. & z, Z. ?4 [* w8 Y
Item qryItem = this.newItem("Part","get");
! W/ v4 o( w4 W3 B& ~; `! SqryItem.setAttribute("select","item_number,description,cost"); - L; K) T; x$ a$ ~
qryItem.setID(myId); ( ^. q4 O3 q p* H+ G2 Z* D
! [' u5 u$ }9 m! }& z* H; g
// Add the BOM structure.
1 x; E Z, R, p% o o& lItem bomItem = this.newItem("Part BOM","get"); / j0 H5 g$ y3 `( W8 R
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 0 e5 V# q: b8 H$ Q2 T. W# S+ v. i
qryItem.addRelationship(bomItem); : G( A- s# N8 @
, h, U1 h& ^. a$ k7 C" Q4 P
// Perform the query. 4 R: \, e( v& Y, O4 k E
Item results = qryItem.apply(); $ Q' s% Y7 D0 q$ a( s8 I2 y
. {+ ^8 H* D$ b
// Test for an error.
7 J; ^! _- e& M' K) p) B6 Dif (results.isError()) { 9 V4 p3 M: u& l4 o. D/ J
return innovator.newError("Item not found: " + results.getErrorDetail());
6 R; [& J8 k* a z} Q/ n+ F* Q- u
( ?0 }2 M( D' q( q
// Get a handle to the BOM Items. 6 i& C9 h- W( U
Item bomItems = results.getRelationships(); 4 @+ B- F+ p) T% D5 k
int count = bomItems.getItemCount();
9 d" i/ J* R$ @7 w& t; C4 Mint i;
% ^# q) ]" u2 i, L) Q
! { a% I3 q/ S5 L+ j) E// Create the results content.
+ r$ g- v" J% E# p2 U; U4 Estring content = "<table border='1'>" + 7 a& s% j6 t3 B8 s6 \8 b( X0 O
"<tr>" + 9 [8 E. V l5 N6 y6 K1 [
"<td>Part Number</td>" + / x+ M/ ~: h$ V
"<td>Description</td>" +
& U4 n0 R$ R6 Q. z "<td>Cost</td>" + ! a% w1 {: J- L/ ]- |6 o2 C: K& K
"<td>Quantity</td>" +
6 Z4 w( `8 O! Y2 t/ B; K& H "</tr>";
! u5 n. Y$ k% a 5 G5 r) W5 I& _6 Y8 } ]4 c
// Iterate over the BOM Items.
/ W& r1 D9 U4 m) }' rfor (i=0; i<count; ++i)
4 p. ?; W" ]6 r2 _8 R# P. f. y{
) b4 Y' n3 [) A; C2 N. J// Get a handle to the relationship Item by index.
' e) v2 n/ j3 d1 r' [6 t8 S4 |/ G Item bom = bomItems.getItemByIndex(i);
% g) k P6 r' A, \' g' b# _// Get a handle to the related Item for this relationship Item. , [$ ?9 r. z: v4 `1 I
Item bomPart = bom.getRelatedItem(); 6 B% }! R. k' b; |' d( O* L- Y
, k* _$ d) g6 z/ h content += "" +
$ z7 B& F! P3 a% ~4 M6 O "<tr>" +
+ K: G& K: i J; }/ ~5 s8 X "<td>" + bomPart.getProperty("item_number") + "</td>" +
0 t( q3 ~4 g+ O2 \, T/ E: \ "<td>" + bomPart.getProperty("description") + "</td>" +
/ I7 P) W; }; o "<td>" + bomPart.getProperty("cost") + "</td>" + - ?- _) d8 Z, N3 K- k5 `# o
"<td>" + bom.getProperty("quantity") + "</td>" + 7 a- _8 i) g% W& ?/ a* W
"</tr>"; # G/ X. I; s; k, o6 W2 T
} 5 x5 T) g$ y8 y$ o( [# Z
content += "</table>";
# ^; r2 r6 `$ i& j% b9 U
, g' T% H& |! @, greturn innovator.newResult(content); 6 H7 Z: l- v; X
* |% {1 W& R$ x! H4 a2 v9 x
" o) d q, e9 p7 [, l- V6 C& @
- b& ?! m0 I0 Y
1 }" e( e5 ]: k, p5 k- e5 N3 [, g/ s7 g5 R
% U9 J+ G5 e% V0 y
- q ]6 K* S) X& K' F" t |! ~ Page 46
9 U0 `! D# r% m: ~ `* v
1 S6 B8 u* K+ w, X0 jCopyright 2007
# H: k: [+ ^3 q. Q1 I4 r. d& Z4 AAras Corporation.
7 d; [3 L6 R m. |1 Y* i6 Q; d+ ~0 UAll Rights Reserved. / ?7 V6 ?* y9 J
VB.Net 0 d; [2 q* R `9 L
Dim innovator As Innovator = Me.newInnovator()
C- i3 T3 m( V , D- \, Q9 Q$ G3 }, W
' Set up the query Item. ) s, Q7 J! t+ W8 s& p/ n
Dim qryItem As Item = Me.newItem("Part","get")
, g" g* v6 K0 a& x( n, wqryItem.setAttribute("select","item_number,description,cost") " }0 ]5 z. ^$ G" M3 L/ q4 ^" |
qryItem.setID(myId)
: W- Q" h* ^- R
4 m2 C+ P+ V: v4 ~5 J* c' Add the BOM structure.
1 T$ p7 `4 I: mDim bomItem As Item = Me.newItem("Part BOM","get")
9 E9 w; m, A& |4 mbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
1 j9 I; k8 o a3 XqryItem.addRelationship(bomItem) " _ i% n" Y+ S' m9 J
0 w, n, w: j8 ], R* P4 o' Perform the query. 4 J" ^2 N. _7 l5 U
Dim results As Item = qryItem.apply()
; {6 ^5 ?- \( _+ F% I & J; R7 f0 o, A$ O/ o. E5 U9 u/ I
' Test for an error. * Y& U- L9 o4 `! F6 U e: f$ u
If results.isError() Then 2 M2 I, ?/ e. m3 m# Z. ]' V
Return innovator.newError(results.getErrorDetail())
7 }/ ?! y1 d+ Y- ]End If 5 ^# _9 h$ y( z
. k7 W; O6 g/ e$ `( o/ X0 [' d' Get a handle to the BOM Items.
, P# [# @. ~% G2 I) t6 }Dim bomItems As Item = results.getRelationships()
; h% w3 z; L6 l+ s/ p) aDim count As Integer = bomItems.getItemCount()
/ G# m8 }! \, T$ {7 ?1 LDim i As Integer
- p0 S+ h- m( k/ K/ Q" ] . @+ j* z( _/ S
' Create the results content. 1 @$ @. E5 J* b0 K9 P
Dim content As String = "<table border='1'>" + _ / `! ?/ R# \ U# I' z8 w! W
"<tr>" + _ * a2 d- \; F: \' Y" c
"<td>Part Number</td>" + _
8 N, x6 T, h; ~! K/ N "<td>Description</td>" + _ & J+ m% u: T3 u" m: p( M' e* E8 _
"<td>Cost</td>" + _ * u, p0 {! z& X+ ^ ]" h
"<td>Quantity</td>" + _
* E/ F" y$ D3 ]' {. ^% x: R* I "</tr>" , |, V$ h! L; m/ M H c8 X
3 i+ Z- e# p5 V' Iterate over the BOM Items
4 l9 s; O* V- q+ {! sFor i = 0 To count - 1 4 B3 Y' k; [7 f2 o/ |7 N' y
' Get a handle to the relationship Item by index.
5 m, J+ [2 I- m$ q; y. w; ~ Dim bom As Item = bomItems.getItemByIndex(i) ' D% |5 M3 v$ s# [: k7 L+ q8 J
: W/ l% ?0 U# f% |/ u. ?8 P2 v) y* s5 ^' Get a handle to the related Item for this relationship Item.
0 W% M) o, [: S. o$ H Dim bomPart As Item = bom.getRelatedItem() 5 r |' g1 z/ w5 V$ ^( m2 {
8 X; x0 p9 ^/ Q
content += _
2 h4 A% D- T4 N4 K% k4 v. i! b "<tr>" + _
/ e0 H2 X; ]' Q* _$ D5 a "<td>" + bomPart.getProperty("item_number") + "</td>" + _ / K3 K* D5 e! i* _& t6 h8 S4 _8 q
"<td>" + bomPart.getProperty("description") + "</td>" + _ 4 H6 j- U" f+ G4 Z! c1 @, \
"<td>" + bomPart.getProperty("cost") + "</td>" + _
% K) L) h0 t; Y# x. s: K$ Y' f "<td>" + bom.getProperty("quantity") + "</td>" + _
& s: L/ `$ E& Q3 H4 W "</tr>"
' L, m2 ]# t- i. D. t9 d. \ oNext
6 P: B9 k+ p$ T3 B; L j9 x9 zcontent += "</table>" . ] l* l) l( B5 Q8 P1 L) B
8 `8 u, H D4 D8 F) K. ~Return innovator.newResult(content) 7 Q' J" F+ k: y: d/ ?2 {. A
9 M1 T6 V. O# b, B% w* ?7 |
|
|