|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique , r8 p$ M* M6 G7 K( H5 u2 E& `
To query for an Item and retrieve its structure you build the query as the structure 8 H {% y/ H/ T
you want returned. Use the IOM methods to add the relationships you want and 9 O1 P: [& h9 G3 u. L
build the structure in the Item. The server will return the structure that follows the
3 O3 _; A+ j, v9 k3 qrequest structure.
2 \8 K) y4 O/ O6 D* vThis recipe illustrates several related concepts together, which are how to get a set
) o, v7 e4 K' w5 R) B# A0 E$ s \1 _of Items from an Item and how to iterate over the set, plus how to get the related
9 i6 o6 } V: L8 ]1 g, ZItem from the relationship Item.
8 ^2 m! s* {2 x* L- N, ^; {+ WJavaScript * C" k4 V* x) I3 h0 G
var innovator = this.newInnovator();
* M) [/ F& x# w3 X
3 r! x+ R5 P- R. w% w/ a// Set up the query Item.
- V- ]7 D- u% x" \ {% Cvar qryItem = this.newItem("Part","get"); : z+ i# C* G+ [; J5 D& }. K
qryItem.setAttribute("select","item_number,description,cost");
4 Q+ f0 O; f8 \4 r+ o) j2 yqryItem.setID(myId);
: Y5 G$ W- y; z + n9 F* s }' D" s5 y3 n2 @
// Add the BOM structure.
7 M8 T8 H" [& svar bomItem = this.newItem("Part BOM","get"); 9 G, \; |. O1 F& k% K0 `* I0 A
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
0 s2 Q! [" L" ^) bqryItem.addRelationship(bomItem); ; T' R, U$ a' h
. X2 k) \# O- n* C% j// Perform the query.
U0 @4 u/ U. ?9 n! evar results = qryItem.apply(); " T) H( `/ v Z8 U1 D
3 Q4 Z# q+ P! ~6 z1 Q9 Y
// Test for an error.
4 N7 K/ O9 a& S* o: H; r3 Gif (results.isError()) {
9 M, m" M, F: d s: q* N top.aras.AlertError("Item not found: " + results.getErrorDetail()); r/ q3 j8 Z% q4 g) V2 W9 k: g
return; : Z7 }6 Y% c% X
} ( Q7 s7 T" b- l: J- f8 D
: }5 d; g) U+ m) A// Get a handle to the BOM Items. , c2 b) z7 C. z( E* H5 J0 A: M
var bomItems = results.getRelationships(); 9 ?% k* P) W0 N/ U) F9 }
var count = bomItems.getItemCount(); ! O- ?8 g% f: }3 t; j: V
9 @) m5 _& A" a// Create the results content. * B' m* v4 q- r2 @3 {
var content = "<table border='1'>" +
8 d: _0 p' E$ n) C4 N9 C) w/ n. Z "<tr>" + . m3 C: Z/ S6 X f; E# H
"<td>Part Number</td>" +
- D. G" x6 X; O) O4 _9 K' I5 b% P "<td>Description</td>" +
7 p- t) p. h9 u1 i2 Z: j "<td>Cost</td>" +
* H9 O$ u& G1 W: b2 I* n "<td>Quantity</td>" +
0 L" h0 D) u$ |) v "</tr>";
+ E8 }. l% x0 j2 j, B" k
* j7 [/ h4 k( D- E" X( X) _// Iterate over the BOM Items.
# ?3 \) o; e& t/ x0 Hfor (var i=0; i<count; ++i)
) i0 t0 D, j* p* Y# o: u+ l2 g{
" W. @2 U1 s! Y// Get a handle to the relationship Item by index. 6 a0 f, e4 c% E( j$ l2 ^# q
var bom = bomItems.getItemByIndex(i);
3 ?% ?# T; O% P2 k// Get a handle to the related Item for this relationship Item.
! _" v( z7 S9 N( A var bomPart = bom.getRelatedItem();
+ X; f& @. h3 D8 E5 C# \ - j$ w) Z1 ?6 M: B3 w5 O, M4 z
content += "<tr>" + / ?9 [: \' A O" }
"<td>" + bomPart.getProperty("item_number") + "</td>" +
. x y" I; p$ U0 o j "<td>" + bomPart.getProperty("description") + "</td>" +
1 s$ i, z) k* E) q "<td>" + bomPart.getProperty("cost") + "</td>" +
$ b- i/ M1 k, ^ "<td>" + bom.getProperty("quantity") + "</td>" +
X I! a f* o& r "</tr>";
9 Z# U% l, M( R4 w9 ^}
* P' I7 d$ A, N1 e" yreturn content + "</table>"; d& c# Q3 P; O
8 }/ U; @: P7 g' G7 F! b
, u, [& d) Z* R8 L; n: C0 ~
9 n5 V: ^! d/ n7 {9 a! Y8 I& ^+ p! w
$ u( y9 ~4 u' n' _C# $ h/ ~- W3 r0 r6 f$ f$ t9 u7 F
Innovator innovator = this.newInnovator(); 4 R& T! }# B1 C) o7 Z6 N* G- i
' l f" k$ n& z* y! V* l& j
// Set up the query Item. & l3 N! w# Y# J7 z; L6 x
Item qryItem = this.newItem("Part","get"); : p- i- g: r7 Z9 p0 G6 Q
qryItem.setAttribute("select","item_number,description,cost"); ; K+ x& O. H/ N' C; n) Y; P/ A
qryItem.setID(myId);
# ]6 l* V, c! }) y+ S 4 M5 w+ @5 N. s3 }9 u- g$ F# z
// Add the BOM structure. $ ]+ x& S1 M; Z* {; f4 v
Item bomItem = this.newItem("Part BOM","get");
( L$ K- D% n4 K: H1 GbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
- F) `$ n. E0 m1 F& ^qryItem.addRelationship(bomItem);
8 w2 Q6 {0 [* t: r
- |7 v9 \0 O+ C$ ?0 u" p4 @// Perform the query.
7 Z3 M1 O! H# k: b$ N2 S tItem results = qryItem.apply();
# p. F, x. l, d ; p/ T+ x2 d+ |* f
// Test for an error.
+ M5 o: C& E, M/ z }: V& Iif (results.isError()) { 2 e( M' }$ P% T- R( z1 R" u
return innovator.newError("Item not found: " + results.getErrorDetail()); G" H) R9 R% f, q
}
/ P% h7 O# \! f9 h* @
5 P$ A1 r. q2 N7 u4 k t0 A// Get a handle to the BOM Items. / i) W* \) Y7 g2 T
Item bomItems = results.getRelationships(); + p# ^9 u! b% z3 {! i
int count = bomItems.getItemCount();
5 m) y8 b0 e4 W/ iint i; . w* |4 |6 S& X. m
2 y+ h# k7 \& |( p- s1 O
// Create the results content. , @* }6 ? t$ @3 M& ~
string content = "<table border='1'>" + 2 l5 ~- \! x4 P
"<tr>" +
) n2 l4 P. ]1 t) u$ z _ "<td>Part Number</td>" +
% v# V) C. [7 g7 a8 D "<td>Description</td>" +
5 a( X. F" E/ e) _* R "<td>Cost</td>" + ' D& |. I6 C& J% ^5 `+ Z4 f
"<td>Quantity</td>" +
. I; Q& l$ [% [. N8 N! d5 Y' o "</tr>"; 7 f2 ?3 t. g7 a
: A Z' |7 ?' d0 P8 R# O: ]6 w0 d
// Iterate over the BOM Items. $ ]7 }3 B( U# z4 B
for (i=0; i<count; ++i) 9 g% s) z. }3 O7 _) P, W
{ ! Y3 z% r0 N( p, t
// Get a handle to the relationship Item by index. 7 j/ Y$ k' G9 @8 X& q; W; h1 z
Item bom = bomItems.getItemByIndex(i);
3 H" T9 z: V$ a// Get a handle to the related Item for this relationship Item.
1 Q1 R* o/ W- c6 \/ p, O% _ Item bomPart = bom.getRelatedItem(); 8 Z0 w, T3 f f$ Y* ?
7 {) `! ~# ^3 r/ B! K
content += "" + ) p) ?" P% e/ \: `! a& w" T
"<tr>" +
' ?5 _8 B* P3 c. H "<td>" + bomPart.getProperty("item_number") + "</td>" + ; E- X5 I k6 I7 z, k
"<td>" + bomPart.getProperty("description") + "</td>" + 8 N1 F3 l I3 s+ M& l P
"<td>" + bomPart.getProperty("cost") + "</td>" +
3 J. o6 U+ U% Y' k2 j v3 a "<td>" + bom.getProperty("quantity") + "</td>" +
/ _$ k" {4 N' h4 R "</tr>";
/ u4 V0 Z6 B+ Z. h( r} 3 J1 n6 a- X6 ?5 p
content += "</table>"; + d8 ~ Z6 ~) d
0 p6 Y. w2 p3 E) B, e. E1 u4 b
return innovator.newResult(content);
) J, ]8 B2 }! ~8 `5 @; q2 _& j* N3 E4 C% `" Z- ?
3 _1 W/ Q1 V( s
* X$ B' ]/ Z H' a% X8 m2 A- z: i7 t
Y! I( v* \+ Y, ^
4 m; _* J3 e5 t$ W# g
3 Y8 H9 j. `) u' \( O2 S
9 {# X& D, M6 S/ o Page 46 8 B: g# f# h( L" \, G
9 T$ O) ^8 K) t3 d. S6 w( ACopyright 2007 % _% c# J+ i3 r4 o: r2 y- R
Aras Corporation. 3 ^+ m& @6 H( K. X+ d) z
All Rights Reserved. ) u& f( x2 s9 l# d
VB.Net
3 Z" x( y: Z. i! y% MDim innovator As Innovator = Me.newInnovator()
( S _7 Z u+ W7 z& T q - C' A/ X7 @! t1 }7 i
' Set up the query Item.
) X& Z, U# O/ O; X1 R; ]9 [Dim qryItem As Item = Me.newItem("Part","get") % O6 ^+ V g8 X8 M; I2 U( D$ z
qryItem.setAttribute("select","item_number,description,cost")
5 [# R* u: r4 K3 _# P( LqryItem.setID(myId) : ~% f: ?/ n' W; ?
7 f j& i& y$ V j& x! p* a
' Add the BOM structure.
9 D! g4 \" ~! P4 @; Y! Q2 GDim bomItem As Item = Me.newItem("Part BOM","get") 3 _8 m! X2 r# C3 ^
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
* `) b3 ]0 ?2 N% Q4 [qryItem.addRelationship(bomItem) 6 ~ S1 T, p1 B+ D0 k, _
U: @7 g2 V/ s
' Perform the query. # k4 H9 L" b1 e" k
Dim results As Item = qryItem.apply()
( ]* r) y% q, k9 X3 P! n ; R- n% }" S/ v; g0 l
' Test for an error. , t0 E8 [* [* ^) P
If results.isError() Then / e1 h8 o' t! P+ s0 o+ J
Return innovator.newError(results.getErrorDetail())
! ` K( a& r. v( |! AEnd If . H" Z3 F8 ~# y* u# {8 L
! F* i9 U- \2 n h' \; {
' Get a handle to the BOM Items.
+ y7 @0 R; Q {3 t/ S. @Dim bomItems As Item = results.getRelationships() 8 P' \9 M0 T2 ^
Dim count As Integer = bomItems.getItemCount()
& I( ~# `4 d( x# w* a" a$ GDim i As Integer , c7 l2 X8 @' F+ o; z
4 u7 C" @3 F8 P1 G$ [3 v' B' Create the results content. * N% X3 t. [7 { e3 K
Dim content As String = "<table border='1'>" + _
! f8 n: u6 N5 m( t# G, l "<tr>" + _ 2 y( J; R/ |* S6 R7 r7 ~
"<td>Part Number</td>" + _ 1 ~6 ]- B0 X- N& b4 _/ B
"<td>Description</td>" + _ % ?' o2 N& C/ j; a$ W+ Y0 q
"<td>Cost</td>" + _ " ^/ L- B1 z9 C1 O% I( N+ ^
"<td>Quantity</td>" + _
9 @( j, E( Y; O6 q* N "</tr>" 0 D, G Q/ A1 X5 j
" q& Z" t9 s2 v% v. w/ I5 ]
' Iterate over the BOM Items 5 e/ O; L6 A V& P7 f$ y1 n" U
For i = 0 To count - 1
4 |9 M* F$ I6 H2 x' Get a handle to the relationship Item by index. 4 n# |- ?0 y+ b3 r% B# a
Dim bom As Item = bomItems.getItemByIndex(i) ' `. o6 f( f1 p5 N9 F8 i$ F2 {
# a% |& I8 s) f" Z0 ?5 J- r) v( a
' Get a handle to the related Item for this relationship Item.
) Z- L/ \* f+ P; G: ? Dim bomPart As Item = bom.getRelatedItem() # h! X: o2 b/ [0 v: ^: y# }
; h' ^: Y( S8 Q: w content += _ & p; W; }) c5 R8 B" e+ l4 {
"<tr>" + _
$ g1 Q8 i5 {+ d& O: E! }& K "<td>" + bomPart.getProperty("item_number") + "</td>" + _
/ K4 h6 J- y7 J- Z; p: @3 K* K "<td>" + bomPart.getProperty("description") + "</td>" + _
! J a" s, n( Y F. I4 z4 O "<td>" + bomPart.getProperty("cost") + "</td>" + _ ' U7 h% {6 m! Y/ J' G' \1 _
"<td>" + bom.getProperty("quantity") + "</td>" + _ # ], y- Z. I# h8 D. N& @* |
"</tr>"
6 X' l& _7 o s( P% oNext ; o. C5 u7 R5 }0 T' q: y
content += "</table>"
, N3 B7 Q, S- Q! }/ z H" Y/ S f% c: t, P
Return innovator.newResult(content) 4 ?( k& \. E6 W9 x& f
! ?. u/ e- l7 c- Y/ Q( N |
|