|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique - ^- w# |2 ]" V8 U% g. g
To query for an Item and retrieve its structure you build the query as the structure 8 m- n5 W0 _; y9 p4 d+ [4 g
you want returned. Use the IOM methods to add the relationships you want and
9 @8 e, Q0 i+ X9 ]build the structure in the Item. The server will return the structure that follows the
( f j& n+ a- c7 A& B: @request structure. / I9 ]2 e$ h6 s' b$ p3 y
This recipe illustrates several related concepts together, which are how to get a set / r3 n3 A, y+ a7 M; v; a4 W& K
of Items from an Item and how to iterate over the set, plus how to get the related
5 Z/ H, [0 b; M8 `, t0 v+ u0 M7 TItem from the relationship Item. ; {$ D/ W- n3 p3 a4 l
JavaScript $ @$ d/ X7 d+ l: L
var innovator = this.newInnovator(); 0 O/ f& u/ b7 v2 B
( G# Q; a1 C1 K9 ]& O1 A// Set up the query Item. ! n- ]! ?* i) A" r' N* n4 X
var qryItem = this.newItem("Part","get"); 1 a. ?) _, x# ~7 N) _* u" P8 ?% x
qryItem.setAttribute("select","item_number,description,cost"); + a; W7 h8 a- L1 l* l
qryItem.setID(myId);
0 N, ^, W4 G5 M; H0 q
: B/ | f2 D! s2 @2 f// Add the BOM structure. 1 Q. q; }& v, X- h0 _- r/ ^* m
var bomItem = this.newItem("Part BOM","get"); $ G; h) R9 p' a- x0 \8 `& C( S( {$ a
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); * O6 V' @) p2 K5 r' ?5 m# `
qryItem.addRelationship(bomItem);
9 B& H" r+ Q1 o7 P
4 H) n$ d* o1 y8 k// Perform the query. 2 B# g1 d* r- }$ F
var results = qryItem.apply();
; P( P! n* C, b, a2 J1 E
& `6 _2 v- c- }" E Z, O// Test for an error.
- M8 u( h2 g! }% h: Oif (results.isError()) {
/ W) C& X8 R- Y# | Q top.aras.AlertError("Item not found: " + results.getErrorDetail());
' _+ b5 _' U- b. I* Z1 `7 ^+ Q" ?$ x return; ) v- L v$ q- f3 F$ b
}
( k% M6 d/ e) P% Q* {: e' q
1 B" b' _: z+ x) }% `* Y8 D, j. t// Get a handle to the BOM Items.
# w9 T' X1 ?) i7 p+ U8 @var bomItems = results.getRelationships(); # z6 S9 \& V7 P2 v
var count = bomItems.getItemCount(); / y; z. b2 } ^& |! b
# l' I% J5 c2 L) P4 V
// Create the results content. 0 r1 Q4 Y- s$ z5 D; m% h1 O
var content = "<table border='1'>" + 7 J, U. w1 g' Q' ?
"<tr>" + 5 w& f" z$ Y5 U+ |* G" ?7 G' z
"<td>Part Number</td>" + . f0 g. [0 B! k
"<td>Description</td>" +
( Q! U9 P5 ?. W* e$ t5 w "<td>Cost</td>" + 6 t) m0 t ]4 x0 _! p
"<td>Quantity</td>" +
% [; E& `4 ~8 S4 h3 T4 _ "</tr>";
+ c- Q9 e- J' e1 R2 e) E7 ~" e
+ t5 \( D" Z7 @$ I. [) @// Iterate over the BOM Items. ( O! G; `! J9 D1 J1 {# Q# v
for (var i=0; i<count; ++i) ! b, y- G( _2 J" l- ^. p
{
* \5 b N3 O' q2 Z1 f) i& Z% c// Get a handle to the relationship Item by index. $ ^" f7 B$ ]0 [) F
var bom = bomItems.getItemByIndex(i); ( G2 |% G8 d" H/ \. w
// Get a handle to the related Item for this relationship Item.
! \# ^* k5 L3 F+ E6 X& J: P var bomPart = bom.getRelatedItem();
2 ]+ x1 T7 ~0 k' @$ |3 J2 G3 `8 H4 ` + A. ~& W' C& K0 \
content += "<tr>" + # h- |% @: f' u1 Z$ l' L: ~- ]
"<td>" + bomPart.getProperty("item_number") + "</td>" + , l5 M) W7 L: e7 U* v2 N) @" { a
"<td>" + bomPart.getProperty("description") + "</td>" + 9 I: l- C1 `" V, q. R3 z' b
"<td>" + bomPart.getProperty("cost") + "</td>" + }/ t5 L, l9 |
"<td>" + bom.getProperty("quantity") + "</td>" +
& q2 B% m* G, i' x3 q% Z "</tr>";
) X5 N8 [( ?! |' Y7 |: ?' @3 @}
4 G' `* T- q. C" M6 o, jreturn content + "</table>";
& t/ J G, ]5 R; u6 `" C: @+ I) S- A, h; S6 L% \7 K& ]
/ s4 J' T/ [7 d( [! R K
0 S$ G* T& x" h+ i3 d
( {% C# `3 P* f8 n6 lC#
5 Z8 h6 B g$ MInnovator innovator = this.newInnovator();
6 y% g1 m9 t1 u/ M$ f7 w3 ^
1 |) @! N2 M% b5 l6 F// Set up the query Item. 6 H4 ^& K4 \$ K# u: S
Item qryItem = this.newItem("Part","get");
3 Y7 D2 t+ Y/ M3 v u" z; K% ^' QqryItem.setAttribute("select","item_number,description,cost");
' i" z& N! X$ lqryItem.setID(myId);
" s n) V9 i, l& i9 S* t # }# W v; \1 q1 }- O- K+ V4 @
// Add the BOM structure.
( n3 R; V# U# `; XItem bomItem = this.newItem("Part BOM","get"); 4 l# x7 o) _- {; G
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
; Y+ J7 B9 i0 P8 ^, SqryItem.addRelationship(bomItem);
! }* ~, D- O$ Y j) K1 Y- J1 p 0 _. F7 z& M& k/ [6 t9 t4 {
// Perform the query. - Y! }+ H# g2 A
Item results = qryItem.apply();
0 o$ t9 ^+ V# J% n+ _/ J0 b$ S
" ? { E- l3 K7 Q" H6 W// Test for an error.
$ {* J t$ t8 l7 ]' |! Lif (results.isError()) {
9 l' r9 G9 \1 K$ W% g. I: k return innovator.newError("Item not found: " + results.getErrorDetail());
& |+ O1 h, B2 f5 b0 s( u, G) ~- F6 N} # L4 T; w: W( ^, p
3 D T1 B6 F! j+ S3 [. `3 F// Get a handle to the BOM Items.
4 g4 z. V( Z3 u7 `) J$ XItem bomItems = results.getRelationships();
1 @) K7 ^, g* c& K0 xint count = bomItems.getItemCount();
& J1 D3 \9 g* Z) S1 k/ n" r, Kint i; # i9 N) H- w+ w5 V$ |
- e- y1 M, w: } F5 W: [& O
// Create the results content. ' k; {& o S4 G6 u- N, N, q9 ^
string content = "<table border='1'>" + $ L4 b3 @% D' X; D9 h' O
"<tr>" + . n; {0 w2 K( n* T: l4 e
"<td>Part Number</td>" + / j' }. z: z4 m' c' r
"<td>Description</td>" +
+ M) T4 m0 W; i$ U "<td>Cost</td>" +
- P' l, m; l4 R A8 E "<td>Quantity</td>" +
( R' @, _0 N7 l% n1 ]7 ` "</tr>";
4 E- {! A" s( I) s/ F/ T ' T" h8 B6 [" d7 _# @6 h$ g, a2 h5 F
// Iterate over the BOM Items. l9 j4 a3 _6 M. t
for (i=0; i<count; ++i)
: I8 y* p4 w' J) f' L- D9 J G# ^" p{
% V7 C& m+ l" P3 v// Get a handle to the relationship Item by index. 5 C6 A7 X' C9 T% p4 p5 Z$ E/ L
Item bom = bomItems.getItemByIndex(i); : c! I1 I+ y! U- N9 Y
// Get a handle to the related Item for this relationship Item.
9 l2 l8 \2 l% Q6 ]8 I9 u Item bomPart = bom.getRelatedItem(); ) d5 b. k/ C% D# y! n
- t5 w9 c" R6 [, F$ h) C content += "" + 8 w" F; u* q0 n
"<tr>" +
5 s. R* J9 i& t8 } "<td>" + bomPart.getProperty("item_number") + "</td>" +
& f1 R8 }1 ~* k3 e L. u, v "<td>" + bomPart.getProperty("description") + "</td>" + ! M. w) B: D) J2 I. r
"<td>" + bomPart.getProperty("cost") + "</td>" +
- s" A$ K+ s% n: Y: u' g" l" p "<td>" + bom.getProperty("quantity") + "</td>" + ; A# i! t# U" z0 u' F+ t; a" C- Y
"</tr>"; 2 p- v: v# J% v( |2 B6 Z) b# m
} 5 o, q" K9 b4 T8 ^
content += "</table>"; . ? V" m5 X [8 A
1 x+ C( s0 X( B% T# ?! Q- Q
return innovator.newResult(content); ) u) {5 A. M2 J$ c- U1 I
1 G1 g( n+ o$ \2 `* @6 I5 k
6 n2 _: m5 y6 S$ e2 y
6 B6 l5 j! l2 H2 D& d
* `7 X2 @' C4 c$ @+ e/ ~ m' U1 p! @. G; _/ B, X
: }; s' c& J$ ~7 t' q 6 r- h" C+ q2 d! p: A, M
Page 46 6 V$ y. {. E0 V% ~) I" w; M
/ @" F+ L7 ?) V( x+ dCopyright 2007 4 D' E8 [ J% f- a% t0 `+ t
Aras Corporation.
! r: T/ k% K& a, U1 H, R' UAll Rights Reserved. 4 R( Z7 \+ Q5 g; f2 E4 g3 q) ]: [$ b! b
VB.Net 9 {7 p+ s8 m+ _5 k2 v/ J: ^9 v
Dim innovator As Innovator = Me.newInnovator()
& n! f' e- U1 A8 B, @% N 7 A8 u: a3 |1 K" ~5 l1 m
' Set up the query Item.
9 L3 b1 l0 S2 C% W# u: h7 gDim qryItem As Item = Me.newItem("Part","get") 4 l; e! d4 ?" q9 ~9 v% c8 t8 r2 W
qryItem.setAttribute("select","item_number,description,cost") 1 t0 j' U1 [4 m% l, w. i# X
qryItem.setID(myId) 8 A4 a; d3 E8 [- I% b" p% j( J
9 }! A8 \3 @. G8 v2 [9 h8 W' Add the BOM structure.
6 W! K% ^4 w, N( _Dim bomItem As Item = Me.newItem("Part BOM","get")
/ y! ? ?0 j: L$ d2 C- m5 j; _bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
1 j) G8 i8 f% |, D* ~' RqryItem.addRelationship(bomItem) w, M, V8 [% @3 f) C k
& z7 u* Z5 |/ a. d; F$ U
' Perform the query. ( p/ e. Z& l/ [4 a2 K
Dim results As Item = qryItem.apply() ) e6 u' V* E% A+ i q6 d
/ X7 u( m, O9 e2 q3 x
' Test for an error. - l) y0 y |/ K
If results.isError() Then $ R# v% i9 i5 w. i
Return innovator.newError(results.getErrorDetail()) ; Z/ j* J5 F) w
End If
+ h) n- w: e, ?5 ^6 s1 T $ O- V% A$ }7 @8 L/ |0 K; z
' Get a handle to the BOM Items.
. o, X3 z+ F5 T" ZDim bomItems As Item = results.getRelationships()
0 w$ B; P6 Y6 t1 p" uDim count As Integer = bomItems.getItemCount() + @! z5 F( }/ v" r+ x% C8 C
Dim i As Integer B1 ^8 r; {* y* {, u- w4 E ~( E7 m
" h' l* [& ~. {' P- z' u+ p
' Create the results content. - k1 w# H! m! U* B# b2 i
Dim content As String = "<table border='1'>" + _
2 ?0 q9 G8 r1 M) P: s V# ~. M "<tr>" + _
; z$ A- Y' D+ b9 n. i5 z; C "<td>Part Number</td>" + _ ( e8 b4 A$ h& X( A' F0 ^
"<td>Description</td>" + _ " A# X. X$ u9 j) c. g
"<td>Cost</td>" + _
& U9 Z. l s* T" E1 R "<td>Quantity</td>" + _
4 C) n, f( R" j9 H ]4 o; Y "</tr>"
5 I" O6 n" J4 q& _4 t
* u- [/ D: Q; C1 C4 R/ U- l2 ]7 O' Iterate over the BOM Items
1 G( p/ F! T- {3 u. RFor i = 0 To count - 1
% n0 X a' m! O1 ?' Get a handle to the relationship Item by index. + U0 @4 K5 v; i; \! a
Dim bom As Item = bomItems.getItemByIndex(i)
" h) u7 y; p9 k% |% n4 @1 F
, ]( ]0 f- `+ ^. n* c' Get a handle to the related Item for this relationship Item.
0 l0 v+ B" ^( H Dim bomPart As Item = bom.getRelatedItem()
/ G/ l, w `" G! X! { # ~, E# D' o3 y% X
content += _
/ ]# X% M6 |$ \0 X "<tr>" + _ 5 d0 S9 h& q$ y8 Y: }+ ]7 e
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 2 l+ x. X9 n0 V; s
"<td>" + bomPart.getProperty("description") + "</td>" + _
3 w4 _ f" g! } "<td>" + bomPart.getProperty("cost") + "</td>" + _
/ h' o! k- H% Z "<td>" + bom.getProperty("quantity") + "</td>" + _ : Q8 F+ m$ i) C/ |; Z, X/ m
"</tr>" 9 T$ H5 S0 z" ]
Next
0 {1 B3 Z+ b! q+ g+ K I) ]content += "</table>" : j; [7 R' A2 o* _% n/ S9 i
- Y' d5 Y2 }( [# S6 y% ?! e
Return innovator.newResult(content)
8 _8 d' p4 l( L$ J. W3 x$ l) K$ @: F4 H- E7 |( k
|
|