|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique & p9 z. T2 j( e# _, g, E2 L
To query for an Item and retrieve its structure you build the query as the structure
) Y( ~7 F2 T- c' Z/ nyou want returned. Use the IOM methods to add the relationships you want and
* i7 y# z3 ]1 f+ P2 @build the structure in the Item. The server will return the structure that follows the ' l c4 Q! _5 @8 u9 j1 k5 e
request structure. 3 n$ _7 G4 p0 ^; i2 t" p$ f: j
This recipe illustrates several related concepts together, which are how to get a set f1 i3 }- \. e4 s& L, a) o& K
of Items from an Item and how to iterate over the set, plus how to get the related
2 }4 Z. G3 _7 @4 H8 B5 D2 XItem from the relationship Item. ; M. E4 @- ]8 l9 a5 x
JavaScript ; q& o, E& J+ K. t0 j
var innovator = this.newInnovator(); - n2 m# Z! Q$ @1 r4 ?; h
* n! `- b" P7 K0 ]7 O& H// Set up the query Item. 8 Z8 n _* q; I/ O+ ?
var qryItem = this.newItem("Part","get");
6 P) H! M0 E& s" f, WqryItem.setAttribute("select","item_number,description,cost"); - K- \$ V) G1 |" u
qryItem.setID(myId);
6 ^) D4 Y: ~. P- i4 l& {
; d3 T0 S7 F. Y. e// Add the BOM structure.
1 H1 Q" G; Y; H$ y- _' |var bomItem = this.newItem("Part BOM","get");
& I" Q7 `+ [" R* f7 z' `bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); & U2 N0 V; n* J- C# e
qryItem.addRelationship(bomItem);
8 O4 R6 p1 @/ ~$ S, a, s2 C
( _" M2 J. Q" T; o// Perform the query. 5 `2 {+ ~" z, d# D: \
var results = qryItem.apply();
! ~% s- [5 }3 A+ {. Y, q" y) F
! I9 T9 l2 H8 a3 _& c, ~$ o) g* J// Test for an error.
: t k* o! h9 uif (results.isError()) {
" y. X9 ~+ ^% b) W- Y top.aras.AlertError("Item not found: " + results.getErrorDetail());
% M' f% d% W0 R6 p- c2 }% z return;
$ a' z2 P7 M1 h1 W" r9 J}
9 @- }7 H. A8 r; F6 q % T3 ]) O2 N5 R! N q5 V8 c( _5 ~
// Get a handle to the BOM Items.
7 {2 s! g( d) t0 Cvar bomItems = results.getRelationships(); ( C9 I& J* H4 C+ D
var count = bomItems.getItemCount(); / D2 ^: `0 Y, c$ H
( G( r& B+ E; }' T
// Create the results content. ; P, d# y' Y6 G" Q# F
var content = "<table border='1'>" + ' |2 j7 a+ l1 x) _0 T
"<tr>" +
& P+ V, t" o1 b% @" Y3 E9 U' R "<td>Part Number</td>" + ! b' ]1 u. V' @. F
"<td>Description</td>" +
+ x; P K! y" o2 F+ m "<td>Cost</td>" + " i9 }7 Y0 Z @; u, K8 x
"<td>Quantity</td>" +
9 P0 p9 f, q, e "</tr>";
. V+ u; Z2 \- \+ z, `0 m6 i1 n" }
# W# r% m9 g# S// Iterate over the BOM Items.
. e: c4 p; }1 l2 Tfor (var i=0; i<count; ++i) 7 A3 R+ Y5 ~' d* Z- b3 ?- Y7 j
{
' C3 i( k: r0 w// Get a handle to the relationship Item by index.
! Z O* x& p) c5 T2 v* p; Y, O var bom = bomItems.getItemByIndex(i); * O' o* A2 O7 R' F* q
// Get a handle to the related Item for this relationship Item. 9 u. Z; O# H( y; w
var bomPart = bom.getRelatedItem(); . Y0 }3 T5 M: t+ ]
3 k) _- t6 g8 f5 ^$ [
content += "<tr>" + 7 m/ ]. v5 l5 r; c# H* f/ b
"<td>" + bomPart.getProperty("item_number") + "</td>" +
! k7 e6 ~( [9 h9 C# t% v0 ` "<td>" + bomPart.getProperty("description") + "</td>" + 8 ] i) d3 v# E3 J0 D8 L6 m
"<td>" + bomPart.getProperty("cost") + "</td>" + . z, Q; Q) i- v0 R/ V C& [& T
"<td>" + bom.getProperty("quantity") + "</td>" +
! r' O( E. Q- V; c r "</tr>"; 1 A" ]$ n8 `) R+ m) {% a
}
* f8 C9 S$ _! @0 oreturn content + "</table>";
( x& o' L; d& r; ^* k5 \
4 T: j- F2 W9 T
1 w$ U6 T, o3 e* f
0 R& J+ v* d9 h8 y/ s5 o3 w) I* _8 y0 d* K7 a
C# h7 F0 l, F% l6 h/ p5 l+ n6 _. ^
Innovator innovator = this.newInnovator(); ( r+ K6 L- b5 c
. l" c$ V7 ?- c' c// Set up the query Item. + E: y; ]$ O6 b" R6 _
Item qryItem = this.newItem("Part","get"); 1 {& {" |% K% b
qryItem.setAttribute("select","item_number,description,cost"); 2 {' u( _3 A# |: T1 i0 m
qryItem.setID(myId);
5 t6 v- h- K' P% Z
4 |8 j; A% l7 B$ `9 g* s// Add the BOM structure. . C1 L8 W7 G& j; V$ m& V
Item bomItem = this.newItem("Part BOM","get"); : P6 m7 o- p9 G- |% L( N M
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); $ q1 `* e. G& y; b7 o8 W" b2 t
qryItem.addRelationship(bomItem); : }7 G4 y. A7 O2 c" b
: e" k5 E o' I0 K8 G6 W2 i, \* m// Perform the query. " x: x2 ~6 c+ n" G" q
Item results = qryItem.apply();
6 |' @) V) c7 ^+ n * J, l2 O* n% u* S3 Y
// Test for an error. 1 H/ k$ Z- b' y1 W P
if (results.isError()) {
" h! w" L0 ~1 h. @# a* x return innovator.newError("Item not found: " + results.getErrorDetail());
: F) M; W% I- i+ V}
2 q# o# ~+ F3 h
3 d7 y+ |, Y, A7 s// Get a handle to the BOM Items.
& c7 k2 \ P" S# ^# u1 p; B I+ P* \Item bomItems = results.getRelationships();
# \, t3 D1 {( k r7 iint count = bomItems.getItemCount(); 6 f* y$ O! @$ J" G; f& j a4 e
int i; - f3 T# s3 ]- ]' ] a2 T0 i
+ E( x4 v4 i# v# S* @/ i$ v// Create the results content.
4 F+ h% e0 J0 Z8 W$ D3 n3 dstring content = "<table border='1'>" +
; D- o$ c# K9 B h4 j3 X "<tr>" + 6 D3 D9 _) d) B* K; M% U
"<td>Part Number</td>" +
; Z: \9 N" b% o$ M2 u6 c/ E" t "<td>Description</td>" + ! t: T8 z* k" k3 _0 V# \( A
"<td>Cost</td>" + 5 X, b4 b! k% m3 L8 J) g0 o
"<td>Quantity</td>" +
0 }& i& J, b5 P. V* [( L "</tr>";
1 R1 i& q+ F4 Z* M- ~% N# u ; P) _* O0 ~7 t3 E* W6 k
// Iterate over the BOM Items. : _: Q9 e/ o5 }5 h# y- a) n
for (i=0; i<count; ++i)
S N2 J$ _. T{
% z; E5 M% r: N1 _2 {& _// Get a handle to the relationship Item by index. + u% M8 A! z" D: a! @: L
Item bom = bomItems.getItemByIndex(i); 4 Q2 G8 ?1 H! g) P
// Get a handle to the related Item for this relationship Item. & j& A3 |6 k {9 _+ B7 q% ~
Item bomPart = bom.getRelatedItem();
4 I1 F/ {' m! E& X8 h8 Q ! ^3 N) ^- k5 Y Z
content += "" +
' o( q# ?& e# ?+ X0 Q; C5 l' B; { "<tr>" + * B. o6 m$ V1 C9 k2 r5 e
"<td>" + bomPart.getProperty("item_number") + "</td>" +
: u; [- g" p0 p0 G) r$ T/ ]) H "<td>" + bomPart.getProperty("description") + "</td>" + : y, n3 ~( ~; @! U5 A! E Q& g
"<td>" + bomPart.getProperty("cost") + "</td>" +
3 S. K1 F( d! @% b8 y6 M+ M "<td>" + bom.getProperty("quantity") + "</td>" +
! p. j/ e& J3 P# U1 i m. Q( D "</tr>"; 6 d, h; g, {! b
}
3 p1 u4 \0 T+ K; ncontent += "</table>"; 4 u; ?6 ? Z1 D( `% A
$ J. m3 e7 |# b% w9 D3 A$ lreturn innovator.newResult(content);
( K# r. {+ x0 ?3 v6 O4 Z% t
- p7 B+ k( C7 i* d1 c1 L: c' d7 F; Q
6 Y9 ~6 @* E" a+ u
4 I& }& E# ~, c8 X, o9 \' h& l( m5 p; n1 A1 T$ V" i
) W) a. u. p/ ^. w5 L- X9 R, @ ! F3 h$ \3 u9 X& D$ b) |% z
Page 46 4 G7 q: K: w/ c& l! i
- Y O, a) l* n' k3 ^2 X* l3 G' hCopyright 2007 . {* L! k( d# p( h9 \5 [1 G
Aras Corporation.
& F- Y( ~; Z$ N* bAll Rights Reserved.
# z6 n- h! w; `' {6 wVB.Net
: J1 Q* t+ d7 k1 L( k7 @- C: EDim innovator As Innovator = Me.newInnovator() $ U# i* `0 i9 \* U$ ]7 T& c" S
$ l1 s) k5 P9 v- m% A' Set up the query Item. * D" A5 \& k J$ O( u- q3 L
Dim qryItem As Item = Me.newItem("Part","get")
( J2 `% }+ W. {7 J* y" kqryItem.setAttribute("select","item_number,description,cost")
: s+ T8 \ L" Q1 t& R HqryItem.setID(myId) 7 i% W7 H5 ~( t/ x# k' s7 Q
" V) Y3 i5 J5 V; j6 s' Add the BOM structure.
7 C, u- e7 M' X7 tDim bomItem As Item = Me.newItem("Part BOM","get") 6 u" ^/ t" S/ U' H0 u" {9 W
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
0 `7 V; e/ y5 bqryItem.addRelationship(bomItem) 4 f/ t" B$ C. ?: j6 Z+ P
9 U+ F- w) j7 W& o
' Perform the query.
5 `, r/ B# W3 S9 s+ R5 LDim results As Item = qryItem.apply() ) ]+ \7 c6 L0 M+ k: |. a
! a0 A0 R" t! m$ S( h7 @9 @0 H
' Test for an error.
9 ~: u8 k/ D4 M7 r" ^# O! `1 }If results.isError() Then 5 m2 C$ G$ C" ?6 V3 @) \
Return innovator.newError(results.getErrorDetail())
- q1 K* h: T2 S1 u+ A' REnd If 3 n5 n( D Y8 C/ U* G
) v$ E) _7 E% @# O1 M# w l- C3 e' L' Get a handle to the BOM Items. ( b9 k5 u! R4 v1 V* |1 d
Dim bomItems As Item = results.getRelationships()
' S% L- @, `3 U; e* YDim count As Integer = bomItems.getItemCount() * Y( d2 H* y8 a1 @
Dim i As Integer 0 \$ \. n2 v! o* h
& F5 D7 M2 @6 V8 e2 h w9 A& x
' Create the results content. ( G7 c' S$ R# m- |
Dim content As String = "<table border='1'>" + _
( B: s# f8 ~1 {: V9 j7 Q1 f "<tr>" + _ 4 l" ?; A3 U6 ^$ s7 Y2 P F7 P& d
"<td>Part Number</td>" + _ % b( i9 f& Z6 ~6 Y
"<td>Description</td>" + _
4 Z7 z/ |* s* M: c% c# I. A6 w "<td>Cost</td>" + _ 8 K, w m q# U6 [. ]+ z
"<td>Quantity</td>" + _
- s+ g6 T, }. j) F. [& C2 o3 b "</tr>"
) ]6 i: {6 Y' m; f) q7 k1 ?9 s
T$ `8 O2 J4 e7 o( \' Iterate over the BOM Items
9 B3 ?5 `, }2 dFor i = 0 To count - 1
E# S4 c) j7 \6 M- r' Get a handle to the relationship Item by index.
1 t3 f6 U, X2 d* O) l Dim bom As Item = bomItems.getItemByIndex(i) 6 N; T' W5 u. @) [) R2 U- O t
, I9 C1 Q0 d6 V$ w ?, [9 ?- |
' Get a handle to the related Item for this relationship Item. " I% K$ G, e; x! [; H; @
Dim bomPart As Item = bom.getRelatedItem() 0 B9 v8 Y- M6 p; t! i' |
E9 ?1 q( p% \ e, A
content += _
1 ^; q/ }+ y) G5 V$ a/ M "<tr>" + _ $ h. X8 g" F1 P( P% } |5 R f+ V0 k) {
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ v9 ^8 c6 c8 @& O' j
"<td>" + bomPart.getProperty("description") + "</td>" + _ ) R! z9 F/ i/ U) t2 |& ^+ L
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ; J- h$ ], ]+ {1 P, U
"<td>" + bom.getProperty("quantity") + "</td>" + _ 8 o5 [; W5 A. i, k" V& N8 G
"</tr>" / u6 Z1 x' y5 c
Next
! E0 D) D7 W7 k" c' Gcontent += "</table>" 2 I, M' \% X5 o4 S4 ~. J1 F5 q
! V# y& r1 @; F" }9 \6 NReturn innovator.newResult(content)
T: a3 Q3 k3 f/ N2 }4 ~
) o9 w3 R/ t0 B! Y, | |
|