|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
, @, N) {1 u& kTo query for an Item and retrieve its structure you build the query as the structure 4 t! E' x% X. w* T( r- }. T
you want returned. Use the IOM methods to add the relationships you want and
7 @2 H1 q1 }$ H( r* F! m" e) ], Ubuild the structure in the Item. The server will return the structure that follows the
' y: @2 j7 V# X' T. q* |- o. brequest structure.
' X8 j% D9 b! H- L/ l+ q" ?This recipe illustrates several related concepts together, which are how to get a set 7 q/ t. k2 A z3 c
of Items from an Item and how to iterate over the set, plus how to get the related
! z: G# N. \5 W3 sItem from the relationship Item. 2 c7 t9 a1 g% n5 |7 Q
JavaScript 2 W2 o) g+ B9 `& C e6 s0 S
var innovator = this.newInnovator();
( x( t) |# A% D9 L8 P
, s, f4 k# U: R// Set up the query Item.
! ~" d! f' a2 n, r' bvar qryItem = this.newItem("Part","get"); : C* J6 Y6 ^& G* I9 `
qryItem.setAttribute("select","item_number,description,cost"); : C) p5 l1 ~! e& v. L- E
qryItem.setID(myId); 6 t; d$ l- _1 x d; q0 }; i* N- k
& l' q+ {7 [, b" H) r
// Add the BOM structure.
; V# c0 m) @% B8 pvar bomItem = this.newItem("Part BOM","get");
% H& L0 D+ ]2 _5 d: KbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
6 h2 L0 |2 R7 w; JqryItem.addRelationship(bomItem); 7 y: ]; }1 e( V) |9 L4 Q
; i' \0 E! K% A* c// Perform the query. & l; Q% W* E2 b8 H- q
var results = qryItem.apply(); + l$ l: D+ W) I1 F* g
$ k* K% l) m6 n* e1 [5 \
// Test for an error. ' c0 P t8 N$ r, @8 v" X0 ?
if (results.isError()) {
. O$ X3 ]5 T0 w& U0 s& ?8 B' w( X% K top.aras.AlertError("Item not found: " + results.getErrorDetail());
5 f/ z9 V$ F3 B( e6 {: t. [ return;
' J* V+ [/ m3 ~4 Y! a& P$ }}
8 G0 ?) e9 z. Y0 w" h
* K" }2 R- n( Y1 H* L// Get a handle to the BOM Items. 2 a) B' ]) ~ V1 d$ W1 }- g" X; u
var bomItems = results.getRelationships();
, p0 d, B) j0 c- z, {! _var count = bomItems.getItemCount();
( Z3 i M! c& O6 @9 U6 T" `. [9 K
& {' e- ?- P: z// Create the results content.
, R9 P; K/ k9 jvar content = "<table border='1'>" +
" a i) L8 w5 m, S "<tr>" + % B! e6 e7 T, e, i
"<td>Part Number</td>" +
: c- Z* [- [3 h+ Y& A* A( ? "<td>Description</td>" + 8 B& g( s$ l$ k2 l
"<td>Cost</td>" + + A/ Z0 t4 e; F" [, T
"<td>Quantity</td>" + 6 z5 {/ h! [3 o2 Y7 X
"</tr>";
" R' ]3 [& t2 H4 K4 W % `& N7 |+ J! _5 R8 V# D2 \
// Iterate over the BOM Items.
" D9 D$ S. I) ?# T6 efor (var i=0; i<count; ++i) 0 K: d- A7 e( a; P0 g. k* d- S
{ ' {: q6 K5 z, j6 Q0 o; e
// Get a handle to the relationship Item by index.
) f% ~; W" B! s0 g1 X# B4 [+ ~! I var bom = bomItems.getItemByIndex(i);
1 @, n, ]7 d5 Q! v3 Q7 b// Get a handle to the related Item for this relationship Item.
5 ^, p) B" R/ R! x- @ var bomPart = bom.getRelatedItem();
+ o1 t* k( l7 J; A, G4 F
7 t! h) z: y# j content += "<tr>" +
# v% F1 n0 o8 N "<td>" + bomPart.getProperty("item_number") + "</td>" +
3 G8 _: G* ~% h- I "<td>" + bomPart.getProperty("description") + "</td>" + ' n. l" a: c) U
"<td>" + bomPart.getProperty("cost") + "</td>" + 3 q2 W+ Q- X1 X2 {+ M
"<td>" + bom.getProperty("quantity") + "</td>" +
: A/ r; f. J6 r$ {& L "</tr>"; . a% a7 N% d6 B8 h& L: E
}
+ _) |* l0 g+ w) v3 Freturn content + "</table>";
* }, V: O7 }5 D! [3 p; v
4 h6 \& I3 m$ X i# b! ~, O) s- z
# `+ }8 x1 i3 u
+ j; }/ S4 D# X/ W# |9 u7 ~# b7 Y1 aC# # e9 s1 ^2 l% A7 K! `% V( K, D* J
Innovator innovator = this.newInnovator(); ) d: F: G& X/ K' H; ~6 P
/ l# }% ]0 Q: p
// Set up the query Item.
4 y7 K( y7 M+ c$ A4 V8 k8 jItem qryItem = this.newItem("Part","get"); + c6 t3 t# J* G {/ |
qryItem.setAttribute("select","item_number,description,cost"); 2 r- G5 W. |" T0 }! f& `
qryItem.setID(myId); " {. |+ @9 Y# E1 d2 B A! m
9 j8 l1 H% K: y- ~
// Add the BOM structure.
* g1 k, q: u* S- m8 gItem bomItem = this.newItem("Part BOM","get"); , a4 g2 }2 P# c. V: P& Y* {
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); : R. E' s4 ^, r) G: L/ w a
qryItem.addRelationship(bomItem);
5 ~# c5 _* F E7 A
. u. K2 t! o! Z' M. ~4 s% F# h// Perform the query.
" O% y$ N3 p: z o% n4 PItem results = qryItem.apply();
! Z0 M6 S, v$ T 6 \' v+ U# B% ]! H, |
// Test for an error.
) h0 V1 K+ ^9 |$ U: |if (results.isError()) {
" E8 Q* ^1 ?8 J* }. u return innovator.newError("Item not found: " + results.getErrorDetail()); 4 D" F% {1 B( s0 J2 |: G5 |; L
} 1 G. i0 _7 e# u6 v0 N0 ~+ P: O
- ]) A- ^5 ]1 N* L3 c
// Get a handle to the BOM Items.
( L: P2 y7 P/ f1 C- L/ D) t. D$ ~Item bomItems = results.getRelationships();
8 f# F0 `$ x8 I; @int count = bomItems.getItemCount();
: n$ h \6 @1 V- Uint i; ( E, @/ \" X, u$ F
) @, ?- X4 ?7 S% Y9 d+ V& r3 M* v// Create the results content.
" H; d; N8 Q5 e8 Q" f3 Y0 qstring content = "<table border='1'>" +
/ I$ m. W& g% w/ X$ G "<tr>" + 7 X R9 |/ b4 Y4 j! \$ M
"<td>Part Number</td>" + 1 I5 { f- C( F5 W1 z- p
"<td>Description</td>" + ' g. K9 z5 }$ O4 Z" A: F
"<td>Cost</td>" +
! w9 K! D! e C4 g8 \ "<td>Quantity</td>" + : W/ P7 [- h3 [! j! M
"</tr>";
2 N4 E8 q& w# Q8 Q3 S1 t
3 N7 U( M4 l& ~( {9 ~, R" ~9 V// Iterate over the BOM Items. . ]& h' v) [4 k' \: {* }
for (i=0; i<count; ++i)
9 h+ [5 o1 ]- h$ m4 d- J{ . J- Z2 Y) `. B2 P; |/ s# A
// Get a handle to the relationship Item by index. $ }' q; z: `4 I. `2 k
Item bom = bomItems.getItemByIndex(i);
2 x3 x% c/ M; M; Z5 P/ L6 H1 [// Get a handle to the related Item for this relationship Item.
) ` @. ~: z* s% E/ g Item bomPart = bom.getRelatedItem();
+ F5 L, ^* `$ D& R r % H0 t. \+ P/ }! h
content += "" + 9 p3 q0 |* N' t! o
"<tr>" +
8 M! z' G% p& R1 e" D o/ l "<td>" + bomPart.getProperty("item_number") + "</td>" + ! o7 l% n$ _, o& b' d
"<td>" + bomPart.getProperty("description") + "</td>" +
# r3 V% W3 s3 Y5 O, S1 ?. D0 M8 g "<td>" + bomPart.getProperty("cost") + "</td>" +
. h2 S( M% x; }+ S' Y# Y "<td>" + bom.getProperty("quantity") + "</td>" + & f- k$ B6 @1 h. R! X6 |, ^
"</tr>"; ; K# m$ z% h/ b, Q
} " v/ U, U5 A9 ]- S
content += "</table>"; ' H3 {3 z a i
% i9 W* D$ N/ E# R T7 z) x& yreturn innovator.newResult(content); 7 G/ Y1 \ h8 s5 R% k0 M
) m' a; y3 H) E6 X, Z" [
; y: c- |! u& `. c, g; x' [7 C) L, d# C. B8 O: T
$ W0 u$ n" J3 S3 g, K
3 t) m* s0 B+ R3 a `* [: n5 T& h: E9 A7 q b( }
0 R3 a! f* u& e
Page 46
' A* N* {: r0 A
7 P0 T5 p: e8 r4 ?9 D, |, lCopyright 2007 " E- \* ]5 j% f1 `& W& T- N
Aras Corporation.
! c& p x& P" K: [! G1 JAll Rights Reserved. $ g$ O0 r/ o0 v* g! t" ]/ p4 F# q
VB.Net 3 M5 H( w+ h9 M8 i: |0 D2 P
Dim innovator As Innovator = Me.newInnovator() ) ^3 T# \% S+ [
5 N; u: E6 W. S9 X& K
' Set up the query Item. 6 N' v' X- T: G
Dim qryItem As Item = Me.newItem("Part","get")
8 h* h' m* S. a* xqryItem.setAttribute("select","item_number,description,cost")
; E) l6 e( W: M8 j5 W( A5 @qryItem.setID(myId)
) T7 ` c) i0 |3 m: k* s
% p- F5 I$ b. _4 N& b* P' Add the BOM structure.
) W/ F* ] D; l3 LDim bomItem As Item = Me.newItem("Part BOM","get") " }3 s/ @, X7 n* v. K( ^& L
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
: T3 R t4 R. K7 }. ?qryItem.addRelationship(bomItem) ( x% ?: s; D0 t9 ~7 E0 D8 R
6 m7 H$ y4 d: q, Y% t1 Y4 n
' Perform the query.
( } E5 y [6 m, F8 X% l aDim results As Item = qryItem.apply()
2 T* s( Z6 x5 e+ T7 S n
0 A, o0 R' \0 j. |8 Q8 J; ]' Test for an error.
7 ?/ m o( U' oIf results.isError() Then
% N4 ], |, s5 R6 H8 y* Q/ q Return innovator.newError(results.getErrorDetail()) 6 {1 }8 e/ ~# [
End If + w2 g' }2 z( `% z1 {6 O5 C
/ Z2 Y7 q* E5 {8 t4 }1 G
' Get a handle to the BOM Items.
9 J! U3 L g% a' @0 xDim bomItems As Item = results.getRelationships()
0 K0 U1 y$ Q3 M+ n: P' LDim count As Integer = bomItems.getItemCount()
+ x& d1 t- D& l; J% iDim i As Integer
- }4 t0 w2 n2 m; E$ o! H " S: i5 d. t% X. K
' Create the results content. # G# f9 d+ Z7 g! A* d' b, v! m
Dim content As String = "<table border='1'>" + _
0 e) b: q/ I; ^, \ f V "<tr>" + _ 8 B$ K, e. m" W6 r+ Q0 x* |; m
"<td>Part Number</td>" + _ 6 r [# q, Q! d: P1 T& e6 G
"<td>Description</td>" + _
( l% R! k! L& g4 F0 `: a e "<td>Cost</td>" + _
4 z U. m+ S: `9 z' m L6 G3 s "<td>Quantity</td>" + _ e% I: r, F- V3 K9 v& J+ L# E
"</tr>"
# C; z, U+ M& n- p, o0 \3 z2 @. w% v 6 C1 X0 @) k" g* A# D9 c2 h
' Iterate over the BOM Items 9 a0 B! K \9 O$ ~; J: a) I+ z" K2 c
For i = 0 To count - 1 2 h9 U! q1 r$ s) b
' Get a handle to the relationship Item by index.
7 a }) g! X* v Dim bom As Item = bomItems.getItemByIndex(i) 1 ~, L' ?# `5 q
0 \. v# H6 M' ]+ T" r
' Get a handle to the related Item for this relationship Item.
' M T* H' [- a' p! _ N7 r Dim bomPart As Item = bom.getRelatedItem()
$ r" W& Y, a( K/ K' ?0 a' h $ E$ P( f: l, V: I, u% D9 K
content += _
7 D& h" d2 e$ j: t: R- I/ o "<tr>" + _
3 w$ E F/ e) I, b "<td>" + bomPart.getProperty("item_number") + "</td>" + _
# v4 K' x) m% m; J "<td>" + bomPart.getProperty("description") + "</td>" + _
( H* |; l) B# ]* p "<td>" + bomPart.getProperty("cost") + "</td>" + _
/ e- s9 m7 q# j% I "<td>" + bom.getProperty("quantity") + "</td>" + _ $ J" w/ w: u# z- A7 u
"</tr>"
! v- w6 `* g% F' XNext 4 l& j% W5 i! i* z: V
content += "</table>"
) Q ~6 s1 @* v
2 R$ R) z& }8 O, {; o( a1 zReturn innovator.newResult(content)
" ` C( w6 C% {) L! j
' g7 w' r3 F0 h5 M" F |
|