|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique , G8 r* ^( J+ R0 {# [
To query for an Item and retrieve its structure you build the query as the structure 2 L; }: |3 {$ u: e* U
you want returned. Use the IOM methods to add the relationships you want and ' U. z' e; S9 d# X8 x% O
build the structure in the Item. The server will return the structure that follows the
2 p! S ^3 X. B" rrequest structure. 4 r9 p2 f, S3 B! n' C/ z
This recipe illustrates several related concepts together, which are how to get a set
) |* {+ c4 M/ G0 s! I% u" y* m% F$ Pof Items from an Item and how to iterate over the set, plus how to get the related
+ Y6 ^! c; i/ j4 v N9 x9 [7 UItem from the relationship Item. 2 R: t4 E( g; X3 s6 {) a
JavaScript . g: C$ u' s/ t* r6 K
var innovator = this.newInnovator(); 6 b8 l; Z+ x( }% b( n
9 Z4 ~- a6 S3 u% c+ A* P// Set up the query Item.
|, f& t7 T+ S) M$ S& f/ G6 I! k8 f, Qvar qryItem = this.newItem("Part","get");
) V! l3 C% u5 F1 p( \; o+ yqryItem.setAttribute("select","item_number,description,cost"); 9 B K, d/ F& B. S4 C" A
qryItem.setID(myId);
K6 X/ R; h; F* h" d) ^
3 ^6 \7 U% R e* H// Add the BOM structure.
- X6 j( V- W% }& H& U" Fvar bomItem = this.newItem("Part BOM","get"); 7 x1 v* U0 |' ?! W) B9 m# T4 ?8 i& J
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); , V2 T; a' l0 r
qryItem.addRelationship(bomItem);
( x4 V) C6 f0 B1 O
B2 k0 ^. v' s1 N1 E// Perform the query.
4 |+ t- r* S! z' Q: I/ Gvar results = qryItem.apply(); ) x$ j! W% g' ^7 _8 k
' G. d7 ?4 k, X; K% i, o// Test for an error.
9 y# q+ U2 L% e6 oif (results.isError()) {
# w% Y' D8 W2 H. G) q- l top.aras.AlertError("Item not found: " + results.getErrorDetail()); o5 B9 Q2 L3 B. n6 T6 Y l) H
return; 0 O6 j( n" `1 ]) O3 H
} 4 l5 j1 w1 i) F' d
- r: V0 F9 Z0 T
// Get a handle to the BOM Items. - z2 n7 ^5 U. t
var bomItems = results.getRelationships(); 5 I" c, Q; P9 q- d! j2 u5 w
var count = bomItems.getItemCount(); - Z7 ^; V2 _3 E( @
, H" w s8 C7 J0 Z3 s# E6 b// Create the results content. 2 V5 E8 L1 Q" M& G: A
var content = "<table border='1'>" + ) J4 c/ z& Q9 h
"<tr>" +
6 {6 a/ ~. a# f0 F4 s "<td>Part Number</td>" +
" n' A- H% m/ z "<td>Description</td>" + + J( K8 W, ?7 f$ d Z8 y) ^
"<td>Cost</td>" + ! m, [& h7 Y" T9 }, f
"<td>Quantity</td>" + 8 y' ?% i1 L+ `9 F. G2 M
"</tr>"; * p/ K: o, n! ], v: b
0 w' G$ Z* G$ u R5 O% A. g, @
// Iterate over the BOM Items.
' ]& L, g. U/ ^3 B; Cfor (var i=0; i<count; ++i)
5 i2 U' Z+ J2 ?8 p+ Q{ 2 @& [ ~! h+ n: h" t
// Get a handle to the relationship Item by index. % B1 W$ z# _# J2 n; C6 a
var bom = bomItems.getItemByIndex(i);
- H' {* `3 }4 p$ R) I% `4 l// Get a handle to the related Item for this relationship Item. 4 C5 I1 ^/ _1 x" C& i' }# K
var bomPart = bom.getRelatedItem();
r) h' |. W4 a4 h; \3 A: E ( R: C. G" c3 A, w, x7 h5 L& a/ E T
content += "<tr>" +
) @4 m3 }# [% h8 {& a/ z6 }, F "<td>" + bomPart.getProperty("item_number") + "</td>" +
1 w0 v8 @& g/ b "<td>" + bomPart.getProperty("description") + "</td>" +
0 z, L* s2 h/ H7 v "<td>" + bomPart.getProperty("cost") + "</td>" +
0 Z1 ~/ h. ~0 L5 G- |& E. O W& o" n9 b "<td>" + bom.getProperty("quantity") + "</td>" + 2 M; M \- c" \- @
"</tr>"; ) G4 P2 V6 N! q/ w' {
}
; o( r& }* Y: n9 preturn content + "</table>";
" ?, z h* ^! G
( T, o. ]- V& K8 j, q8 N2 @7 x$ J. u( o
2 `' R* m! H. s" v7 P4 Q' ^4 L. d; t) b/ S" I% F" b9 b/ O
C# 8 i* a& P5 I; g
Innovator innovator = this.newInnovator(); / |, |$ |3 q7 x0 I7 P) S" {
. x2 U. R8 y) a: a& c; G3 i
// Set up the query Item.
! D6 J# ?) i, _5 N8 NItem qryItem = this.newItem("Part","get");
% s6 U6 i$ z/ K8 W3 lqryItem.setAttribute("select","item_number,description,cost");
1 i$ s0 z- |) G9 x% ~qryItem.setID(myId);
3 O0 D9 q, y0 E; C+ B
5 `/ V- d" b* p, U# H$ N: ?// Add the BOM structure.
a4 l$ v5 P7 }/ Q: fItem bomItem = this.newItem("Part BOM","get"); . s$ R( s y$ Z% n- @( m. V. z
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
0 J+ d4 \" e% D- d/ n5 N9 ~qryItem.addRelationship(bomItem);
X# k) H: ^( K% f$ H1 W/ c5 K
3 E; `% {2 p' Z6 R// Perform the query. - C1 y8 {5 b' S$ c+ a5 C# O
Item results = qryItem.apply();
+ M8 s5 g* @- Q 3 {/ c6 T! z) A8 R, C7 J
// Test for an error. ! U x. X4 v5 C7 m& t
if (results.isError()) { . M0 {" n l; Y' @
return innovator.newError("Item not found: " + results.getErrorDetail()); 6 w; U- ~' [& @* x
} 5 f: Q3 @ O7 i0 |' w+ k" m
& P, T& f. g4 j4 T3 [
// Get a handle to the BOM Items. ! I9 p0 B' c3 Y% R
Item bomItems = results.getRelationships(); 4 b( N6 d; z/ n1 U/ [: \' s( ?
int count = bomItems.getItemCount();
, A2 T3 H" {, C" i# }/ W3 A% Rint i; 1 n- ^) G% h j" A; K) i+ x
, F& |: G1 ^) u
// Create the results content. " G6 C7 ?3 U& j5 X
string content = "<table border='1'>" + * S8 Z3 m- ?* {5 k) c( ~: z
"<tr>" +
- s0 N: }8 E* r5 q" D "<td>Part Number</td>" + 3 z) e |# U9 j+ f% [3 E- y
"<td>Description</td>" + 9 v) O* H4 k G6 K
"<td>Cost</td>" +
! y6 }, U: s) O$ E/ C/ V( I; k- t! W "<td>Quantity</td>" +
, e# `: U# k6 w% f "</tr>"; / Z# O( O# S# c* u
/ ?+ O3 x R+ y" {% W! p// Iterate over the BOM Items.
8 I3 s: w; `& U6 Z+ S: `3 R+ dfor (i=0; i<count; ++i)
" w4 G: {& \) L: {2 i5 {{
& Z8 z3 f2 X1 t( a' d6 C// Get a handle to the relationship Item by index.
7 t) X& M4 L; L' Z d8 _* I- B9 r Item bom = bomItems.getItemByIndex(i);
& [5 g: c6 B9 j2 o// Get a handle to the related Item for this relationship Item.
3 I; ?2 I$ I( {/ Z$ |, C' E Item bomPart = bom.getRelatedItem();
& Z" a/ D$ H8 m z) |* ` 0 C4 Z' G5 @" G1 q8 \) A* h0 O
content += "" + 7 G; U) R* [, P$ j
"<tr>" +
5 {+ q6 p8 B1 }9 W0 V- n "<td>" + bomPart.getProperty("item_number") + "</td>" +
3 p- }/ p1 ]- n, x7 o7 M "<td>" + bomPart.getProperty("description") + "</td>" + ; u, R- E- b- {' h v7 T
"<td>" + bomPart.getProperty("cost") + "</td>" + 4 [$ f" g& ^ W# h* s
"<td>" + bom.getProperty("quantity") + "</td>" +
" a. {. A) I* L. b4 ^2 {, \) n, w "</tr>";
" _; u7 `6 l' }0 V+ V8 b}
9 c' l6 ]/ U$ b4 Pcontent += "</table>"; 8 T: t: g7 M* @# a
5 z1 ]" _8 o) Z) s( L3 S
return innovator.newResult(content);
: T' K$ r9 [% k6 e% T; x1 _- M
" p, j, j& S& Z; i
9 d- y1 X9 H' L. V5 T2 }' ~
# w3 j0 i4 ~0 }9 p6 A
1 r! \1 O8 F. ~* ^2 f" l! u; b' s! o5 q( o& o7 e+ p+ C. S7 {
& A4 F+ `6 b& _0 q' d
% j+ C8 D; Q7 `; Z, O Page 46 2 n6 O; ]2 i; ~& M4 q$ O9 D B
5 J0 L9 s7 l) s3 T2 ?) HCopyright 2007
& T. v3 c9 x* P2 j a2 fAras Corporation. 9 Q, D$ d+ z! W0 D; n7 N
All Rights Reserved. ( f7 A, a. ~6 v$ n' ^9 M
VB.Net
! q) v+ F% r* j' ?# F7 HDim innovator As Innovator = Me.newInnovator()
# f7 `. L- g9 b" F; f+ }' e
" w' B8 l5 h j$ y' Set up the query Item. . g- v! e; o: s% L/ o3 O
Dim qryItem As Item = Me.newItem("Part","get")
) a% c/ C$ X) z$ b) x( OqryItem.setAttribute("select","item_number,description,cost") ( W: @2 q. X9 ?; R' z: v$ \4 F
qryItem.setID(myId) 3 v6 q; j% [; A, u7 z: A& _5 h
: y( @+ W! V( m4 j) |) W! m4 @
' Add the BOM structure.
O/ c) T7 I9 Z1 g* c) A- x: W: JDim bomItem As Item = Me.newItem("Part BOM","get") 5 Q |6 G0 W/ Q3 |
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
2 U: _& ?) [1 aqryItem.addRelationship(bomItem) ! U: I! g1 l6 {2 S0 Q& a# e
, i! S Z5 f# t7 l/ W0 G v0 ?6 D# L
' Perform the query. ! o( {# b7 ~& i0 S
Dim results As Item = qryItem.apply()
8 \$ B. G5 | [: W% G$ w) ~, T - m9 {6 z5 b, M: p" ]
' Test for an error.
$ O/ p2 f1 Q; rIf results.isError() Then % o5 T" Q- B. p' y
Return innovator.newError(results.getErrorDetail())
& Q, L% m; K5 X* c6 ?! {End If 0 E; h9 q* l- R4 Y
6 Z' j: ^' j3 ?3 n/ k3 R
' Get a handle to the BOM Items. : G2 _/ u4 H# a4 x1 Z, r ?
Dim bomItems As Item = results.getRelationships() 4 b- g G8 I% c# _
Dim count As Integer = bomItems.getItemCount()
; d4 F! |+ `+ R- D- K `* M9 yDim i As Integer
0 o5 B& ]* e$ H8 h0 a5 ~ & b1 @- l9 G% g! T0 B( J# k
' Create the results content.
/ R4 e" D3 O* V$ R1 @. [Dim content As String = "<table border='1'>" + _ % g1 ~/ `/ E& s; n: s3 C; w
"<tr>" + _ ! X3 ?4 t+ ^% m# Y6 p8 Q z
"<td>Part Number</td>" + _ # z% _0 ?! Q R( g( p( M0 f
"<td>Description</td>" + _ , X9 r. Z* o( C
"<td>Cost</td>" + _
$ R1 h$ e; A4 H "<td>Quantity</td>" + _
8 A6 H+ M: I. n "</tr>"
2 d" @2 {4 |: t7 s: d* w: h, D P ! C$ f6 W h$ P3 I
' Iterate over the BOM Items
+ H2 B1 {1 f3 c2 H. S$ F! Q0 qFor i = 0 To count - 1 0 v4 }; V$ K9 b2 f$ d0 [$ w
' Get a handle to the relationship Item by index. : j1 B0 c2 h" Q+ t3 J5 n; ^# N; R t
Dim bom As Item = bomItems.getItemByIndex(i) 2 @% U9 L) K2 @" d' O
) x- N- v) F- p5 ~) q: k1 I3 K' Get a handle to the related Item for this relationship Item.
2 H/ Q4 o) L8 E! A+ S: @7 g Dim bomPart As Item = bom.getRelatedItem() 0 X( S5 \1 x9 b5 p; D9 K- [
& p# u$ |; p: [! u content += _ 0 { b$ h/ o7 K8 a/ P
"<tr>" + _ 3 e1 W4 ^# f/ V2 t" a* }* x
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 9 L& h, K* C/ u# b; i. H+ r( c( r
"<td>" + bomPart.getProperty("description") + "</td>" + _ # O A) x$ ]+ M. ?( X& U5 w
"<td>" + bomPart.getProperty("cost") + "</td>" + _
1 A$ \# s% \/ I# k* W1 Y/ F6 L "<td>" + bom.getProperty("quantity") + "</td>" + _ / c8 l% G8 _1 x) ]; v) i
"</tr>"
0 S! ^& d" o: C# N* sNext 5 ]5 D6 ~% ~# u
content += "</table>"
5 Z7 v+ E( a# N% [- b3 j1 X8 F + A4 Z5 \3 C, e4 w3 g B
Return innovator.newResult(content) $ v& ]; l6 Y: }+ d; M
2 [9 _& m; B6 e% W# t7 D7 p9 N |
|