|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 1 J! Q6 C7 F7 Q! e4 |3 ]
To query for an Item and retrieve its structure you build the query as the structure , e8 x: ?9 U0 w5 Y
you want returned. Use the IOM methods to add the relationships you want and 9 u; t; j7 i, Z; L" d. O
build the structure in the Item. The server will return the structure that follows the 6 S) p6 `- E0 l1 H$ ~
request structure. / y/ I! |3 o& H5 c+ I/ @
This recipe illustrates several related concepts together, which are how to get a set
# C7 h; w* x1 w' c2 D. Jof Items from an Item and how to iterate over the set, plus how to get the related
9 c2 E) c) x' y, N; [' vItem from the relationship Item. 0 }, `* @( g- u/ t
JavaScript . V* s. M. ~6 `) a
var innovator = this.newInnovator();
0 z4 n/ P; P- ~! A % f6 M5 J+ X+ ^( Q3 {) w3 A! Z
// Set up the query Item.
' W8 g$ N3 r6 o" kvar qryItem = this.newItem("Part","get");
# p0 c/ \ T: Y( w/ I' S7 gqryItem.setAttribute("select","item_number,description,cost"); / N) d1 n8 }. b4 G9 J
qryItem.setID(myId);
8 k- ]) a! K2 k i
$ s$ N& V7 @ g; ~// Add the BOM structure.
+ z% M- [ c& A& pvar bomItem = this.newItem("Part BOM","get"); " {. F, d# O% I$ N3 n" Q
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); * t; W5 L" X O: X4 j7 A( i% L
qryItem.addRelationship(bomItem); 1 D0 I3 {; n& t
7 U3 b3 x" S0 g% z' [0 d, P
// Perform the query.
3 j0 S: {. O+ L/ [% Jvar results = qryItem.apply(); # [2 Q/ E$ O1 ]
/ O7 ^( r6 ]% u' d1 R3 z3 K// Test for an error.
/ H. D7 q. b% q* K9 K# Y8 }if (results.isError()) {
$ [& e* O) n- t: L c top.aras.AlertError("Item not found: " + results.getErrorDetail());
" i! K$ F D( D& B return; Y9 `( h9 n) s& v t
} % i; C- M" g, e/ O
: {/ Q! V* N) a1 ?
// Get a handle to the BOM Items. % i! Q$ v! Y& {7 d6 ?* h2 y
var bomItems = results.getRelationships();
$ o5 w% ~8 g; i! svar count = bomItems.getItemCount();
5 f' m5 S9 C6 E- B n , Q+ x* O( c/ ], ?, O: p
// Create the results content.
s1 y, q1 D4 ^- o; Dvar content = "<table border='1'>" +
2 L3 c/ w+ k1 w8 K5 i$ _+ `: H "<tr>" + . W- y+ U! Z$ u1 p# e
"<td>Part Number</td>" + 4 y# z' t3 |- w% X; }/ g8 L
"<td>Description</td>" +
9 n: U6 T% y4 |+ ` "<td>Cost</td>" +
+ G! {& {& e9 @& U, u "<td>Quantity</td>" + . `$ B. l2 O1 Q% a: a
"</tr>"; / O8 V: Z4 z% X+ X
- v0 g' s- j1 V' G4 ]// Iterate over the BOM Items. ( J4 ^' d( J' B3 G
for (var i=0; i<count; ++i)
7 |% `& Z/ u, z& |{ ' e6 o" F+ \$ ~* d9 `& T
// Get a handle to the relationship Item by index.
7 T3 I* ^5 S8 c' e var bom = bomItems.getItemByIndex(i); . T% l1 Y1 K( d1 X0 H/ }
// Get a handle to the related Item for this relationship Item.
2 k# J! j7 f' p. E8 ^ var bomPart = bom.getRelatedItem(); 5 ]% o. s) r! B2 L# I! `
9 F& M/ n4 P# w; g& ?; e W
content += "<tr>" +
- ~7 f. W# S8 O+ W "<td>" + bomPart.getProperty("item_number") + "</td>" +
) {% f) @ a7 i) Y- \% E "<td>" + bomPart.getProperty("description") + "</td>" +
: o0 @ Z- X- X, O3 p "<td>" + bomPart.getProperty("cost") + "</td>" +
. {- J$ h% O' [0 r "<td>" + bom.getProperty("quantity") + "</td>" +
8 x! s! G4 l" {5 n+ \ "</tr>"; # s9 Z3 l7 z8 |/ F4 e9 J. L
}
' j/ a! m1 {1 q, ^* breturn content + "</table>";
$ J" ~8 I# x! L, l) }9 P6 y' D" N0 c( M* I1 X1 c
% S0 T6 k: T* h6 b, z- u( }) {" R
2 \4 P% [+ }5 x- V- T, a. p4 ~1 {
C# 3 k, D) ~; z0 g% {
Innovator innovator = this.newInnovator(); ; q5 D* c9 a& \. d7 _) W
: u5 v/ ?/ }+ m/ j8 {0 u) P- E
// Set up the query Item.
3 n! z$ p! b3 tItem qryItem = this.newItem("Part","get"); 1 m6 s8 r9 `9 E2 { L+ ] O
qryItem.setAttribute("select","item_number,description,cost"); : J! |# s2 ?: I% e$ j8 u
qryItem.setID(myId);
; f1 v0 |% q1 T- U6 D
" O7 U# W% p7 ?// Add the BOM structure. 6 j4 ~! f4 s: a" ^% d V( Y7 {
Item bomItem = this.newItem("Part BOM","get"); - e$ G3 |: u7 ]) ^6 o
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 2 V' ^4 A& y7 r- |3 w5 s
qryItem.addRelationship(bomItem); 6 g% W' R r" _3 K0 x8 T
' V7 o, M0 p" j2 B// Perform the query. 7 n% \2 l& l6 P- u
Item results = qryItem.apply(); ; {$ F; R0 V" t" D( U
* c* S2 [; Q q5 R, \
// Test for an error.
9 t' {+ ^- q& J/ M# yif (results.isError()) {
+ G+ x+ _8 j9 q. b return innovator.newError("Item not found: " + results.getErrorDetail());
8 ]& F: d. F, H+ T! Z8 Q4 F} 1 B6 M$ `( T, {' g, N# H8 f/ L
% g3 O2 D3 \6 Z2 J$ p( C# O: ]
// Get a handle to the BOM Items. 0 L% l/ ~" T* k0 X4 s
Item bomItems = results.getRelationships(); 9 x3 X: |% y2 z9 o2 @4 v) U
int count = bomItems.getItemCount();
8 O9 i2 Q- D6 aint i;
& E* W5 v, y' L3 v1 H" d / ?# K, R0 k1 M3 @
// Create the results content. % p- G [0 R- U7 k' X
string content = "<table border='1'>" + 0 @1 O8 S0 ~& x+ G5 o! H/ O) j9 d
"<tr>" +
2 {3 }% W0 ^. ^0 i: B5 Y: v "<td>Part Number</td>" + 5 { @2 k# |) ]" e) a. Z
"<td>Description</td>" + : t5 Z1 ?4 V3 }5 x9 |5 q* i
"<td>Cost</td>" +
& J2 [$ P6 H. u8 W8 L "<td>Quantity</td>" + ' v/ L8 I9 Y$ Q( J3 d
"</tr>";
`8 {; Q5 t3 c ; ]: k* O, D# I$ r. j7 ~! V
// Iterate over the BOM Items.
! g9 V. C: ]; q; s" ?for (i=0; i<count; ++i) 1 D% q; y2 q" H/ i
{
( A9 k* @- y: p% F2 A// Get a handle to the relationship Item by index.
" g2 A* x: n% U Item bom = bomItems.getItemByIndex(i); + y+ K) [& \& g( ]! ~
// Get a handle to the related Item for this relationship Item. 8 e \2 i3 J. E {
Item bomPart = bom.getRelatedItem(); - p8 j. p6 d' e4 |* f* D& a1 y! i5 w
. C* ?! U/ T4 ~( ~4 M/ I
content += "" +
; L# W; ]7 C; C7 D2 P5 I4 R "<tr>" + 7 `7 t4 F0 J& w* }' r
"<td>" + bomPart.getProperty("item_number") + "</td>" +
6 Q6 A, Q8 k' G' }5 P) z* w: m "<td>" + bomPart.getProperty("description") + "</td>" +
7 Z8 G, l7 W) H1 }# \* b+ ^1 Z2 H9 E "<td>" + bomPart.getProperty("cost") + "</td>" + 7 M: {7 i5 l. u- _. d. ^! C
"<td>" + bom.getProperty("quantity") + "</td>" + 1 B2 r# [0 z2 d$ o n
"</tr>";
& X& K1 m* f" t, x6 i7 w}
% l9 r& i" W, p' g6 t: Y& w3 ~9 Scontent += "</table>"; 6 T# S9 |9 w# w
& R& O2 a' y& u$ G3 \9 K
return innovator.newResult(content);
) g2 n, ?3 j6 f& Q8 c6 r1 q3 G) P3 c8 {% { i" k
4 O: B3 e) c. O9 Y% h# y1 R% W: P( A8 ~2 O
5 F9 P# \0 B5 @0 M$ C7 x6 V& X
7 o0 n9 I) W3 P4 b5 a& g
2 s8 t/ Q& h% D5 I1 \! o # F( _ r7 |, g2 e+ ^. ~, ^, i
Page 46 : P' \- }# m( w6 V, D0 j
( }6 y5 W2 Y0 [9 k/ ]7 X/ N' wCopyright 2007 * c4 I% K" Z1 |/ X
Aras Corporation.
$ i @* _4 Y& ?All Rights Reserved. 2 [/ k/ E7 C- d, N* u. \9 ^
VB.Net
2 m: ~. c0 C% [. w$ [Dim innovator As Innovator = Me.newInnovator()
' D$ i6 `3 x# ]% f" [0 O! Z. k
4 t% \ R* c( s' Set up the query Item.
1 i: L9 _0 w: @: w$ C( Y9 |7 D$ rDim qryItem As Item = Me.newItem("Part","get")
1 o9 |6 D3 r0 K5 J, U9 eqryItem.setAttribute("select","item_number,description,cost")
8 g) e4 P3 E" rqryItem.setID(myId) , l D( |9 f, r1 I$ `) t: ]6 ]
: u1 X0 L) |2 Y( X0 ~0 R
' Add the BOM structure. + {1 |$ }: D9 R8 ?0 s9 I
Dim bomItem As Item = Me.newItem("Part BOM","get") 9 T# |: W. i2 N7 j3 ]
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
9 m: H" m4 s6 u7 Q- UqryItem.addRelationship(bomItem) 8 s: v5 ]$ z1 y) g+ _1 e. j! G
- {& U% z+ G* \! b" n' Perform the query.
! ]$ V/ P, D. L6 w) UDim results As Item = qryItem.apply()
. b" D3 n' j) R1 Q! T ' j( t$ Q5 P4 H: [' Y' e* g, p* V
' Test for an error.
3 V+ a1 A+ N! qIf results.isError() Then
& Y$ W! g/ j. K+ d7 g Return innovator.newError(results.getErrorDetail()) / S# G' }# _9 i. \) E2 |
End If & Z7 w4 I1 K+ s9 m% e" m% B3 n
: h1 A k3 m% i7 r6 ]$ P' Get a handle to the BOM Items. , s9 O z' r6 N7 g3 j* j1 E8 ~
Dim bomItems As Item = results.getRelationships() 8 {3 m, N5 T7 `% x; n- w" h
Dim count As Integer = bomItems.getItemCount()
" U6 s1 ], ? G- s7 O- Z6 w' }, {Dim i As Integer & K1 A: _& t7 q
s- I+ a0 H$ d7 }8 ^
' Create the results content. 4 e; ^- k" {* V' w2 N
Dim content As String = "<table border='1'>" + _ 9 O7 L" M+ n9 D' K
"<tr>" + _
. H7 A0 d( Z7 s+ t7 ?$ h5 n. K' Q5 k4 g "<td>Part Number</td>" + _
5 U2 Y0 _9 M9 s/ f5 A9 E "<td>Description</td>" + _
% R& z1 |) b' d) G "<td>Cost</td>" + _ 5 ]3 N9 T9 Y4 }# B- A9 v) w& ?
"<td>Quantity</td>" + _
. h& b( m1 ~( [' v( @& I+ x "</tr>"
! _% v+ r6 h \0 E! t
/ l: L: z, ~' V' Iterate over the BOM Items
1 x% k% j* \; @3 D, U9 W0 NFor i = 0 To count - 1 6 ^* s N7 \4 g7 n/ [$ Y, _. u
' Get a handle to the relationship Item by index. 4 p5 q' I# C4 B c9 \
Dim bom As Item = bomItems.getItemByIndex(i) - q* ~9 d! q/ h$ |& r) O
6 i3 a4 k0 N- F& |
' Get a handle to the related Item for this relationship Item.
+ b- Y1 @( [% I1 D3 s R Dim bomPart As Item = bom.getRelatedItem()
$ e. u( u& J# C" Z( I
5 n2 o% _1 p& C content += _
( o5 Q: T; e. M6 Q "<tr>" + _
7 w S, q( J7 |% J1 { "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ) f k C7 F/ ?3 d7 b+ j$ Y
"<td>" + bomPart.getProperty("description") + "</td>" + _ / c/ T) n+ i! l2 _
"<td>" + bomPart.getProperty("cost") + "</td>" + _ $ `; b5 p' o# A8 ]
"<td>" + bom.getProperty("quantity") + "</td>" + _
& Y( Q, G" s: Q& U4 M- q "</tr>"
* U, T1 C8 p9 w% U8 ENext 7 _/ r0 }" c& I J
content += "</table>" ) a" a* w. x; ~. E: N7 O4 o
( q+ h4 _: `4 P6 _) }$ z
Return innovator.newResult(content) 1 g' E6 x4 a9 }; G% E% j. b6 ^
1 q+ ?% _ p* i5 F4 D* n) k; p |
|