|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique - y" o- W. [6 O1 K3 \% T
To query for an Item and retrieve its structure you build the query as the structure
0 u- s! P5 ^0 Nyou want returned. Use the IOM methods to add the relationships you want and
& f8 O$ k% ]$ } F) G' Lbuild the structure in the Item. The server will return the structure that follows the ( M# m- ^) Y8 w; ^
request structure.
4 A2 l. @1 D, `- P% U3 eThis recipe illustrates several related concepts together, which are how to get a set 2 j* n- K* n2 q$ T( B7 Z5 d; d
of Items from an Item and how to iterate over the set, plus how to get the related
, I" q4 g" D* g: e7 I# ^Item from the relationship Item.
9 k) @& N3 V, }, O' Y/ ]8 @, |JavaScript
- ^8 d" A0 c6 T5 H$ Zvar innovator = this.newInnovator(); : O/ @5 L$ P7 c. [
; m6 v3 T1 |0 _// Set up the query Item.
* s8 B" ?3 \4 g4 Tvar qryItem = this.newItem("Part","get"); 8 ` i$ D8 G" a& ~% v5 W7 k
qryItem.setAttribute("select","item_number,description,cost"); 3 P1 c, U1 u: Q& a
qryItem.setID(myId); * l2 w! b6 B6 ]1 j
1 \' q+ R$ i" Z3 r* w5 b
// Add the BOM structure. / a- A9 B% P. D) f2 I8 [ w
var bomItem = this.newItem("Part BOM","get"); ( a6 n/ h, P6 g* [7 h$ s
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
% t0 N, R$ M a, M; h% e% j" fqryItem.addRelationship(bomItem); . ]2 Q8 [, g! @+ f! X0 [
: P: l" m3 D& v8 B: U
// Perform the query.
$ a5 x# j, g' J0 c+ Fvar results = qryItem.apply();
! I% H3 H+ Z; c2 N " X0 U$ ~9 Z4 s7 g% ]# r
// Test for an error.
+ H1 `& B9 q- U {+ Y" Y+ R3 Eif (results.isError()) {
/ F1 E9 I- F' [0 N top.aras.AlertError("Item not found: " + results.getErrorDetail());
8 N9 `0 ^7 C2 H d6 B+ x/ k+ G+ k return;
0 y% H; o* @; Z( q}
# X3 h1 [) J6 V: n4 H * K4 K( C, p1 t5 b, \) s) m% N
// Get a handle to the BOM Items.
( h( T( F( R6 m7 x1 j5 H8 F, ^: Nvar bomItems = results.getRelationships();
7 Z" j7 a" Q. b2 ~" D' T5 `9 ^ Kvar count = bomItems.getItemCount();
: Z0 m, R' n' [" j: g
/ {! H7 s6 V8 z7 U0 T- q/ n4 j// Create the results content.
& ^, }" \! Q- O* d! p l5 \4 `$ k+ Yvar content = "<table border='1'>" + 2 `3 i7 M: h; }& |
"<tr>" + 1 z, w0 f+ M% U2 U* p: m% `* t; x
"<td>Part Number</td>" +
* h6 H7 {4 [3 @7 y" y "<td>Description</td>" + " w9 B1 k" C: S2 z, V5 o+ F
"<td>Cost</td>" +
, u, V( O5 i$ O7 X "<td>Quantity</td>" + 8 R/ Z1 |% c# A# J( B7 N* R- @
"</tr>"; 0 o- _, m/ `; r: S) m T' z
; N( D/ ]' v# u! t! `. p! j// Iterate over the BOM Items. ' z2 |. ^+ A: a9 e1 C7 a
for (var i=0; i<count; ++i) 3 X& {7 A: [, i7 l8 u$ R% |
{
: ?& y; _, o7 d X2 U0 @6 p, d// Get a handle to the relationship Item by index. # p5 r. g$ U5 h6 X4 G2 x" k3 _
var bom = bomItems.getItemByIndex(i);
( c2 L& @0 u" _5 o/ }& u% Z- v// Get a handle to the related Item for this relationship Item. $ i5 G4 Q9 M* L$ {) b
var bomPart = bom.getRelatedItem(); ; j) v& V f3 J1 g# ]+ @6 N; q
9 ]; _. @1 H# ? content += "<tr>" + . t" l7 }% m8 q+ k1 H
"<td>" + bomPart.getProperty("item_number") + "</td>" + : P7 V/ k% `) U% ?& P& G
"<td>" + bomPart.getProperty("description") + "</td>" + , P7 d$ }, q! e) j) w( M' i" U
"<td>" + bomPart.getProperty("cost") + "</td>" +
2 @# V ^) J' h; f' M. B "<td>" + bom.getProperty("quantity") + "</td>" +
! d7 z4 O9 ]+ z0 x3 v9 q- o "</tr>";
) g/ H: G" H; [+ P}
. I0 P2 q# l' U+ Q8 @return content + "</table>";
8 ], g+ ]6 y, a! B. n2 n0 x# Y" Y1 p
& L) f# @8 {: H# V* Y3 G* _% }
. S* B3 m4 F6 H3 w; X6 G* t# `7 C7 |( e( Y& y
C# $ [- `) o9 a; a
Innovator innovator = this.newInnovator(); : o7 H" t9 d N* _
# N8 `: H% }: ^5 r: s
// Set up the query Item.
' S2 u9 _# R; E2 OItem qryItem = this.newItem("Part","get");
/ ~% d$ F; K( oqryItem.setAttribute("select","item_number,description,cost");
& a ?/ @5 d: c8 mqryItem.setID(myId);
7 M8 {. f! _. u- {$ {: z: [( t
0 S) \) L) g8 T0 q) B2 k// Add the BOM structure. 3 r p8 |; m" f, a, }
Item bomItem = this.newItem("Part BOM","get");
3 P9 t) Y% h" {! Z# wbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
- ^6 a1 ?6 O/ s, M( i% ]$ VqryItem.addRelationship(bomItem); 2 l6 c) K; O8 Y$ [$ N( H) b2 Q9 D
( X' A, V* b/ I// Perform the query.
4 @% {3 S2 J& ]( \/ O' h9 D: QItem results = qryItem.apply(); 1 c, d' s1 i" e$ o
8 z1 W* u# A2 n1 M& y T// Test for an error. 4 S. ^ c2 F Z! f( c
if (results.isError()) {
5 e9 x' g2 V0 f( M return innovator.newError("Item not found: " + results.getErrorDetail()); Z6 d1 S2 ~/ q" `1 @3 P
} 0 M0 T; _/ L3 ~' d* T8 p
: H7 p; E1 N4 A' s0 e7 K" Q' }& P// Get a handle to the BOM Items.
4 r. V; Y3 H, y* v+ DItem bomItems = results.getRelationships(); ( R m1 V1 _" I; B+ t/ n6 Q* E, Z7 t
int count = bomItems.getItemCount();
6 q7 j- j2 K6 G5 c2 }! x) dint i; . d0 } z6 D% ~% u; n- e+ s
. t/ L4 s* \* c* |: B
// Create the results content.
+ S6 l7 P7 j5 fstring content = "<table border='1'>" + ; H) I! b+ q. r# R: P/ ^+ C
"<tr>" +
- F4 w, t+ `9 y, D% i8 v "<td>Part Number</td>" + ) R' t8 \& M; w) E
"<td>Description</td>" + 0 W6 H* J2 M" g2 f" M0 K$ j
"<td>Cost</td>" + 0 t% B) T0 G" ?2 ?0 z+ D7 t! i: g
"<td>Quantity</td>" + 2 i2 Y% Y1 c% J5 Z6 C1 V
"</tr>"; ' N1 x9 t2 ?0 T9 x" O) }" U1 h% q/ r/ x
) v( F/ w% ?2 c; M4 r3 N2 r" i
// Iterate over the BOM Items. & p6 U! J, Q- c/ j: r
for (i=0; i<count; ++i)
- ?/ M! E2 }7 p c( x K: I{ 6 e! `: w! T, Z( J: ^. x) f/ H. a
// Get a handle to the relationship Item by index.
2 x/ i9 e3 \. _1 _, u Item bom = bomItems.getItemByIndex(i);
% Q# {. {6 i; [/ n) m5 P" k// Get a handle to the related Item for this relationship Item. & V5 ` ~; O7 N! L2 ?/ k
Item bomPart = bom.getRelatedItem();
! L$ P% ?- C0 \ ) e9 J9 q: l/ I
content += "" +
% I1 p8 J0 c( ^8 n" | "<tr>" +
! V/ ^" _8 ^3 W3 t "<td>" + bomPart.getProperty("item_number") + "</td>" +
, K' }1 ~( c; O "<td>" + bomPart.getProperty("description") + "</td>" + ' n: v+ K# \% s7 D
"<td>" + bomPart.getProperty("cost") + "</td>" +
6 f9 N+ G" S: m0 F4 V; c! j# H8 o: q "<td>" + bom.getProperty("quantity") + "</td>" + # L+ D+ d! G6 S. R* b2 ]5 l' D- i* D
"</tr>";
: r' M8 u# S3 k! @}
4 }* R1 P1 s7 ?$ ycontent += "</table>";
q k* z c" p0 [$ B
3 r+ M/ f0 i9 B$ yreturn innovator.newResult(content);
2 z! a9 p, S) S. J/ O$ t4 j6 s: Y! {6 B
. R6 ]( `. s( N! a1 M
# C* G/ [' ~+ q+ y
9 E! C+ o0 S8 ~! X
$ f9 m! P1 j, o# K5 M
& a' h2 u7 a' p3 f1 V
. H! B, y, t) |2 ^% g Page 46 7 I. h7 Z8 k& s. W0 C. I
: e2 w$ f7 }' P, c2 V8 GCopyright 2007
; B: g- C5 H+ ?- Q dAras Corporation. ; L' q* r- M& c6 Z$ \
All Rights Reserved. " h+ H f( B# K# ]
VB.Net
S& N9 |5 X9 XDim innovator As Innovator = Me.newInnovator()
* l) O3 E& s( d4 c" |' x/ |) r
3 A3 G! y1 c2 `2 C% S) D' Set up the query Item.
+ p. C* \- ^+ J& [0 o* zDim qryItem As Item = Me.newItem("Part","get") - m6 C: `; s, A: @6 c* a' o0 Y
qryItem.setAttribute("select","item_number,description,cost") , b& e/ q# N$ J. L \9 v9 k$ ~" H
qryItem.setID(myId)
$ a9 J \: p0 W, u& D0 \ , x) ]# R/ m1 V& m. V6 k
' Add the BOM structure. ; h6 z1 p' a6 F I2 R6 k$ c
Dim bomItem As Item = Me.newItem("Part BOM","get") % R6 O h ^4 k7 m! i8 P8 w
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") & \. M; Z/ {7 f2 x
qryItem.addRelationship(bomItem)
1 U& Y' C+ d5 g! [) Z
+ K E: p/ J2 J. ^, ^9 d+ i* ^' Perform the query. 0 l6 S) [( t8 [& f
Dim results As Item = qryItem.apply()
' K3 o. O3 ]# {! @6 s6 p
3 `" [8 A) B' [2 q' Test for an error. / d) ?: W C( z2 Y
If results.isError() Then
; ?; g3 z0 K) y/ Q Return innovator.newError(results.getErrorDetail())
' S% a1 L7 D. }- }; G5 |' zEnd If
2 M' b% d( |9 `1 |* V a) I$ u 0 i/ H. m: Q/ E; m
' Get a handle to the BOM Items.
: r5 m4 H9 Q8 U0 m. P8 o' ^Dim bomItems As Item = results.getRelationships() * ^3 @" c) K5 u& P! b* e
Dim count As Integer = bomItems.getItemCount()
& ~/ I$ p3 U4 v2 [Dim i As Integer e+ x* o# f! O/ y- A2 X7 J5 A
# f- ]; ^% r2 |* B
' Create the results content.
" o" }/ g i& ~6 m- |/ cDim content As String = "<table border='1'>" + _ 8 @3 W- e/ @, b. W4 u
"<tr>" + _ ' ]8 ~7 k7 n) g4 n# A9 g
"<td>Part Number</td>" + _
* ]' E* M. C" G2 w b: _/ \ "<td>Description</td>" + _
& S" x& e& i% Y. n "<td>Cost</td>" + _
$ {, d7 d: Q2 E5 i "<td>Quantity</td>" + _
! p- e' B- O" h$ p# A9 n "</tr>"
8 ]* L, ]: a" e9 g! k$ z. C
, m' s& q# }1 M. ~& \5 H, E' Iterate over the BOM Items ; x) t% _+ v X4 J
For i = 0 To count - 1 8 r: A. Y2 `: @7 H& K I& D
' Get a handle to the relationship Item by index. + N1 c; u0 K3 n7 F* k5 @) s; y2 Y* H
Dim bom As Item = bomItems.getItemByIndex(i)
" s* h2 G& U. Q e
0 M/ M7 p! k) K7 s8 ^( M' Get a handle to the related Item for this relationship Item. . k6 h: K5 T4 ^7 T0 N- W/ j: E
Dim bomPart As Item = bom.getRelatedItem()
' f0 T8 u$ F9 h8 A/ N 4 {+ A: P6 r* ~
content += _
9 D0 Q3 k" u E, e "<tr>" + _ ; d5 u$ d; f+ [; I9 [7 L
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
m+ z3 f8 M* X6 W- B "<td>" + bomPart.getProperty("description") + "</td>" + _ 8 A h6 c, m; J" M. y
"<td>" + bomPart.getProperty("cost") + "</td>" + _
4 W+ r, Z6 B/ ^! S6 U8 f! u "<td>" + bom.getProperty("quantity") + "</td>" + _
* @& A4 w1 o5 f7 n4 b1 h; M "</tr>" ' ~9 S/ R( }" _" Z, A* m4 L7 G
Next
`7 Z( g+ V7 [& z3 |1 A3 kcontent += "</table>" ( F, }) [) p! L0 o z8 L: @
5 F' }% r8 g% A3 H% w aReturn innovator.newResult(content) ! v$ _; r) q# n( q0 p) D9 I
, U" F6 g& Q! Q( _& l y |
|