|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique # ^0 V, V9 D0 O; z6 N& r2 P" {: _
To query for an Item and retrieve its structure you build the query as the structure
" d G5 P: y+ j/ _# b8 Dyou want returned. Use the IOM methods to add the relationships you want and
" j1 O% G4 g; ~& }3 S- I D( [build the structure in the Item. The server will return the structure that follows the
. w8 T9 N- `0 s& U+ \) D5 G* W. qrequest structure. * w& p; T' c" r+ U* T
This recipe illustrates several related concepts together, which are how to get a set 3 n& u" m! Y+ w. N6 v' m$ r
of Items from an Item and how to iterate over the set, plus how to get the related " |: H) k$ p( h# i
Item from the relationship Item. 7 T; z4 U- E0 e* Y9 K1 h9 {5 L0 p
JavaScript
A) ]" y3 i5 h+ v1 ~var innovator = this.newInnovator();
5 X' h3 M4 o8 q; {. I
6 }+ U2 q+ f$ r// Set up the query Item. / X5 e9 ^$ Z+ \
var qryItem = this.newItem("Part","get"); 8 g: Z* H- ?5 T; U9 Z
qryItem.setAttribute("select","item_number,description,cost");
& o; x. u5 ]0 g7 [' DqryItem.setID(myId); ' y8 U P4 i5 v/ c3 V' P
+ K& h4 O+ `$ B5 p// Add the BOM structure. 5 m" r% L8 C' X. l; O d' a
var bomItem = this.newItem("Part BOM","get");
" t0 r! m; t7 I4 y7 G% G LbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
( N/ M! z! d3 W4 ?qryItem.addRelationship(bomItem);
0 V. I) q$ i5 N3 g 4 p9 p. a0 J* n2 G
// Perform the query. 6 O! _- a7 Z+ N2 X
var results = qryItem.apply(); ' e) C. h6 H" u# U9 a
( C. w- e) a0 `7 \* A
// Test for an error.
8 {" R7 d, Q8 b0 N5 `8 m0 X+ z. m1 |! Lif (results.isError()) { # A$ Q% w: ]9 t3 }5 ]
top.aras.AlertError("Item not found: " + results.getErrorDetail());
: b D& o$ U+ N; p return;
4 |& Q' A* j! q n9 ?8 _% e} ) ~1 A' s5 r0 D% P
2 U1 T- ], o( Z
// Get a handle to the BOM Items. X( P) o9 X: a6 P# N& A+ U1 i% \
var bomItems = results.getRelationships();
5 n+ q+ A4 `7 `7 p% h1 I. U: zvar count = bomItems.getItemCount();
* ]) r3 t" j) O) S4 Q N, t
' ?! |) [; t( X2 z" j8 ?- Y9 G// Create the results content.
* C/ ? m) O+ l; J4 ?: Fvar content = "<table border='1'>" +
7 @0 p& L5 z Y: t7 o6 M* G "<tr>" +
$ ]% C$ d; ?( B8 x* ]% }; g "<td>Part Number</td>" + 9 B- \, K0 N- n @- m7 M
"<td>Description</td>" +
5 [' J4 M R- k "<td>Cost</td>" + 5 ?9 \% C! _4 T2 X( z
"<td>Quantity</td>" + $ }: h, k; y" A0 r2 K
"</tr>";
' {) y+ [0 \( r' | * p) F8 V3 g' b: b" b# p% M
// Iterate over the BOM Items. 0 T% m- I1 f! F; z9 W0 o9 A- D
for (var i=0; i<count; ++i)
+ T# {+ g/ w* C5 X8 J) D2 V& s6 h* u{
- f' z4 P$ g7 R" k4 I1 L& |$ B) a// Get a handle to the relationship Item by index.
) d0 U' i1 ~( [ S2 f) N+ V) l4 [ O- K, e+ t var bom = bomItems.getItemByIndex(i); 9 i$ e2 D# y8 }3 \- C
// Get a handle to the related Item for this relationship Item.
% `' g4 R8 G s. Z5 | var bomPart = bom.getRelatedItem(); & R$ C5 k$ _. @! g+ p
9 s$ ~/ I, C$ R, V% K
content += "<tr>" +
3 J& H# ]. S' k6 o "<td>" + bomPart.getProperty("item_number") + "</td>" +
" j" N; a9 W3 e5 d) s( A) }+ H "<td>" + bomPart.getProperty("description") + "</td>" +
' q* h1 W% {1 I* c' Q/ O "<td>" + bomPart.getProperty("cost") + "</td>" + + ?3 S$ N/ M; [+ [2 x* g9 B/ S
"<td>" + bom.getProperty("quantity") + "</td>" +
% o+ z+ e6 V' a9 Z, j6 X "</tr>"; ( A4 R6 M; ] B# ]/ l1 x
}
8 M! L8 S& ^4 M e6 x9 Ereturn content + "</table>";& ]& P' |9 W! u9 Y! ^( f
3 G) O& u4 s+ M6 v X9 h- U4 z9 b4 L# i: Y: }4 n- |
- s% a5 W) n( ^+ [: s; S7 ~* t0 Q. l+ B9 j
C# ; x6 Q: f/ ^9 w: F7 n/ y. R% _& ]0 ]
Innovator innovator = this.newInnovator(); 7 j" X } I7 f
) {; `! U+ h i I8 x
// Set up the query Item. ( M5 o7 s0 ]: P0 M
Item qryItem = this.newItem("Part","get"); + y" e _3 x, J. a# V& `% t
qryItem.setAttribute("select","item_number,description,cost");
& F, S5 I+ k& {$ rqryItem.setID(myId); 9 \* N! a! t/ K
5 I3 `( ]. Z2 ?+ F- w& o' W// Add the BOM structure. 7 j& z3 R* d9 i+ g" r: p" ^/ d
Item bomItem = this.newItem("Part BOM","get");
' ]" C: K0 y- \# s. n9 dbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
( {: ]' L* Z Q3 o/ ]3 ]qryItem.addRelationship(bomItem);
* N# F! `! O A$ B; X+ [! ~. Y1 ?) G + }: K |/ H n: V9 t5 G* w! H
// Perform the query.
7 h- U4 B* B1 r* E# I1 tItem results = qryItem.apply();
: x! }1 r8 z) `( P: L* R
# J# i3 d$ l' \6 A1 Y" Q" n// Test for an error. 6 E: X1 W, ~: y! R- a: Z
if (results.isError()) { % M( x; \: G2 d. n% ^, A- N6 C
return innovator.newError("Item not found: " + results.getErrorDetail()); 4 J7 z$ z5 e1 Y8 r4 a
} , U. Z8 ~! B9 t' o G& g5 Q/ ~* L
" f5 B. F+ g2 L1 M) P8 {
// Get a handle to the BOM Items.
9 B1 V1 {; p4 N9 G4 `Item bomItems = results.getRelationships(); ' g. `* D. P0 R
int count = bomItems.getItemCount(); , P# d! `; g4 H' t
int i; : J. F3 w' L1 d. a' I5 h
' d; ?: n% F7 v! e$ W! q e
// Create the results content.
2 X, \0 }& l; d) U) qstring content = "<table border='1'>" +
2 s7 C' i/ \+ [; X5 e "<tr>" + ; X8 E2 s" w1 J; K
"<td>Part Number</td>" + 7 [* n! O2 s3 }, T3 V
"<td>Description</td>" +
, @/ b% m3 f; F% Y9 ]9 V! B "<td>Cost</td>" + & s' C& ^ P+ @
"<td>Quantity</td>" + ; V# n/ u* f% B; F/ W8 N0 F& O
"</tr>"; / u6 _' D" `% z) g! i
3 {9 Y, R5 @: {/ ]4 Z
// Iterate over the BOM Items.
' k; r6 z: W; v# J o# u) Q7 w. Gfor (i=0; i<count; ++i)
& W1 P1 ]3 c, N; w& U: O{
" t5 T' e) w+ {, Y6 ~// Get a handle to the relationship Item by index.
1 {5 |- }4 l: G& m Item bom = bomItems.getItemByIndex(i);
: F3 b8 ~9 l' w i; c2 }- [" J// Get a handle to the related Item for this relationship Item.
: @; G% f3 R9 u Item bomPart = bom.getRelatedItem();
1 u4 U: U! E/ j& M% Y, ]4 k/ w " V) Q3 H6 {7 Y3 s+ N% A/ H2 R8 W G
content += "" + % O. k k9 w1 S# d& L& f
"<tr>" +
; w2 T+ r/ {8 S* }/ o X "<td>" + bomPart.getProperty("item_number") + "</td>" +
6 S2 r7 j4 }" A: O- A% l "<td>" + bomPart.getProperty("description") + "</td>" +
% L# ^5 W! G$ K2 u. L0 p' G; y "<td>" + bomPart.getProperty("cost") + "</td>" + 0 v& q/ r! \6 {) ]- Z/ n: C% |+ B
"<td>" + bom.getProperty("quantity") + "</td>" +
, l$ T. `3 E! J "</tr>";
' d8 U2 m: v. w' ~% p' L6 M+ O}
/ c; `9 w& l ` e/ ocontent += "</table>"; 3 R; b6 Y$ I; Y, _% S( C. E3 C
5 H7 O. C1 u' v; h' ?' ?
return innovator.newResult(content);
* }+ l( R# s0 A* D) r) b3 z5 W# `8 R% |: m( x, X5 i$ k' @ L; i
; I, h8 {* |: E9 Y
; @# E. X$ B$ d) E- y! ^; E3 L
8 n* \, H) O' ^1 B/ T5 f* i3 @! [2 i5 l5 k
$ W) m" w' C' B4 W6 q& D
. i! b; K; ?8 [% r Page 46 % [ t' X; F x9 u* Q* }- l
' H$ \( l( A& w2 _
Copyright 2007
% N1 |* b. J1 AAras Corporation. # t' U0 Y5 p8 m
All Rights Reserved. ) g9 ~$ @' [% m8 F, [
VB.Net ; ^' V+ n' E. `3 L3 I3 C; R* ~
Dim innovator As Innovator = Me.newInnovator()
; p4 u. b4 a* H. [/ H" g) U
7 \9 c5 w& _0 H- d n% I7 G' Set up the query Item.
$ G [6 c! y2 U4 \* I& h. TDim qryItem As Item = Me.newItem("Part","get") * a& M1 F6 v& O, j3 i- k
qryItem.setAttribute("select","item_number,description,cost") `' @+ E* {" G! K/ {/ ^- C
qryItem.setID(myId) : T% R: H3 h/ u9 F
- O5 `5 k1 P& E) d. D# k
' Add the BOM structure. 4 v: ?/ j4 g0 a6 o) Y
Dim bomItem As Item = Me.newItem("Part BOM","get") ) s6 J& @* }1 `; k: X
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") $ L. @. [4 O5 T
qryItem.addRelationship(bomItem)
4 i: f+ y3 u2 X* L4 b ; a- u8 t) E* Q0 G5 Z: W: r5 v
' Perform the query. 1 Y+ J( c, S! z7 {
Dim results As Item = qryItem.apply() : `( o, c2 L R6 t+ L
) t6 H4 H/ C& c3 e+ ~/ d- _' Test for an error.
: S$ m/ h, \+ h# H/ B8 R: T7 ^If results.isError() Then % Q9 ~5 o* [/ {. D! u4 m
Return innovator.newError(results.getErrorDetail()) $ Z% U4 d$ j5 u, E* E/ E5 {
End If
8 t' n+ |" A# W" P+ K" X& c 1 }6 ~5 X7 `1 W3 z
' Get a handle to the BOM Items.
; w0 {3 k4 g1 ^. C3 Q q3 [4 sDim bomItems As Item = results.getRelationships() , F: j8 }+ V& C# }# r* A' G; |4 v
Dim count As Integer = bomItems.getItemCount() ; z& Z. G& Q: J
Dim i As Integer
! z# |( x @% F# y8 p( ]
! [3 K! C& V4 s( W0 Z5 o, k& D' Create the results content.
, x: s0 D" B* e1 ^% t3 q! bDim content As String = "<table border='1'>" + _
w( ?( m0 D L- m1 `- h "<tr>" + _ / e- v1 Y! y( O! r) _: b
"<td>Part Number</td>" + _ ) Q7 Z3 a5 T/ U0 }
"<td>Description</td>" + _
/ x' e2 @2 _: d& Q( y9 X& m "<td>Cost</td>" + _
5 X7 [3 E. q5 W1 h "<td>Quantity</td>" + _ ! S6 R$ s4 e& E1 P( a, L0 P
"</tr>" 9 x* R, o# N a: t
2 I& c8 p% G' I7 _
' Iterate over the BOM Items
4 \. b$ T; ~$ o+ R& h8 {9 `6 q' XFor i = 0 To count - 1 2 ]' h# F5 F- _% j
' Get a handle to the relationship Item by index.
& M- m" E+ t" q n' i% Z% \( f Dim bom As Item = bomItems.getItemByIndex(i)
1 |, J, P( `" p# S : s2 Y2 M; a9 C' ]5 z
' Get a handle to the related Item for this relationship Item. & i& r2 z2 b- [: U5 ` g
Dim bomPart As Item = bom.getRelatedItem()
/ Q- p# b$ F/ |( U" m $ f/ O$ U& X' S8 D: K7 x8 J
content += _
+ a$ T1 e% V$ K( V "<tr>" + _
" C9 x* z0 B! R6 r: M/ X "<td>" + bomPart.getProperty("item_number") + "</td>" + _ f: ]9 v9 G% Q* m( _' i
"<td>" + bomPart.getProperty("description") + "</td>" + _ 3 | Z7 J W0 b5 ~
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ! a( J6 ~8 l! I7 G& J6 L
"<td>" + bom.getProperty("quantity") + "</td>" + _ 0 L- z5 S/ k7 Q4 ~, s( Y
"</tr>"
5 V" n* B1 ]& v% R6 oNext
+ ?7 A( ]0 k: n4 ]2 t7 Q4 L L5 ]content += "</table>" % H: P0 q- \1 d$ h7 U7 o
% p# n$ y& v/ x7 n7 H. V
Return innovator.newResult(content)
0 O7 l+ m9 |" Q5 {" q: N8 ~' P6 h; Z, {2 N t+ T0 |
|
|