|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
( m# \) x1 t' f4 |To query for an Item and retrieve its structure you build the query as the structure ( O* f% u4 ]3 I2 u! y" U
you want returned. Use the IOM methods to add the relationships you want and
3 q6 l( h/ l* _) ` N' sbuild the structure in the Item. The server will return the structure that follows the . g6 c T6 v, s5 H
request structure. & {3 |) p6 b6 r; B/ g. v, q
This recipe illustrates several related concepts together, which are how to get a set % p0 F1 X2 z, w8 Q( d
of Items from an Item and how to iterate over the set, plus how to get the related
. i* I. L6 P2 q, `/ xItem from the relationship Item. 6 A7 \" Z" x0 O/ y6 s1 W( y+ r! s
JavaScript 9 s' d# Q; S: o2 m5 [6 a; A
var innovator = this.newInnovator(); ) _- Z. Y! \& e) O q {0 Q( U
6 Y2 G# M, C6 i// Set up the query Item. 5 j9 u" y9 I' F+ s
var qryItem = this.newItem("Part","get"); R- Y. r3 `3 I( ~4 g& F/ F4 O7 _
qryItem.setAttribute("select","item_number,description,cost");
: M0 r3 E6 U3 P z HqryItem.setID(myId);
5 F( K: ?, c( J5 ~/ L3 M4 R6 k , K4 l8 H+ y) t3 E9 B ?/ }# w. T- r
// Add the BOM structure. 3 w4 p) B6 H* Z8 S0 I' f
var bomItem = this.newItem("Part BOM","get"); & f C! Q4 i& n% h8 s3 ]
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 5 A7 X7 @& R+ q8 P6 C# \
qryItem.addRelationship(bomItem);
# J. q! u: Y' s5 y8 A6 G. O% d- m
" B' L$ M# R% f// Perform the query. / D1 E1 q. `) N* c' w
var results = qryItem.apply(); * ?0 l. B c* J5 o% `1 y) B
' L6 _% ]/ l: [// Test for an error.
+ w7 p) B% t9 ?9 pif (results.isError()) {
* i6 ]6 {# a, x' S. G1 m- Y( M top.aras.AlertError("Item not found: " + results.getErrorDetail());
1 ], _: }* ]. `2 t& U0 m7 @ return; 5 e! Q' P' p8 L: j
} 7 ]5 l8 Y+ |6 `3 x: S
/ d) o) y! x% T1 Y: {
// Get a handle to the BOM Items. : e% q6 W$ T& l' a
var bomItems = results.getRelationships();
7 n. }$ o7 a0 U9 s& V1 rvar count = bomItems.getItemCount();
2 x- y9 `# ?) a I' w6 J
* R4 [. U& s5 E3 g- M/ I// Create the results content.
: H _1 D6 v) J: gvar content = "<table border='1'>" +
4 l8 R9 w% Q h9 O+ P "<tr>" + : f& n3 Z2 V) ^6 O9 S7 s9 ~6 q
"<td>Part Number</td>" +
3 @; H( U5 {% K4 c l+ _ a "<td>Description</td>" + 6 I, M2 f& A0 {0 \: A+ y! D3 _3 o: C
"<td>Cost</td>" +
, ^( g7 W5 S; R! B; u "<td>Quantity</td>" +
' b; I6 @1 @ ?5 Z/ |( I$ f "</tr>";
3 N+ F2 `$ L. \, e' E# r' K ) F& v Z1 D4 p" G1 e$ B
// Iterate over the BOM Items. + l+ Y- }1 j4 R6 a
for (var i=0; i<count; ++i) 7 ~5 a$ W1 ` \- j
{ 2 [' l5 ?0 e& F& k1 D8 G
// Get a handle to the relationship Item by index.
4 [. H2 h) [3 }2 F* q var bom = bomItems.getItemByIndex(i);
: o- V! r" c; T D// Get a handle to the related Item for this relationship Item.
3 O7 G* K6 t& J9 v$ m" J var bomPart = bom.getRelatedItem(); 4 H m) K! b1 R" P' O f
, l8 o' M. r# p# D( c( H3 [ content += "<tr>" + / W. w# R E; z7 j2 _0 C
"<td>" + bomPart.getProperty("item_number") + "</td>" + 5 u3 ?+ T8 r# A: `
"<td>" + bomPart.getProperty("description") + "</td>" +
" G* T, A. D, A* a "<td>" + bomPart.getProperty("cost") + "</td>" +
+ j" F# T1 r m, C: ?8 O* x. _ "<td>" + bom.getProperty("quantity") + "</td>" + * s# e- {$ i% x) c4 p' a
"</tr>"; / i6 _/ l6 ?8 l6 n% ^ I
}
" s q8 X% x7 }; S% z& Kreturn content + "</table>";( h% t- D& A Q1 I
" A0 [+ [% |7 J, ^/ J6 g8 A7 a( K+ L" {9 s# p* `
; q5 H6 V3 Z5 y7 I7 s8 h
4 h/ ]3 u Z9 V) ` f% e% O! dC#
; p. u; b& o2 a0 Q0 U2 g: G hInnovator innovator = this.newInnovator(); + }( d0 ?5 Y3 g& u' F* E6 r
, `. S" ?5 r0 a// Set up the query Item. " c" z6 R$ @7 L; u/ N7 f' s
Item qryItem = this.newItem("Part","get");
1 }. F! I! k4 w) a2 Y$ o4 A+ kqryItem.setAttribute("select","item_number,description,cost");
/ ]. m& N) P1 P6 k8 N. R6 mqryItem.setID(myId);
2 O% s! l/ Z5 {+ r! } 3 @+ I' K6 P2 `% O& f* D9 |
// Add the BOM structure.
- t" c* p. K1 fItem bomItem = this.newItem("Part BOM","get"); / p5 m7 Y- H1 [" d5 l2 O
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
. T2 [1 [* }+ a& oqryItem.addRelationship(bomItem);
a& E( Q# U8 ^: f' i
. L! [8 `" a1 E// Perform the query. " J" F8 Q3 F' y0 T
Item results = qryItem.apply();
# }6 r+ {0 _% x) H5 \( r
% D) g8 J2 z4 F$ u// Test for an error.
% O9 W$ ^0 d* p5 n2 r: aif (results.isError()) {
' S8 [+ }6 R( I, Z6 w return innovator.newError("Item not found: " + results.getErrorDetail());
" L8 R7 S; {: P}
& d* O2 Z6 ?0 T+ X4 t7 O: E . P+ f6 Y& g5 x# o/ K( S, \
// Get a handle to the BOM Items. . W$ S( V2 M( z$ I8 [' C- ?
Item bomItems = results.getRelationships(); 4 J! v/ U' |: e& S
int count = bomItems.getItemCount();
+ W D: h/ c- P" Z( v4 iint i;
. g4 t9 K# f1 P 4 k! a/ ` \" C* O, f) W& e7 O
// Create the results content.
+ x! N0 z2 s9 r; wstring content = "<table border='1'>" +
* e3 T5 P; O, H4 z4 L; ?$ A "<tr>" +
# ^5 n0 `" x8 v6 u! o1 ~; ~, |; p: O8 F" P "<td>Part Number</td>" + * r, m- M: U" g9 @
"<td>Description</td>" +
0 r0 u+ ^6 C/ t "<td>Cost</td>" + 1 l0 e+ S% s) K7 ]; _
"<td>Quantity</td>" + ' l. X& t5 ~( C) X, i
"</tr>";
* v S$ t7 Q' ^- ^% d
0 W: J; i+ s. {+ w$ l7 i! W, B/ s// Iterate over the BOM Items. 3 i( Z( S: {) i
for (i=0; i<count; ++i)
& X3 `% d/ e, b: R! p{ . j( f/ X) r9 j! s
// Get a handle to the relationship Item by index.
& s. T" d1 L& b7 C Item bom = bomItems.getItemByIndex(i);
. R0 [( M% p' o3 t2 T" {* w E- y// Get a handle to the related Item for this relationship Item.
5 O$ N- T q2 u& r$ t Item bomPart = bom.getRelatedItem(); 9 \* u- Z( ~! J
4 q- t0 Y- j E6 L* D2 A- q
content += "" +
; L F: V5 u* w3 E "<tr>" +
- R* S' s( ?+ J! ?! a "<td>" + bomPart.getProperty("item_number") + "</td>" +
, Y! D4 n( G$ m5 v5 ~3 t "<td>" + bomPart.getProperty("description") + "</td>" + ' I4 a8 \0 S( N( V3 `+ W
"<td>" + bomPart.getProperty("cost") + "</td>" + + u& e/ V- H7 l+ C$ `; s' i: L1 O
"<td>" + bom.getProperty("quantity") + "</td>" + , N* \5 s9 W3 M7 _) _
"</tr>";
; |: W- C& E& v9 y: N: n/ L! Z# S} + h/ h7 \7 t8 ?& Q+ q+ L
content += "</table>";
8 _; m5 w. ?0 m1 U. S0 ~ ' f2 d: d/ W$ G$ j6 V8 w
return innovator.newResult(content);
) m+ h/ J) o! E6 f1 B/ ^; n# |4 f9 |; U
& a' r, e7 X) F4 m2 N0 w& J9 c
/ n( y; l9 ~4 e( ?' g- W6 _, |3 T
8 ~$ J R ?; n1 N0 P" V9 L, |$ p w2 F. a3 S
! ]' W p8 w. Y: C4 j) r3 k
! J, t; d* V, R9 D( J Page 46 : C6 W+ q$ C& m" @7 W# y6 ~
0 L7 K# N+ J1 d- X! P* a/ sCopyright 2007 ' @, M0 |9 Y! e
Aras Corporation. , g" O. T! X* B3 l% m$ U n$ S
All Rights Reserved.
. F8 d T# S$ o# ZVB.Net
" S) U" k% u$ I PDim innovator As Innovator = Me.newInnovator() $ d* k) P" o; ?: q b# W$ z
7 m H$ [8 @, k8 G. D7 }3 s' Set up the query Item. / i% j5 ^; {6 x3 U4 h3 n2 {
Dim qryItem As Item = Me.newItem("Part","get")
7 t) f, ^& ]: R4 K4 `* zqryItem.setAttribute("select","item_number,description,cost") * p+ q1 }3 X8 l
qryItem.setID(myId)
" c8 z' E/ k8 I6 T* t' U * S6 Y4 y' G8 Q3 K, h
' Add the BOM structure. : [* C9 [ O/ ~& a; V+ u
Dim bomItem As Item = Me.newItem("Part BOM","get")
\) T: I' y5 j3 @8 Q: gbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") W. U& n2 I7 t* Z( @
qryItem.addRelationship(bomItem)
0 t6 V7 ?+ d8 m7 O 1 x5 [6 L* O- b) H! j
' Perform the query.
: l) l1 g' I$ e2 g5 k5 c, iDim results As Item = qryItem.apply() - m+ _3 n( c* h2 y8 s* i4 }$ Y
% ^ }+ C& d" a3 K7 d( q4 E
' Test for an error.
2 g p% r$ f ?6 {! Y1 ^7 X; qIf results.isError() Then 4 J6 }7 z, F6 V3 J
Return innovator.newError(results.getErrorDetail())
% T2 r# u- e5 y1 hEnd If / @ A6 ?; W# v
7 r1 K8 h3 `- s3 G) z' R- C( s
' Get a handle to the BOM Items. & N) |+ ~' e6 V+ x' d; z
Dim bomItems As Item = results.getRelationships() # N: P; A( s$ |" G( o: C: X
Dim count As Integer = bomItems.getItemCount()
. d% r7 D% t9 @% O% e( QDim i As Integer
; Z' Q4 b- \+ }4 ]( f1 N4 a* \ ( E8 u( x. i* }/ _: r( S, D
' Create the results content.
s- M6 J/ v) R- }% j3 n+ X2 rDim content As String = "<table border='1'>" + _
9 G6 S" y7 g/ a# h3 z "<tr>" + _
6 }1 b4 X5 t0 m' w! A: m0 l "<td>Part Number</td>" + _ & R8 ~( ?* k& K; [
"<td>Description</td>" + _
, G& C" ^+ T* r- s2 [, P% f; k "<td>Cost</td>" + _
& }# n) j: x) {" A( y: M "<td>Quantity</td>" + _
1 m$ `- f- j( L, S& S7 } "</tr>" ) l. q4 Y, S9 Q: B; W& o
! r) E' K* D' p6 S
' Iterate over the BOM Items
8 F" M2 h1 X) C0 n$ E) W2 UFor i = 0 To count - 1
9 m! B8 }6 Q7 u' Get a handle to the relationship Item by index.
7 {0 c5 g. u9 r9 f8 `0 ~+ a Dim bom As Item = bomItems.getItemByIndex(i)
& w: i \# R, e% {3 W1 e
( C, X* G/ d+ g$ o/ S; ~' Get a handle to the related Item for this relationship Item.
1 f9 ^; e3 O+ t" K% P Dim bomPart As Item = bom.getRelatedItem() ; F. `1 n; L/ g2 ?# t- ~5 w
" O, y& h+ R0 b. i) r! J
content += _
( B0 r$ \% I) W) e+ f2 W* V% R "<tr>" + _
$ V: c4 [: L3 p; V& S( g5 O: ?% m. n "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 V' {! W1 ]; e% q; J
"<td>" + bomPart.getProperty("description") + "</td>" + _
. B y0 v: C$ I- h/ e "<td>" + bomPart.getProperty("cost") + "</td>" + _ 3 V) R5 [# \! `1 J" w0 z
"<td>" + bom.getProperty("quantity") + "</td>" + _ ]6 M+ z" [2 S2 i
"</tr>"
2 c# w/ V6 Q. ?" \4 ]* ]' o5 J4 [- p* aNext
A* i! ~& w0 k' Icontent += "</table>" ; E$ r/ }, S$ L! B) x( S
2 D5 ^" _: Z6 k" l
Return innovator.newResult(content)
" ~: `; Y; l8 R6 N3 a, x$ s; O
6 G# o7 {! n0 i% B. v$ k0 y |
|