|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique + i- s# k0 m' |4 U: s
To query for an Item and retrieve its structure you build the query as the structure
2 u, q% D, {& ?4 H' nyou want returned. Use the IOM methods to add the relationships you want and 1 h; ]4 u' c1 E. n% [
build the structure in the Item. The server will return the structure that follows the
( m. H7 X1 }3 o: m# M, B" c( Xrequest structure. 4 y. W3 `, Z# X8 d O, T
This recipe illustrates several related concepts together, which are how to get a set / u0 W+ K. ]1 g5 }" S( T
of Items from an Item and how to iterate over the set, plus how to get the related
' o1 v" N: x1 H, _* e# J) rItem from the relationship Item. : B5 ]0 Q8 [- w9 r* B
JavaScript
# I5 k6 |$ c5 lvar innovator = this.newInnovator();
6 {0 n( i) I- r 4 \0 G# M0 `7 K7 b% h K4 z$ P" o
// Set up the query Item. ; B. p: q( X6 V' P2 b
var qryItem = this.newItem("Part","get"); " c1 Z; B) B% S4 h$ T! o7 Z3 o! j
qryItem.setAttribute("select","item_number,description,cost"); * V* g3 w# j" j
qryItem.setID(myId); & U1 g5 ^+ Z2 f& u; c+ o
- S; d( `/ [9 J- i, s0 i
// Add the BOM structure. - w1 e2 x5 h; X) L8 I
var bomItem = this.newItem("Part BOM","get");
2 o+ @' T7 a. T6 BbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 2 p1 C3 v9 o" w
qryItem.addRelationship(bomItem); ( X+ r1 |7 {4 J% ~( _, A3 s
) ]/ J' L( x* B1 P- i6 _5 X// Perform the query. ! ?( y9 o3 r- z; R! h" e, h
var results = qryItem.apply(); : X4 x9 e) S" ^/ E/ d
* E) @& D6 G; H T3 Z) K// Test for an error.
' ~- }3 X* @ _% K8 T# B8 n1 Eif (results.isError()) {
. F9 o2 G' m1 R+ x* w3 ~# _ top.aras.AlertError("Item not found: " + results.getErrorDetail());
% x: x. t" O. V: H" V return;
% w0 `4 U( F5 y* l7 P} # g/ d! ~. T3 Y: f y4 D. X5 }8 W
) v. _( a3 G- O& `+ ]9 c
// Get a handle to the BOM Items.
% l8 M! P5 {! {, P6 V8 V7 i. \var bomItems = results.getRelationships();
; C0 A/ u& _, s% ]# \+ y% t gvar count = bomItems.getItemCount();
Y/ r0 Q8 e$ N, p8 A/ \ 4 V: U& D7 m% V) k: O9 c
// Create the results content.
; ]' ^- F$ H0 t3 e. r; I% X; Gvar content = "<table border='1'>" +
" |7 l; g9 J$ c, N5 n' D "<tr>" + ) ]% g; v/ i5 P% o
"<td>Part Number</td>" +
5 Z' {% t0 P2 ^" v$ ` "<td>Description</td>" + ( f6 P0 C7 e C9 r
"<td>Cost</td>" + 3 X9 t' E* w A" C. U/ F
"<td>Quantity</td>" + 4 N, c9 N+ S; K& ]7 s
"</tr>";
' G* r' \5 d2 ` C
$ g! G' a# u+ O% U// Iterate over the BOM Items.
+ a7 J+ ]5 z' B+ [% f$ e" v% `/ Jfor (var i=0; i<count; ++i) ! T4 s6 o* V1 G, v& f( i; ]
{ ' a3 b6 j7 U {& E* Y
// Get a handle to the relationship Item by index.
" b2 D T# Y9 `8 j var bom = bomItems.getItemByIndex(i); 5 S, v: V0 r& t" Y1 z f8 T
// Get a handle to the related Item for this relationship Item. 0 t+ E; \' c* @6 F* N- d
var bomPart = bom.getRelatedItem();
3 A8 J# ~) |" I1 B# }! @: G 0 X; \& r( M8 s7 ^. B
content += "<tr>" +
' J' y$ o, R1 b "<td>" + bomPart.getProperty("item_number") + "</td>" + 5 B2 D/ K; p) [& j7 t/ w+ E
"<td>" + bomPart.getProperty("description") + "</td>" + - o! Q8 a) e! a# l( {; p
"<td>" + bomPart.getProperty("cost") + "</td>" + ) L& S- L- h, ]6 i
"<td>" + bom.getProperty("quantity") + "</td>" + 3 ~: r C7 w/ P* I
"</tr>"; # e" Q" o1 g1 G
}
- s; x) s/ S$ S5 i2 Q# breturn content + "</table>";
3 e4 I6 P4 }' n* [2 z4 r# f6 ~! {9 l
- f' r. J+ C2 Z0 { y: y
2 n: k( n9 h7 Y
% G( N& k/ x( C4 Q$ I0 YC#
) }3 `; f, \$ m+ qInnovator innovator = this.newInnovator();
: O9 H. m3 j# | U 4 H1 t5 t9 ?' c6 J- t
// Set up the query Item.
. r6 m$ y( K6 uItem qryItem = this.newItem("Part","get"); 0 j4 ]6 z& P/ \
qryItem.setAttribute("select","item_number,description,cost"); 9 G8 [! p/ Y; K' t! l$ O
qryItem.setID(myId); / L, o+ n1 t: ]- I6 `$ ?( T' G# T
& o* @- |8 D$ I+ }' m9 o
// Add the BOM structure. / |' @, ?: {) D9 J5 ~
Item bomItem = this.newItem("Part BOM","get");
1 P' D, R- z/ e# e2 L; WbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 9 I( G6 g( x+ [! p( a4 h
qryItem.addRelationship(bomItem); 9 P m* o7 c9 s& e6 c/ Y5 X
% ~% U1 R5 ]- \& e& H- t% N// Perform the query.
& }! C) g: D2 |0 t6 S7 L% Y# }Item results = qryItem.apply();
1 Z; A0 v7 \! m! ~
1 Y5 i2 H$ ]5 |" `1 ^// Test for an error. , V3 @' V) a; Y7 L- M! _
if (results.isError()) {
# o# g0 ]% z' C! o return innovator.newError("Item not found: " + results.getErrorDetail());
, \% {# B, t, E' V$ i$ J}
2 o3 Z& V D; [: J3 u8 z3 W+ V
) O& i" x. A! P% t! [// Get a handle to the BOM Items.
" e# Z, q- W* F8 mItem bomItems = results.getRelationships();
. t$ X6 N* H7 z% W( A1 U2 J Pint count = bomItems.getItemCount();
. ]0 M/ d7 L( h. Q$ ?int i; 4 {- Q' ^. R4 F! y. L) q& K
- {9 o0 s4 L- p$ B3 `' ]' R// Create the results content.
2 J* ?' l' A7 `; ~# z* Lstring content = "<table border='1'>" + 1 N/ v, @7 ]+ N
"<tr>" + * Y5 T6 c: P9 R, L9 j
"<td>Part Number</td>" +
9 X0 b4 j- k4 Y6 b5 B6 U "<td>Description</td>" + ; Q4 a+ |# @$ z, f! `
"<td>Cost</td>" + . x x* o6 _/ Q
"<td>Quantity</td>" + : \2 h- H4 }5 i6 f
"</tr>"; 2 p y" ^* Z5 J) {2 g
" H: C/ M" v8 l) m8 \// Iterate over the BOM Items. 6 I" J8 ~% V7 q( i4 I1 m
for (i=0; i<count; ++i) ' Z: x. V; A) u1 {. E
{
: i, p/ t q2 K// Get a handle to the relationship Item by index.
5 ]( E9 A! M7 ~/ d, q Item bom = bomItems.getItemByIndex(i);
- | q$ w m7 G1 W// Get a handle to the related Item for this relationship Item. 5 E f7 F% _6 Y0 A' A1 R. {
Item bomPart = bom.getRelatedItem(); % W# c2 m' Y9 C( y% M
* B' \! c6 e$ y9 \* T
content += "" +
! b4 j( m4 f/ f4 Z "<tr>" + : [0 s0 b7 b3 g" w$ Y8 m4 W
"<td>" + bomPart.getProperty("item_number") + "</td>" + 4 m9 p+ P; _+ O6 j
"<td>" + bomPart.getProperty("description") + "</td>" + ( ]' C& s. Y D" s
"<td>" + bomPart.getProperty("cost") + "</td>" +
1 }7 y* F) \$ @- H8 P "<td>" + bom.getProperty("quantity") + "</td>" +
! u+ y9 v+ t s3 |& c "</tr>";
, f. E& ?9 D& A: r' @ Q2 B} 4 a6 P* W7 P- f- |8 N- I: ^5 `
content += "</table>"; 0 v. t1 W* w2 i- G# g" O
8 R; n( L. z' `) G9 F
return innovator.newResult(content); . q' k0 ]1 d# o. k0 w' X: x0 V
d( t5 P2 ^+ i1 \* M
9 U# }% j' D+ Y! {. r' v) c) U& I& W4 l0 i
+ W! q: R8 d0 ~9 l1 R% h3 b4 G. ~6 R' T4 X6 Y9 \" y
* b2 g' e/ f# @- T& ?5 P
/ r. _9 @& U* ^6 q; {# y7 i) g
Page 46
3 K$ E! s' _9 m8 ?* h. ]' @
( J' U3 F0 L* SCopyright 2007
9 s* Y) \4 |( h- _' |- h: vAras Corporation. ' B1 w) ~# y& V( O! ?
All Rights Reserved.
) z, H) K- }, C2 R) [* @VB.Net 1 S; ?1 u/ {; r; _; E
Dim innovator As Innovator = Me.newInnovator() - V( M0 p) o1 M, \ m, S
- w/ ]% t- g% r/ x2 `7 j) D' Set up the query Item.
# `) @* w& C% j4 CDim qryItem As Item = Me.newItem("Part","get")
# I) W5 x: Z# d8 u0 Z' IqryItem.setAttribute("select","item_number,description,cost")
! q u9 o1 |4 B3 E1 e) X4 n- i) [qryItem.setID(myId)
9 n- ^, K- T6 L" A, U- l5 s: Y: \ 3 f0 P( h5 B) W- [ Z& Z/ x7 D4 X
' Add the BOM structure.
2 r9 n0 B5 ?# p/ u" Q6 W y1 y: YDim bomItem As Item = Me.newItem("Part BOM","get")
) C; b4 |. v: Y/ _bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") # u; ~6 W+ t2 U/ j
qryItem.addRelationship(bomItem)
2 C9 P- m6 e1 v* t- w! B 7 c( Q0 N! O' |$ K% s! a* J! N
' Perform the query. 8 K+ V3 z9 Z. e* ~
Dim results As Item = qryItem.apply()
4 Z I% D9 ~# G1 H4 W: u
% G5 h! t5 D/ O) p- V |: L8 @' Test for an error.
) h( h$ n; X, P8 M0 T* {; MIf results.isError() Then
+ H5 ~4 ?2 v- c# Q/ k0 | Return innovator.newError(results.getErrorDetail()) 7 H" K$ t2 m4 Q2 d7 x1 @, e$ W
End If
6 w6 s" I& U1 c( J3 K6 } 0 C4 q3 D; E/ R) E
' Get a handle to the BOM Items.
- F. N6 d9 a9 @Dim bomItems As Item = results.getRelationships() 1 q/ j2 h# r) Q+ @5 _3 x9 F2 N, v
Dim count As Integer = bomItems.getItemCount() ; i8 r' \9 o, I9 d K* i) H
Dim i As Integer 7 W" ]. [- C+ e& m
' U% V7 O8 D4 U. ^+ m' Create the results content.
# ^* G V! \$ uDim content As String = "<table border='1'>" + _
9 z! W6 x1 r7 m! I$ w7 z "<tr>" + _
2 ?) q: e: h- E. W# M: a/ ? "<td>Part Number</td>" + _ , W+ C; ?6 z# c
"<td>Description</td>" + _
9 t2 y; p, J" X' J9 u' E/ K "<td>Cost</td>" + _
2 }; n9 ~2 a# Y% P "<td>Quantity</td>" + _ ) k9 L% a/ _- Y( P% ] \
"</tr>" 7 ^7 U" [ N5 E) q2 j6 N: T& Z
4 n4 Z' l9 c' A: W; V
' Iterate over the BOM Items
# ~4 N7 y: A1 [+ p4 E" M5 bFor i = 0 To count - 1
: i4 @# G5 `8 s2 w+ i' Get a handle to the relationship Item by index.
0 g( }+ X: s! x! K6 f) M' U! ? Dim bom As Item = bomItems.getItemByIndex(i)
2 d- U( k* h8 I ! O3 h: K1 I5 A
' Get a handle to the related Item for this relationship Item.
6 s% }( z% o: y# X2 p$ X Dim bomPart As Item = bom.getRelatedItem() 4 {: D; d$ h6 r: _
8 [4 |3 o( h; Q8 t9 K' j+ @ content += _ # z1 E: W4 b' J$ g* w
"<tr>" + _ # a& U. @- P4 |( l& z# z
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ I( G+ I+ A+ n' Y- G' R" f1 `
"<td>" + bomPart.getProperty("description") + "</td>" + _ . c) \& q. ?* D: ^5 T) D8 s
"<td>" + bomPart.getProperty("cost") + "</td>" + _ / {# \2 P3 N0 F7 G9 P0 M
"<td>" + bom.getProperty("quantity") + "</td>" + _
: N( g+ t6 b$ C' v2 c "</tr>" , p M# h, q+ T3 P3 f! i
Next
& S4 Q7 E2 I( L5 N' h" u2 mcontent += "</table>" $ ^, c# ^0 L. B1 I9 {
$ h$ m$ u4 L& E8 k7 b, _, E- @Return innovator.newResult(content)
, o4 F8 L* W1 g; i
9 ?7 q0 U+ k8 a4 r, x |
|