|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 5 Z3 c4 C* t% u0 ]/ W- Q2 K
To query for an Item and retrieve its structure you build the query as the structure
5 ]/ J$ j) K6 d* @' t/ Eyou want returned. Use the IOM methods to add the relationships you want and
, Q3 W7 U) E# Y4 o- u Tbuild the structure in the Item. The server will return the structure that follows the
$ r0 A& C/ ], O; I+ s' erequest structure. ( S, N. Z* ?3 {& ^2 P# @2 M
This recipe illustrates several related concepts together, which are how to get a set 0 A5 N1 L3 p- ?3 Y) z. q) ~
of Items from an Item and how to iterate over the set, plus how to get the related
3 k; `3 x8 I+ C1 z6 lItem from the relationship Item.
2 ]6 N c; G& P* u0 b! `JavaScript
9 C9 i( | r# P4 C" }1 I' kvar innovator = this.newInnovator();
. c( r& T* u& D* d- | 2 G6 C6 `) l' K6 r( g0 X1 L; u
// Set up the query Item. 9 U* b+ D0 [! {9 ~: L) ~( q
var qryItem = this.newItem("Part","get");
. J: y, |1 v2 C$ o; w) Q6 JqryItem.setAttribute("select","item_number,description,cost"); & J7 g! N9 @' C1 d6 m$ i3 A
qryItem.setID(myId); : x4 x7 W' f) V7 d4 y5 T
2 Q+ N( q5 Z: g: F4 J0 M// Add the BOM structure. 9 }2 @* O) F2 N: { e
var bomItem = this.newItem("Part BOM","get");
5 \0 l1 |- a) }) X. b: {bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
, M+ {# N- Q0 U6 R5 iqryItem.addRelationship(bomItem); 4 X) x3 H4 u, F2 M! M/ l. ^+ q }
B7 y4 i( ^/ R7 n" q; T- }
// Perform the query. & ]7 p7 I3 K8 D, z( Z) X, y8 c* o
var results = qryItem.apply();
) H1 Y) G+ i8 {1 G
0 T0 b! `7 m" d+ W$ M6 f% [// Test for an error. 6 q; [( A+ H7 X/ h) E: i K
if (results.isError()) {
' ~* O3 E0 ^+ s4 m7 v% k1 G top.aras.AlertError("Item not found: " + results.getErrorDetail()); - m% W2 ?5 Q; ]4 t9 K4 N9 ^2 V. R
return; ; t, b" D" \7 C2 M9 x
} 5 O! C! b% h. r; i! [
% H; m; U) n- ?! V/ ~& n7 z; d1 r// Get a handle to the BOM Items.
& s1 ]# j6 V1 Y( O+ c% ?- Xvar bomItems = results.getRelationships();
5 T9 p& Y! a$ Y/ J8 kvar count = bomItems.getItemCount();
+ L- l8 E0 h% L, U7 r4 U- q
7 Z1 j; z5 r; J' v: K$ E// Create the results content. 4 `3 I2 t8 |) x( T0 x0 Z
var content = "<table border='1'>" + $ g8 B; E$ f/ V+ T: r+ Y
"<tr>" + ' J2 |) P0 s: f2 m- u% B! \
"<td>Part Number</td>" +
# N; a- F0 |/ a. Q# U "<td>Description</td>" +
7 R" @; G7 W3 P% ?, P "<td>Cost</td>" + % |5 W" }. Q+ w
"<td>Quantity</td>" +
4 a, f# K' _7 Q5 h& t "</tr>";
6 a' ~( |9 V( L$ h% P' @1 ~ {+ V( _4 F$ Y9 p0 X2 R- E
// Iterate over the BOM Items. 7 b! A7 R7 n" N2 H7 n( r2 d
for (var i=0; i<count; ++i) ' T0 J& W: \% G% k
{
( @/ r) U; W* V. ]1 o1 \, H// Get a handle to the relationship Item by index.
( C: a3 ?$ C1 ~- H var bom = bomItems.getItemByIndex(i);
8 v) }/ @. q/ @1 ?/ {1 l6 z0 _1 d// Get a handle to the related Item for this relationship Item.
" \& D' v) J5 U3 A* t- b var bomPart = bom.getRelatedItem(); ; ?; H# k: Z7 K
: u3 n: \% ?0 B2 I8 f7 p content += "<tr>" +
C1 ]" ]! T3 s4 U/ h) S "<td>" + bomPart.getProperty("item_number") + "</td>" + + z2 k m* B5 Y3 `/ v/ o' Q
"<td>" + bomPart.getProperty("description") + "</td>" +
- v8 c. c3 k7 k "<td>" + bomPart.getProperty("cost") + "</td>" + 4 R7 F9 m: a7 X1 c5 J9 k4 V' I
"<td>" + bom.getProperty("quantity") + "</td>" +
. l: A& U q- Z, ? "</tr>";
% t# o4 f {& [2 h} 6 t$ X# I+ u3 v3 {
return content + "</table>";8 T; X% I4 u! m) X/ w2 s7 [
8 X9 l* j- p+ l* v5 G3 B1 V
' b. }$ |) f! {# G
# g# ]' N# ]+ N0 ^2 ]+ Y5 P/ u
C# 5 Z* y9 F; X" u$ \, n% k
Innovator innovator = this.newInnovator();
. p1 Q3 u8 c% Z# J
* k6 T9 d- P1 c// Set up the query Item.
3 i! I+ f7 l% x: \Item qryItem = this.newItem("Part","get"); 9 s% _6 `2 ^& P" b
qryItem.setAttribute("select","item_number,description,cost");
# J8 E4 B7 R( ^$ u0 WqryItem.setID(myId); - F0 ]6 x4 R6 k% e/ ?9 f1 e
# A( s9 b- x' V9 n4 S9 n' e
// Add the BOM structure. ! F @3 W; R5 w- H
Item bomItem = this.newItem("Part BOM","get");
0 }5 p$ `7 S! l3 c$ ]9 S: i6 Q! ObomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
1 W% m1 N! N) v, p1 \( hqryItem.addRelationship(bomItem);
' U K& E: e& f2 W5 d, o . @; O6 C* P3 {
// Perform the query.
5 G0 r1 n2 g6 w' D; |5 e3 i! zItem results = qryItem.apply();
) s/ v+ ^, _) G; }
' u* |# H) o+ `% V2 o// Test for an error.
6 @' A; f1 m4 f I3 X. w! Zif (results.isError()) { 1 {' e) V8 N% R+ e
return innovator.newError("Item not found: " + results.getErrorDetail());
) V$ e# Q4 n- \- y# |1 V' q}
8 r6 ?( k' {# ]6 u) o+ g% P
$ {( Y A2 l4 M// Get a handle to the BOM Items. 2 S6 H+ A7 q8 I+ o: n' s
Item bomItems = results.getRelationships(); 8 t" K$ p5 x' P1 m/ ~' h$ g" O
int count = bomItems.getItemCount();
; j) Z& y& z: H% h: w" S5 qint i; - }) A g$ | t
% C5 v) T+ d7 ?/ N* @6 X& W% V
// Create the results content.
- c f( b! h$ A% n# ?3 sstring content = "<table border='1'>" + 7 a6 g* ?' g/ E
"<tr>" +
3 A4 K* C: J2 u "<td>Part Number</td>" + : T* @. r3 X$ I5 c
"<td>Description</td>" +
- J# P, l1 h! ^9 z "<td>Cost</td>" + 5 w! E m! Z+ Z; {( x
"<td>Quantity</td>" +
2 j2 ?1 A! j8 Q. z2 O3 n4 @ "</tr>";
& D0 y' P! `* p+ s, n& N8 f" t ! ^6 X0 D' @7 s+ y( h: A/ H, s S
// Iterate over the BOM Items.
3 p' P* C" B# [' N: A$ Zfor (i=0; i<count; ++i)
* r+ T: e4 l& a- @' O2 ?{ . j J- ~* M, W
// Get a handle to the relationship Item by index. 1 x( e2 H k8 O( \. a6 D; o- Q* N0 t
Item bom = bomItems.getItemByIndex(i);
3 r2 X4 c4 M+ x" u1 @' y// Get a handle to the related Item for this relationship Item.
( r U, p# W/ y" z3 T Item bomPart = bom.getRelatedItem(); # l }+ t; `2 Q, N( V d
) ^: D' \3 l6 V* c- E% S N content += "" +
( O1 A2 c2 x6 p& N: r5 r "<tr>" +
) G, e0 e9 U; p8 _( R5 z "<td>" + bomPart.getProperty("item_number") + "</td>" +
6 z3 q, L$ y( w- p2 ~2 H9 k "<td>" + bomPart.getProperty("description") + "</td>" +
% o- R; ` V5 {, e "<td>" + bomPart.getProperty("cost") + "</td>" +
/ k9 `% D4 e) x p5 j0 X "<td>" + bom.getProperty("quantity") + "</td>" + * b Q" u. b* H j
"</tr>"; 4 I1 N5 S, A0 s/ @
} . _+ g$ u. u2 A
content += "</table>";
* n* J! D' n" u
2 P/ V; j$ r8 H! r. v0 l4 hreturn innovator.newResult(content); / A& V0 s( O5 d$ _1 c n
; k: A& K$ @6 a0 C$ U
n4 g* W" m! }# m- M
2 B2 b) `# z* K; Y$ W. _# O0 |1 ~2 s" |5 b# T8 a
, }+ r8 x! U2 f7 V! W- f3 d0 T/ R- o* _$ `' b" }
" p8 T2 x3 V4 K9 M% @; C4 g Page 46
) `0 X: p, s x' i/ `3 I1 y
, e6 M( L: I/ s0 y% TCopyright 2007 8 ~7 H: n2 L" A- a0 v
Aras Corporation.
! G6 U. z" B5 y9 WAll Rights Reserved.
( u1 h4 K% V" w& t( dVB.Net , ?1 O5 M5 N( v8 ?# I8 B) V. }
Dim innovator As Innovator = Me.newInnovator() % G/ D; d# j+ o
0 x" L- w4 I/ R* `' Set up the query Item.
! Y/ P# z; X9 EDim qryItem As Item = Me.newItem("Part","get") / W- P, u" z+ U5 C
qryItem.setAttribute("select","item_number,description,cost") 5 Z1 E! u) U [" w# g
qryItem.setID(myId)
: X% X/ l; x( Y: h0 p) I
- ^2 E+ N- I8 @0 W2 Q' Add the BOM structure.
8 `/ |( B8 Y4 o8 J) XDim bomItem As Item = Me.newItem("Part BOM","get")
' D* l% S9 c' W& c8 {' }$ `bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
0 D% @3 u! l7 g6 ~* T! [: E) Y9 jqryItem.addRelationship(bomItem) " @: E6 U. V2 J
2 x4 P( o/ i2 t$ {3 T$ G' Perform the query. * a" I6 j" S6 l; R M+ \
Dim results As Item = qryItem.apply() 9 _! C" d8 ~ `+ i' G* v/ m5 K1 U
# M) k! [+ V4 L' Test for an error. ; ~$ ~3 z' m6 @" I1 z
If results.isError() Then
$ @ t- r% s7 c* P) a8 ?, f Return innovator.newError(results.getErrorDetail())
# @+ i9 |' c' }; EEnd If
5 O' x2 Q7 H% p, \( M 5 t* j$ R) C/ L2 u- K0 z' [
' Get a handle to the BOM Items. # d" } Q5 H" q- ^$ i/ W
Dim bomItems As Item = results.getRelationships() / v0 u5 X6 D* r( d
Dim count As Integer = bomItems.getItemCount()
9 a! l' r$ I% f0 _6 j9 cDim i As Integer
5 R4 G4 _2 y; L
, x0 f7 {+ V7 r' _; K& N- x' T' Create the results content. ) h5 N, l$ U+ G ~7 M& w
Dim content As String = "<table border='1'>" + _ 9 r* ]6 J) ~/ n8 q
"<tr>" + _ ( a' X6 u# C3 G5 ]
"<td>Part Number</td>" + _ " V$ A. ^# j# s8 N# I
"<td>Description</td>" + _ # X0 @7 }$ s* r* U% W% C1 d% t
"<td>Cost</td>" + _ 8 e5 J e3 v; [5 ^5 ~
"<td>Quantity</td>" + _
3 ~) S9 j, s8 q "</tr>" 6 ~3 n- H6 | i! w4 k( Y" I' t
7 p" g" Y3 ^" | M' C. ~' d' Iterate over the BOM Items
3 `7 l7 l! y" i- Y4 ~3 S& F; P- MFor i = 0 To count - 1
0 r: O" b7 H G' Get a handle to the relationship Item by index. 2 j- u' [# R* n' g$ v* B* y3 f9 f
Dim bom As Item = bomItems.getItemByIndex(i) , h2 p6 g9 Q7 u* V
# p& X/ s v# f8 Q' Get a handle to the related Item for this relationship Item. 2 N: S' `; b7 S! y# K6 ^
Dim bomPart As Item = bom.getRelatedItem()
# ~- }2 }* ]+ c% D5 ` % `) b% N; B$ A$ M: m
content += _ x' Y0 [ e9 v8 n
"<tr>" + _
1 v+ G0 N- a. R( Q+ A3 P" O5 f& W+ U "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ) J6 U; O$ N: N/ m; S. [* f
"<td>" + bomPart.getProperty("description") + "</td>" + _ % z$ F4 Y2 M8 J) l. `* T
"<td>" + bomPart.getProperty("cost") + "</td>" + _
3 f& w( T# E* I) l. m "<td>" + bom.getProperty("quantity") + "</td>" + _ : N/ o; N% o" n: [$ ^) i
"</tr>"
' P, L# [* j* LNext
8 j) l4 v& L/ r" N" Pcontent += "</table>"
& L6 N1 |# T8 I4 b! n
+ g3 Q) {+ a6 R, BReturn innovator.newResult(content)
8 t3 k& e0 \+ R* D& y2 i9 |8 c6 y5 d8 ?8 q3 Y& T2 X& R
|
|