|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 3 }+ h1 s2 x8 \$ }" f7 {% N
To query for an Item and retrieve its structure you build the query as the structure $ j$ u( i% s; W7 V3 D: |
you want returned. Use the IOM methods to add the relationships you want and 9 k. q F/ C* ^4 ], i$ Q# `0 _. W
build the structure in the Item. The server will return the structure that follows the
4 f) u% U3 X5 F; r0 p# Urequest structure. / d# K' Q3 p3 x! g' J, ?
This recipe illustrates several related concepts together, which are how to get a set
2 ?: g" B, A& Y# E K8 aof Items from an Item and how to iterate over the set, plus how to get the related
4 o6 C) C" k9 Y2 ]Item from the relationship Item.
; n$ H" T# w+ ^, MJavaScript
7 q9 j7 t* s* {+ ^) Rvar innovator = this.newInnovator();
4 U! Y) |8 e% F1 { 3 [. B7 S* z+ Q: e
// Set up the query Item.
0 N( z. O: O" j7 y: r& ^/ w5 Fvar qryItem = this.newItem("Part","get"); ' |3 \; i/ O& J' _( C0 d/ @
qryItem.setAttribute("select","item_number,description,cost");
) Z$ j6 f& y4 ?% N$ EqryItem.setID(myId); ; i" z, k1 [3 X; O6 ]
' S$ p4 a4 j. Z// Add the BOM structure.
+ l" i8 `$ o5 T& L- F' \+ e& evar bomItem = this.newItem("Part BOM","get");
( o7 ~- p& y! W2 w" D# N) WbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); % O5 K+ E, X6 _6 H; [! n+ }
qryItem.addRelationship(bomItem);
6 V @' r% L" c8 ? , p. N: ~: | y' ]4 B
// Perform the query. 3 O9 b6 s7 U& ~
var results = qryItem.apply(); : ~" N) P4 p' M7 m; s
& ]" V, n) _3 l// Test for an error. ( o) H) F# N" R+ N
if (results.isError()) {
& }6 [) B- g' l; G3 B% i top.aras.AlertError("Item not found: " + results.getErrorDetail());
9 l# s& @& O8 E" K* Y5 h return;
9 v& G B- |6 E8 x4 g+ b} 1 I6 ^5 h. m. ^
7 q3 F- {" |6 P4 @+ B
// Get a handle to the BOM Items. * G# x: L6 A) ]4 h
var bomItems = results.getRelationships(); . G3 }& l( r0 M3 p: ~* h- L+ v8 f
var count = bomItems.getItemCount();
$ [- |+ v6 d0 ]0 a( U 6 C3 l3 V/ m1 T; R4 v5 c: H
// Create the results content. 8 ~6 X( F! \8 M8 h
var content = "<table border='1'>" +
; X# s2 y# Z1 h& e "<tr>" +
) K- s+ a# W' U, W "<td>Part Number</td>" + 7 y9 F3 h7 l- f
"<td>Description</td>" + 0 J1 u2 {% c, ^, `1 y
"<td>Cost</td>" +
$ E6 R0 q" b5 u6 D! d "<td>Quantity</td>" +
: D9 }% \8 c! E `( ] "</tr>";
6 d% D% y# S; A$ t1 G- Z1 X
3 f/ U) A K0 h& M( f) j/ S7 @// Iterate over the BOM Items. * n8 I0 m. k6 x0 M: g* g& i) H7 e8 m7 E
for (var i=0; i<count; ++i) / w z( G( I8 I0 M' f
{ . E# `5 ?* \4 @& w
// Get a handle to the relationship Item by index. ) ?9 [* X Q' U
var bom = bomItems.getItemByIndex(i); 9 ~! G. ?3 Y/ ^" c
// Get a handle to the related Item for this relationship Item.
! j2 t q( [: I0 c; c5 e' q var bomPart = bom.getRelatedItem();
" u. S+ u( o" E0 T4 L & O( E3 G$ _0 A2 g+ z/ F- f- w
content += "<tr>" + 5 Y3 o: I* F0 f1 Q) h/ B
"<td>" + bomPart.getProperty("item_number") + "</td>" + 0 d- a7 }1 ^ \. A" N# y
"<td>" + bomPart.getProperty("description") + "</td>" +
1 j5 F; D; {5 C1 O "<td>" + bomPart.getProperty("cost") + "</td>" + / _/ S+ e5 ]. J$ `' E' h
"<td>" + bom.getProperty("quantity") + "</td>" +
1 @) z0 W4 t7 U* B "</tr>"; - U6 w- g, \9 I1 V
} 9 C5 X8 p' v5 m4 g# @; X
return content + "</table>";+ v+ J' }0 f0 t5 p2 n' I$ n
Z. R# c2 n+ w8 F, W7 l0 `
; B* |, d/ F" D$ A2 H
5 v( h7 f6 x: y' t+ r, }6 w$ R1 s9 ^- t9 k
C# . a- q* g) V v) O, k
Innovator innovator = this.newInnovator(); 7 _5 m7 h4 e# g9 B' S
1 m( X/ q; ?0 G
// Set up the query Item.
' E4 i& n! i5 k4 R7 X3 RItem qryItem = this.newItem("Part","get");
8 e- x! c8 C, r" u. R- |: B2 H1 L" g. ?qryItem.setAttribute("select","item_number,description,cost"); 3 Y1 w) X1 b# `
qryItem.setID(myId); $ D; {7 `" f* ]0 M- K+ }
& ?$ q9 T. R3 m0 E
// Add the BOM structure.
$ d; j- b* B7 d% a% T! x1 uItem bomItem = this.newItem("Part BOM","get");
" C6 c9 n( e* n5 b A1 DbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
& y7 f5 C) a2 y. Q+ z0 V0 F; rqryItem.addRelationship(bomItem);
) ?9 S1 w: v! a8 a
* Y. P+ W; N( r7 B& M' I// Perform the query.
: N% F q$ `! Z1 P8 i$ {6 OItem results = qryItem.apply();
% F! y! |2 H: H7 V! m
& E+ k7 O% r L1 @// Test for an error.
9 b8 |) h: ^9 c5 b/ kif (results.isError()) { . j4 k# p/ P6 b4 q
return innovator.newError("Item not found: " + results.getErrorDetail());
4 @- c7 k- l i8 `. j} 5 }( x+ e8 \+ U% H/ f: H
. D6 r' W5 N: P. W" p+ {) R" v3 m// Get a handle to the BOM Items. ! J7 Z0 D9 b, L) F# b7 Q3 z
Item bomItems = results.getRelationships(); # T% T, E# l- N( G V L" j2 _' F
int count = bomItems.getItemCount();
' w1 e, h9 x. z* J; Qint i;
1 W: u* j* q8 M- \9 ]$ |" @! _
q% g' w+ n- N; z; [// Create the results content.
$ X' ?4 q" D- Zstring content = "<table border='1'>" + 7 s8 p" A; i/ K3 M! M# T
"<tr>" + $ B/ d7 [; R8 o* j% W0 T/ [
"<td>Part Number</td>" +
, O* Q! I4 H4 q# v; a# L "<td>Description</td>" +
+ R0 ~7 a( \7 p1 r9 t v/ F "<td>Cost</td>" +
9 d3 j8 |# z' c "<td>Quantity</td>" + 9 e }) T" D- H! z
"</tr>"; - P& k; t0 U1 T6 N$ c$ K: N, a
2 P/ `0 U% G6 f! n6 b7 k( d) i
// Iterate over the BOM Items. 2 T d: m) U$ F: p
for (i=0; i<count; ++i)
. ]8 B8 v' Y" i9 O& ?$ p8 I/ X D{
. s6 _) D& y" S4 z// Get a handle to the relationship Item by index. + ^. O& Q' _( o6 K( U7 I% o
Item bom = bomItems.getItemByIndex(i);
- z+ q/ F9 P$ Q- `9 K& N* |// Get a handle to the related Item for this relationship Item.
7 ~" k6 j& B- |/ R, F Item bomPart = bom.getRelatedItem(); ' M" H; W6 G0 s& ~' x
' }& Z4 j+ U+ `" H content += "" +
9 g g) f) A" E3 G8 L "<tr>" + * z- q; K: A7 `9 K; ]- s& s2 G# u: o
"<td>" + bomPart.getProperty("item_number") + "</td>" +
5 p- j5 }# `7 f "<td>" + bomPart.getProperty("description") + "</td>" +
4 G: t4 ]) Y8 Y" d# l "<td>" + bomPart.getProperty("cost") + "</td>" + : V8 \% ~; l8 W$ M1 A
"<td>" + bom.getProperty("quantity") + "</td>" +
. s% `. X' s5 A "</tr>";
' i8 \9 ~$ G# D- d g2 ?} # W, l9 Q- X8 r* h
content += "</table>"; @% N, `' o0 w: C# [- o) ~8 J$ [
9 O {: W( |4 k& N/ xreturn innovator.newResult(content); 8 H% y! L6 f! L3 h3 K& T0 T
) X; C# K5 q6 d2 R" w
, [6 u2 g% ?7 Z2 w
$ I! d& d2 _! c7 K+ U! B9 W5 m. _
% _0 ~9 s, ~1 ]% v
5 K6 C2 u2 `3 d
$ ]) J8 {% B9 Q" N% c. z7 n0 f
# {& h8 O. t4 U. V* [' W( Y! _ Page 46 - L0 v0 Z" o3 Y& B# c
' y7 r9 H4 y9 x1 J* F1 y( U" Q
Copyright 2007
* d+ E! Y) @+ _Aras Corporation.
' y0 C. o2 Q$ z) x3 EAll Rights Reserved. $ @$ P" ~2 f; O( U8 M4 P! m
VB.Net
$ [- ^; R' q ]" C* HDim innovator As Innovator = Me.newInnovator()
" b* I( W7 Z5 }' r) i2 z2 l- }
, j) }/ ^" d. d7 C3 a* O& }/ D' Set up the query Item. 6 _3 w# a# N3 n7 @# Y
Dim qryItem As Item = Me.newItem("Part","get") ' D% Q1 f! F+ A2 Q
qryItem.setAttribute("select","item_number,description,cost") 9 X; h% i. @* ?
qryItem.setID(myId) # `- s5 q/ r& F$ ~- \
H7 L5 n: g: \# p0 v: v
' Add the BOM structure. 0 s5 C/ u& b `
Dim bomItem As Item = Me.newItem("Part BOM","get")
8 X: w4 ?; e5 e3 w1 }/ fbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ; g( s* I- ~- b9 ~9 n. t
qryItem.addRelationship(bomItem)
: V5 R9 @6 j" l
- T0 y q' H: w# E0 @7 _' Perform the query. & l: W9 N/ ?# n# ]! b; _6 U
Dim results As Item = qryItem.apply() ; v1 B4 `8 K4 d4 d. y4 y/ K
( d* Y# q' f" _7 r0 k k, Z
' Test for an error. / r& N5 a/ N0 q/ g- i/ m% ]
If results.isError() Then
5 \! X+ ]7 O+ c. W: Y Return innovator.newError(results.getErrorDetail())
( F$ I" R5 {4 a' TEnd If
7 |& F8 j- m5 U! u0 L G2 `; G# v : R, s3 D" m3 L! F$ t! p
' Get a handle to the BOM Items.
( N( v* w$ B5 s b1 qDim bomItems As Item = results.getRelationships()
, o1 I9 Y. ^' B3 Q9 } A& ^0 nDim count As Integer = bomItems.getItemCount() # a, _) J( w! s7 q) Y5 q
Dim i As Integer 6 B" N) `. _/ j. r
' J) q: ~6 s( b9 o
' Create the results content.
2 l# E* d" W4 k9 i) l$ _9 mDim content As String = "<table border='1'>" + _ 7 p2 c$ W. { X8 q% t; ]
"<tr>" + _
$ ^9 M& }- A) `- d% b: ] "<td>Part Number</td>" + _
3 g! Z4 P+ U# r "<td>Description</td>" + _
5 i9 |. g0 I3 M' j, G. [" A. b! _ "<td>Cost</td>" + _
|7 Z2 z7 h/ g* \ Z& { "<td>Quantity</td>" + _ g9 k! E' d$ n' F' r
"</tr>"
' \7 @( Y$ G5 r6 c- I+ G" V5 _- c5 z
1 T3 w9 {7 r, G& T6 [/ k5 G3 a& e' Iterate over the BOM Items
$ V6 m% P J( }6 \4 @; iFor i = 0 To count - 1
: \* Y [2 G$ T, H$ o* a' Get a handle to the relationship Item by index. 3 Q$ u L: P) r7 l9 V
Dim bom As Item = bomItems.getItemByIndex(i) ; c @4 r6 T/ u! M) i2 o) v
. \5 R* S/ q( ~2 o1 B( |1 f! Q' Get a handle to the related Item for this relationship Item.
7 h- g$ X' `, @( v Dim bomPart As Item = bom.getRelatedItem() / O( W$ b4 \7 L8 ^+ E C, w% k
! `7 W: `% l, L$ H9 {# G! A
content += _
/ }/ F: n) m1 G" j* G% P "<tr>" + _ - m. g7 `) E& e1 @, `1 x0 s
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
; m2 g3 u: {+ r6 ?& A "<td>" + bomPart.getProperty("description") + "</td>" + _
7 I. e$ ?: `6 @# c$ J7 [ "<td>" + bomPart.getProperty("cost") + "</td>" + _
M$ E: l0 A0 m8 ~8 m/ N5 H "<td>" + bom.getProperty("quantity") + "</td>" + _ $ c( K. g1 ~& Y0 V Q0 l
"</tr>"
- H1 h- I6 X) F; ~Next - N( Z8 r' v r% X
content += "</table>" : Q# u. z9 H$ C& k8 U8 _* Y1 Y
1 A: E8 R" R. L/ w" R
Return innovator.newResult(content)
5 z0 H ?5 P$ V; ]+ h- H/ r+ s) c6 e2 F7 K+ y/ }1 P
|
|