|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 1 P, v9 e/ F0 d
To query for an Item and retrieve its structure you build the query as the structure [6 K9 W$ J$ d5 Z( \, a- V3 F! l
you want returned. Use the IOM methods to add the relationships you want and 8 {& H' L- D" Z, ~5 G- ]
build the structure in the Item. The server will return the structure that follows the
f0 p( Q2 y7 N5 Grequest structure. / q' q; i5 R, `: C5 f% y' ]. u
This recipe illustrates several related concepts together, which are how to get a set
; m! G! k' ^5 U( m. ~1 c( Dof Items from an Item and how to iterate over the set, plus how to get the related ( f' a% E4 T6 v' u& O2 w. W
Item from the relationship Item.
8 K( g" l9 l6 o1 J2 ^* ?; VJavaScript
2 Q; t3 V: |/ t+ Z1 n( p5 l& Dvar innovator = this.newInnovator();
# }" s( L7 h5 ~* W: f) \+ q$ r
2 N& Y. w. q0 i; X _// Set up the query Item. & r: f Q, H/ x- T; T4 r
var qryItem = this.newItem("Part","get");
4 H& k. I, E! i( E. v" {qryItem.setAttribute("select","item_number,description,cost");
* q+ x3 c+ o% t! e- k6 Z/ G& aqryItem.setID(myId); ; \% Y+ R% \! \- _4 H
8 o/ J; q( Z- J" J// Add the BOM structure. - y; h6 D8 s6 G j5 a
var bomItem = this.newItem("Part BOM","get");
* L0 o0 A* D. RbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
( f6 u' R; w3 _" S9 A- N. MqryItem.addRelationship(bomItem); 2 H, {4 O6 z! A6 B* u. E9 _. o0 w6 b
( E' M) }* \. A4 U2 D! ?7 A
// Perform the query. : G6 D& Q% u4 r; s
var results = qryItem.apply();
% g3 b) J# b! s: s2 H & z( i) @/ I \, h! W! z% T- P2 C1 w9 p
// Test for an error.
O' v a6 v- _# \9 O% Zif (results.isError()) {
2 P' v1 ]( M3 J% b, J top.aras.AlertError("Item not found: " + results.getErrorDetail()); ! E: E% a0 ]( Q; Z( ]+ [8 m# B& _
return;
( F% R5 S0 V0 ?+ ^} . A" L% A7 }/ j# L& Q/ \
1 {- m/ I5 W) C% u% E// Get a handle to the BOM Items.
! H9 }5 S- V( ]9 i3 T0 Ivar bomItems = results.getRelationships();
# [7 q; T" x$ Y. [' ~var count = bomItems.getItemCount(); % y6 }2 e- s. } q
* G6 }/ y, b* p: Z9 ~* p. O6 `// Create the results content. ) {+ F- Y) g m5 U$ Z; y9 ]
var content = "<table border='1'>" + ; Y4 ?' y; b+ Z$ F
"<tr>" +
8 E0 _: G, {3 d8 u1 g "<td>Part Number</td>" + ; q% s- F1 M, [
"<td>Description</td>" + . I8 b6 `) c7 Z: Z: Q% X6 n" U
"<td>Cost</td>" + 1 M- V1 T- p5 @% O9 y
"<td>Quantity</td>" + * I- F) t6 z/ O& s. [8 K! f" w7 p0 C
"</tr>"; 4 H1 q5 _) p% b0 O% E
2 _7 ?4 Y5 _$ b
// Iterate over the BOM Items. 6 U) [; L7 d' j: R/ {& t
for (var i=0; i<count; ++i)
) d# N M* C; p" _: ]- D# f. u8 G{
~8 I- R' S- q1 F/ j// Get a handle to the relationship Item by index. # h' A9 _" ?" b: Q" J
var bom = bomItems.getItemByIndex(i);
" Y2 W7 f; g) L// Get a handle to the related Item for this relationship Item.
- ]" V# A ]5 Q# z var bomPart = bom.getRelatedItem();
. u; `( x! h# K4 Y6 M
% W- L# ^4 h4 Q7 b V content += "<tr>" +
7 Q2 X7 D/ \ q* w% @0 m "<td>" + bomPart.getProperty("item_number") + "</td>" + . j4 I+ d" _3 R9 M) [- U
"<td>" + bomPart.getProperty("description") + "</td>" + 9 {+ e7 ?: o! R p& B
"<td>" + bomPart.getProperty("cost") + "</td>" +
) q; }0 k; D+ @: w# E "<td>" + bom.getProperty("quantity") + "</td>" + 8 [7 R+ Y3 j8 T
"</tr>";
$ A% q1 C$ R7 V$ |} . a- l: `* h( o. X% Y4 M
return content + "</table>";
4 q9 t, O: G5 V0 `5 S/ C
# {; i! C- z, I0 }. t) p
* d& Z* U9 k; y+ b2 u8 I9 B# _
( [. O/ T7 H* H0 B6 j4 I
0 S3 A- u7 \6 qC# & J" c: A- a5 o" x
Innovator innovator = this.newInnovator();
& w. R0 d* r+ F% e1 z
. J2 U& o" X2 r: S' }. l- \& V// Set up the query Item. 9 P! ^/ j. p- a0 q9 Y' U
Item qryItem = this.newItem("Part","get");
3 K5 x# M p; ?' p7 S9 OqryItem.setAttribute("select","item_number,description,cost");
7 V. u9 A0 N& R0 c# P- N9 J" t1 \& qqryItem.setID(myId);
" J! n' }% h; G
# W7 H2 t/ M) _0 P+ R, s9 J7 m// Add the BOM structure. " I4 d, K; q, ?( ]) A4 G
Item bomItem = this.newItem("Part BOM","get");
; Q$ K) A' F+ W! o* abomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ' B& t; V, O5 x4 N
qryItem.addRelationship(bomItem);
, B2 m9 e4 D1 `6 x $ Y5 p1 B. i) [, M3 z' u/ S5 F) M
// Perform the query. 2 {: J. B& H/ Q) o4 X
Item results = qryItem.apply();
% Z4 P% }. W0 T# K& e
; _ w5 j6 n+ j9 P// Test for an error.
3 c) S. i1 u5 L$ t2 w, ^if (results.isError()) {
; U( S& b/ [! S) Y/ _/ W return innovator.newError("Item not found: " + results.getErrorDetail()); , ]$ g3 s h4 W! r
} / F* c' j5 c) A$ |, q
- c& z$ o3 t+ A4 c
// Get a handle to the BOM Items.
7 k! l. k; E: ]; z' z1 X7 wItem bomItems = results.getRelationships();
/ y2 _* V3 t3 @5 q7 X! pint count = bomItems.getItemCount();
4 l4 q) x, I; @7 T8 Dint i;
6 O5 z+ ^, G* |5 z& P6 o / k+ z: d7 l( A& T% M/ ]9 [
// Create the results content.
# y: S7 N, N; m/ m( B9 H% R7 ostring content = "<table border='1'>" +
- t+ q. x$ a2 p$ T6 v8 m# k "<tr>" +
) ?5 m" U7 \/ p- ~0 r/ i; K N$ x "<td>Part Number</td>" +
; P4 ^! s: j$ |4 a6 d5 P "<td>Description</td>" + * T5 l+ Z6 x; S4 C. ^2 E
"<td>Cost</td>" + 4 Q! D* ^1 x2 ?8 o8 F7 ?( z- h9 R
"<td>Quantity</td>" +
7 \: c- ^" V5 v7 K6 d% u: \ "</tr>"; ; ~& P& Z$ j2 P4 k
3 L8 e4 D; P; y/ s2 Q
// Iterate over the BOM Items.
3 p) F7 [* l) A! T5 [for (i=0; i<count; ++i) , H, R' K5 z9 Q5 |
{ & u$ D6 `/ f, ?( }' v: H+ H
// Get a handle to the relationship Item by index. ; C; ^# k; [4 h
Item bom = bomItems.getItemByIndex(i); / X- e' J/ ` [) q
// Get a handle to the related Item for this relationship Item. ' \# H& A) ~# x' U
Item bomPart = bom.getRelatedItem(); 6 x E+ |9 L) r* ^$ k9 `
' X5 s: B9 M, m( M5 ^
content += "" + ( U0 |! M, D# }" B& T8 k
"<tr>" +
2 K( _) g* u. S8 k* { "<td>" + bomPart.getProperty("item_number") + "</td>" +
( Y# R8 j/ `' E# f* N0 @7 Z) I M "<td>" + bomPart.getProperty("description") + "</td>" + 4 m! e5 c& l2 V
"<td>" + bomPart.getProperty("cost") + "</td>" +
' m# ?+ |3 N5 L O0 I; t6 Y1 b "<td>" + bom.getProperty("quantity") + "</td>" +
% Z4 J. m8 I" n "</tr>"; 4 Q+ f5 t0 N& G- R9 h$ h& x
}
; L f A) h* i3 m! X0 ]! U0 Ycontent += "</table>";
1 d! Y% ` p/ C8 F & k* C: }+ Z! U n
return innovator.newResult(content);
7 R' v* i# L6 r5 v- Z
1 K7 j8 d* y- x3 z4 M$ w4 m
7 h( ^, x% o4 B( j1 \0 E9 u; N. q1 q v& Z3 ~
! D' h" F8 ~- U: V3 _
/ J y! O% Q& G3 g2 Y4 W( a! h
% p" I# N1 A& L8 l1 @: `
Page 46 7 H/ [ X) M) ]- ~
3 w/ K! \+ C" V" h2 D) F4 vCopyright 2007
. [9 l9 ~# q2 h& fAras Corporation.
& j; X. S' x- I b. p5 [All Rights Reserved.
0 E( g( D4 f- Y' A: SVB.Net 6 h2 m: k1 ^: H% F3 R4 v
Dim innovator As Innovator = Me.newInnovator() * W# N+ z6 g3 @! R. o% z+ B
' T" L# V: r$ R2 l, y; y' Set up the query Item.
& p2 U3 P* ?4 C1 r' P" cDim qryItem As Item = Me.newItem("Part","get") . `7 j0 A- X$ G/ a; y O
qryItem.setAttribute("select","item_number,description,cost") # `5 u- i$ g- d: W! d
qryItem.setID(myId)
5 j9 a1 n' Q+ f8 U6 b8 u% X / l& @7 R. K# a7 t" i: r
' Add the BOM structure. 1 c! F) p/ o. p m. C3 q: r/ \' T% R
Dim bomItem As Item = Me.newItem("Part BOM","get") 9 p. N8 A/ m8 W, s' A& {" R0 \$ ?
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") , N* ~* d G$ A P; ~; ~$ p8 E
qryItem.addRelationship(bomItem) . c" i" e0 w# O' Z
6 f! l d; k, M! n |' E
' Perform the query.
* z; a8 Z+ o# K- | y9 j jDim results As Item = qryItem.apply() $ C& e3 y+ A' @0 ?
9 V9 w Z, o6 o" T; C" v6 X' Test for an error.
( A, l, O, r6 T# y1 pIf results.isError() Then $ A! g! F; Q2 K8 d+ t* M
Return innovator.newError(results.getErrorDetail()) 1 {3 f2 C- i0 c4 I
End If 0 D" c& M5 c! L. x/ l
" U5 M& T/ y! z% S" O, n0 }' Get a handle to the BOM Items. + C0 t; j# O5 S% y
Dim bomItems As Item = results.getRelationships() 0 d1 H/ |. B8 x* P! V
Dim count As Integer = bomItems.getItemCount()
2 ]! g* d- f( |# B; l% e( cDim i As Integer / P( R$ a5 b6 h& e( D" E5 } d
: k! W. l' p- F* D3 i. s' Create the results content.
5 v9 r8 [2 E' VDim content As String = "<table border='1'>" + _ 6 x( i8 M5 |7 ?/ ]/ H. z
"<tr>" + _ 0 T* @; f1 k1 p+ \0 z
"<td>Part Number</td>" + _
# i5 S; h& m( j x: j; k) }& I "<td>Description</td>" + _ : S6 w V( o0 e e3 v# v
"<td>Cost</td>" + _ " p7 J. A; b0 \5 ]
"<td>Quantity</td>" + _ 4 ~4 p/ ?, o3 [% j: B: L# ~
"</tr>"
+ d% Z J; O& C5 R( ]: [2 A & @( R, {, m: J
' Iterate over the BOM Items 9 p0 B& x# z! P9 s0 ?1 X" _
For i = 0 To count - 1
; J) K$ w6 p' L% c) v6 e- W' Get a handle to the relationship Item by index. 7 {. }6 X# L N3 e
Dim bom As Item = bomItems.getItemByIndex(i)
8 l2 [) J" Y7 n6 |3 ]
0 j- u7 ?( h; w2 S' Get a handle to the related Item for this relationship Item.
, v& [+ Z: P; J' `6 A Dim bomPart As Item = bom.getRelatedItem() & T2 M6 U) V$ s/ ~
0 J5 }- V$ x: n. n& ? n* h content += _ ; y( \4 q% Z$ B% ^
"<tr>" + _
, V* `4 Q7 i7 p" ~* @" v "<td>" + bomPart.getProperty("item_number") + "</td>" + _
; @% S5 D* c- ^- X' H5 q- ^! ~# H$ h! P "<td>" + bomPart.getProperty("description") + "</td>" + _ + W+ E- D& r) }$ t3 g8 a' [7 Q
"<td>" + bomPart.getProperty("cost") + "</td>" + _
8 @+ b- @$ q# q3 [5 i2 q "<td>" + bom.getProperty("quantity") + "</td>" + _
1 X6 Q' C2 @* A' j2 x F" ^ "</tr>"
2 F& ?$ H! x7 i% l/ L0 `5 VNext
" _% M( I0 H0 j S% |7 O2 c. d# X$ zcontent += "</table>" 2 o9 w$ P" |& d
* v( _% W" ^; F/ C" v+ q; j/ w5 {$ H. SReturn innovator.newResult(content) 7 J% @# n0 u7 r% o5 {# q
1 i5 Z0 x% @. y/ m4 e& F( x
|
|