|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 0 I! I* D8 ^( P& _0 U% I9 ]
To query for an Item and retrieve its structure you build the query as the structure $ ^" ?; Y* Y/ X/ Z) a, s' T2 Z d
you want returned. Use the IOM methods to add the relationships you want and
9 n0 ]. |3 }4 ~3 g0 E* y/ j( Y2 Fbuild the structure in the Item. The server will return the structure that follows the
0 V) I# m' V' E. ^: B5 T" F# }request structure. w0 Y0 W0 u3 A" O0 `. k1 |5 g
This recipe illustrates several related concepts together, which are how to get a set
2 Q! x1 M) y# |/ z! H0 |$ Tof Items from an Item and how to iterate over the set, plus how to get the related
5 f' K- K% q7 V) \7 K G4 SItem from the relationship Item.
0 ?. b* C( W# y5 D# o9 V d3 ^- [JavaScript
& h, }' a9 I4 q4 F& svar innovator = this.newInnovator(); % i" E. L0 C1 A8 { x: h
4 F$ D0 ]4 I( C( [' V' K& n* a2 |
// Set up the query Item.
* H7 K" b: Q; qvar qryItem = this.newItem("Part","get");
" X" t/ j3 ^5 P0 TqryItem.setAttribute("select","item_number,description,cost"); . u" `7 O0 S4 B* ~- I( y6 B: }4 r
qryItem.setID(myId);
( Y I% W4 Y1 m& Z; s ; z, @' u3 C4 {- a& I7 p& o
// Add the BOM structure.
# x3 b: [! _$ F9 d8 G9 H+ _1 A6 V" Tvar bomItem = this.newItem("Part BOM","get");
$ n9 g1 S. v. U7 E1 UbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
( \0 n7 H# c; P8 i, T8 RqryItem.addRelationship(bomItem); ( }4 G: `! A6 t2 @- F6 H/ E( V B
+ M P- Z+ m% r- V: h5 J// Perform the query. 3 B- i: I. V+ A8 q6 I5 P1 c
var results = qryItem.apply();
, }8 O5 W1 Y; ?
8 N, x% S: H0 z# x( y! N1 |0 Z5 E// Test for an error. : ?( U/ y/ t. P
if (results.isError()) { 7 s5 s; @8 p6 c/ Y
top.aras.AlertError("Item not found: " + results.getErrorDetail()); - b% k: ?& W% _( W+ Q# x6 W
return;
& W: P p' ~1 y}
3 q5 ^5 Q1 O/ v2 S2 f Z
8 {, [2 F( p9 t+ G1 h, [// Get a handle to the BOM Items. - @, x" D% O2 [: F9 U5 K) L
var bomItems = results.getRelationships();
9 a& C/ G" `7 q) W3 b' Lvar count = bomItems.getItemCount(); ' f6 u, M$ g0 J. q+ c0 i c
' J; |, G) Z% ] }& @* D
// Create the results content.
+ L: |0 m; h; k# ^var content = "<table border='1'>" +
, ~" X7 x+ O7 \4 }/ { "<tr>" + & m! O5 {5 A# K0 J, r2 R
"<td>Part Number</td>" +
3 ]8 `3 i* Q' J0 x# A1 \/ p2 U "<td>Description</td>" + * t% J, e3 y4 y- {- r
"<td>Cost</td>" + % l! O6 f; T( m7 X* Z" R
"<td>Quantity</td>" + & g- b( [# m$ S, r
"</tr>";
2 b* D) J& j. I: Y8 ]! l0 i% y+ L 4 I. ^4 u4 B8 C' S# Y( g1 L! C; I7 G
// Iterate over the BOM Items. ) I$ ^2 Y/ s( a" ?
for (var i=0; i<count; ++i)
0 R9 c( x& t* `" d; {{
+ o: q& h! h" N6 `// Get a handle to the relationship Item by index. ( J- Z- r" s5 B J. u6 {1 H
var bom = bomItems.getItemByIndex(i); . P- |) h7 O$ O8 r$ J
// Get a handle to the related Item for this relationship Item. 3 v& p; l8 I/ X2 Q
var bomPart = bom.getRelatedItem();
7 o2 l; x9 H3 L% `) r+ t- Q$ n
) p5 B/ P6 q- A1 L: Z4 D content += "<tr>" + 7 m# `* D' _' v2 [, y- H
"<td>" + bomPart.getProperty("item_number") + "</td>" + 8 l8 K! ` p& r. Q" {3 ]6 T6 m" d
"<td>" + bomPart.getProperty("description") + "</td>" +
8 O- i* n4 @. J: Z' B' } "<td>" + bomPart.getProperty("cost") + "</td>" +
, C/ A6 f9 j1 D0 g "<td>" + bom.getProperty("quantity") + "</td>" +
- |8 ^" z% W) h- q6 f8 v "</tr>";
' R5 x" c) N0 t* [. D2 @& g} / k8 e6 T2 g7 h! T
return content + "</table>";) K( L. L* O* r _# r" b; p
' N, m! c5 m* n \3 L7 e5 I, g' ^( |. y7 n/ G
; v, O5 o8 `5 [: P* [6 d
0 z( w- P7 B/ ?- _; zC# - Q; K) E- A* J, C
Innovator innovator = this.newInnovator(); L( E6 O) z3 X
( A( p$ E- o$ v# @2 e// Set up the query Item. . }) m/ s+ a/ C7 `' b+ T7 F( j/ d
Item qryItem = this.newItem("Part","get"); 0 L: H; W: D( e+ v7 X
qryItem.setAttribute("select","item_number,description,cost"); 3 \" \! u- H9 g c/ n( B
qryItem.setID(myId);
4 X, E; K# }( |) p+ o % m' l6 K: D9 |6 v% M' B4 h
// Add the BOM structure. $ l( T; h3 k5 c6 k: J" X- o
Item bomItem = this.newItem("Part BOM","get"); 4 ^7 z: g& e6 b
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
+ V; |3 a9 z5 Q$ k" f- E- ~2 {: uqryItem.addRelationship(bomItem);
" G+ Y. e* U+ e$ I% ? c3 N
2 j4 Y* | J. I1 |$ p5 P8 a// Perform the query. , Z9 F) K' Q8 e
Item results = qryItem.apply();
2 }! P3 w8 R8 `# q
, O' ~+ o7 g8 G! v' i X// Test for an error. ! Y: F. }- g$ a9 b! K# ~7 I7 `
if (results.isError()) { + J! f* o# @8 [1 e3 s1 k
return innovator.newError("Item not found: " + results.getErrorDetail()); 1 r7 W7 R& o" w/ w+ ^" Z, k- f# O" C
} ( _4 ^) n# |! h2 A+ c$ G2 S3 g
' j0 O) f0 _8 h9 s4 Z- p// Get a handle to the BOM Items. 1 G- {- _+ w2 f! f$ K
Item bomItems = results.getRelationships(); , S% E, z* h# d. z- O* |. b* |
int count = bomItems.getItemCount();
% B: W# q" _& z5 x* Wint i;
5 [. K0 q) ^5 @6 ? : |! |" q! z' ~0 f' c; J! J
// Create the results content. ( H: P S- _9 d; N# H! _
string content = "<table border='1'>" + ) J2 N. f. F: V, p
"<tr>" + 5 S' Z& ?' w' |/ r3 O5 O
"<td>Part Number</td>" + : b+ i* e/ o$ q4 D7 k5 d* ^0 I
"<td>Description</td>" + + ?4 p I2 ]+ e: `: o- B( y
"<td>Cost</td>" + ' O+ S) T$ t" J: z
"<td>Quantity</td>" +
) l" q' }" Q; Z8 B, q "</tr>";
$ j- M% b$ l1 c- h
/ a2 C6 G) k6 W- K% D// Iterate over the BOM Items. # A+ O# j/ {* {4 J; N* K
for (i=0; i<count; ++i) / s+ ^5 t* t3 m% K" z0 e4 Q
{ 6 Q u I @- u$ N
// Get a handle to the relationship Item by index. 8 Q- b* D, k L- A z
Item bom = bomItems.getItemByIndex(i);
9 r7 D: W3 v% f) h. u. B% z// Get a handle to the related Item for this relationship Item.
9 v+ x* E1 R6 P e. ~ Item bomPart = bom.getRelatedItem();
- W! S5 F) ?* ^# d 1 L j2 a- K+ H' k# s* }
content += "" + z/ j( N& D) J' q1 \2 X' D
"<tr>" +
+ E/ ^2 X" }0 Z "<td>" + bomPart.getProperty("item_number") + "</td>" +
! Z3 R* S7 B4 s v$ w2 S" } "<td>" + bomPart.getProperty("description") + "</td>" +
: S( J1 q5 y; h# ]* S "<td>" + bomPart.getProperty("cost") + "</td>" +
$ q8 v6 h! Q! @2 d, q "<td>" + bom.getProperty("quantity") + "</td>" +
0 S2 P3 U* m/ p& \8 u7 r; V "</tr>"; ( x1 [6 J0 Q+ o3 f
} ) ~6 r0 T: ?' w B0 q
content += "</table>";
- }7 S, o! x: ^6 Z# i
, |, G# H8 N- T! Y6 g; Lreturn innovator.newResult(content); ; a1 ?! o. C% w
: M& o' O* r8 e: J
* h( f0 d" g) \& b5 `1 s; ? Y& }' h
+ p% m% F3 b9 S+ y1 {
" ]2 |- W; e1 K& M/ c. X& p
3 F, ` x$ R% l& j0 T. _
3 V" B' n0 t( V( w4 z( p6 l! i 3 C. a9 b7 z( I# L
Page 46 + v' e! c6 l- P0 [/ J
4 D1 Y! C9 i. E2 |. hCopyright 2007 3 k/ D7 t F4 E
Aras Corporation. 7 H. N! D5 J5 m8 ]) `% t3 q. j8 P
All Rights Reserved. ! @9 @' h) ]. Q2 z! p: W
VB.Net
" s3 ~9 G( m& F0 q7 n C& qDim innovator As Innovator = Me.newInnovator() 2 x# F7 i. [8 U% s* C
& |- S- T y/ n% Q( x4 R; ]# i
' Set up the query Item. % k8 x& d# n+ t6 K
Dim qryItem As Item = Me.newItem("Part","get")
; M7 E1 [9 `& s$ u/ Z' vqryItem.setAttribute("select","item_number,description,cost")
! y& u! n, F9 ?8 BqryItem.setID(myId) # H7 |5 x% a3 t! W9 Y, J
% F+ G. ]# H( i* h* R
' Add the BOM structure. ) X. |/ T/ |7 ?7 w: F
Dim bomItem As Item = Me.newItem("Part BOM","get") " c$ D% a/ S3 u
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
6 t" \, J `2 N& ? [! k3 r: OqryItem.addRelationship(bomItem) . V& V/ e1 }7 r) N! [, X
/ k( e& s5 A, _% \
' Perform the query. : o3 M' o* i* i
Dim results As Item = qryItem.apply()
' K% Z+ X+ X- \
/ {; d; w+ V. Z! r' C# Y' Test for an error. ( d8 Q; U% T' A! u5 T& n0 U
If results.isError() Then
+ D8 {5 `+ l3 N. M1 {8 q" u- }, X! z Return innovator.newError(results.getErrorDetail())
& s) |, d; _" B4 q, v( X- L( m& pEnd If ( Q* W9 o0 U* z7 S
' b1 v% I" L" y- s+ @4 U0 N7 ?5 q" N' Get a handle to the BOM Items.
/ L! ]+ e4 X3 j% Z% u8 rDim bomItems As Item = results.getRelationships() 9 `5 m7 c6 S& f. H. p
Dim count As Integer = bomItems.getItemCount()
8 @0 r. z3 g' Y( U! N% g3 CDim i As Integer & q+ j% f2 q P$ J/ M
+ r. h `/ I4 d9 P: Z: K; R' Create the results content.
# P5 i, N7 q0 P3 h T% F' DDim content As String = "<table border='1'>" + _ : C9 Q1 H" o& f9 T, N: ^
"<tr>" + _ - K+ `) I! q e+ Q8 T
"<td>Part Number</td>" + _ Z& K$ m$ t( |1 x
"<td>Description</td>" + _
( @, R. d% Q$ @$ g7 t "<td>Cost</td>" + _
/ v4 S9 A: h7 l t "<td>Quantity</td>" + _ & P% {2 R) {! b, p |1 }8 P
"</tr>" / D2 B4 S5 l$ L" J
5 z% R! U) s, y! p& P% `# \' Iterate over the BOM Items
2 y7 Z1 u: P, ~) j9 i3 e* h5 YFor i = 0 To count - 1
- X6 K- ?4 F. `" {; c, ^' Get a handle to the relationship Item by index.
9 h1 S9 t" o$ o Dim bom As Item = bomItems.getItemByIndex(i) 6 c! f! U, X/ x+ F
7 ]/ V, c a1 B5 \; U9 e
' Get a handle to the related Item for this relationship Item. 6 \$ w+ |' p; g. ~: _: {5 s. M
Dim bomPart As Item = bom.getRelatedItem() + X/ b- t$ \- C
5 \ \8 t [" b0 K8 e
content += _ 5 }% |% h6 n* u% ?
"<tr>" + _ * K2 H+ m( X) F4 ?
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
0 M5 C* x9 ~0 o "<td>" + bomPart.getProperty("description") + "</td>" + _ 2 w( m' V. Q9 b( ^* Z. x7 A& D7 g' h4 o
"<td>" + bomPart.getProperty("cost") + "</td>" + _ * G, p1 i; L# `: d. h* F. M, @
"<td>" + bom.getProperty("quantity") + "</td>" + _ + C. `0 c6 J- e H/ u, S% x% f: Z
"</tr>" 1 x( ]0 O; G3 Q/ q0 `
Next
( e* c7 E! L# `content += "</table>" 5 `$ Z# Z- @$ S- M+ \
: m) Y! w, `- k6 Y: k- ]Return innovator.newResult(content)
, U% H. b2 D9 v4 I0 I* t" [' H6 J
|
|