|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 9 Y* J0 t1 L2 v" }; x: e* t, h5 n
To query for an Item and retrieve its structure you build the query as the structure - N# x$ Q. E! |5 x" {
you want returned. Use the IOM methods to add the relationships you want and 1 \& y6 [' x5 H) q0 j/ i* ^3 V
build the structure in the Item. The server will return the structure that follows the 5 R5 ^# t: J: W$ t
request structure. $ s$ }8 p% ]0 [& S7 W! d9 {
This recipe illustrates several related concepts together, which are how to get a set 9 U; U6 ?- _0 F a& e. r9 z
of Items from an Item and how to iterate over the set, plus how to get the related : D4 B0 M5 s% ?8 ^" t) L g0 @
Item from the relationship Item.
j1 `+ c, G+ } HJavaScript
5 s. N& Z( b8 }% `) \3 b0 t ?var innovator = this.newInnovator();
; m) W2 p' V" L
9 O, B2 K5 a5 N- U' _1 |// Set up the query Item.
+ ]$ @; X$ v2 {$ y/ _- }var qryItem = this.newItem("Part","get");
# B" R1 H5 s1 @qryItem.setAttribute("select","item_number,description,cost"); , m) T9 q: V& G; T6 F
qryItem.setID(myId);
$ X, S- e7 T. U$ c* N3 I# O+ _ & _" X( ?/ h& R: p4 g! Z
// Add the BOM structure.
, Y" s% |- J) v% U; Q: U$ O. ?var bomItem = this.newItem("Part BOM","get");
7 H% F2 G7 q0 P8 I1 R1 gbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); . Z9 o0 }5 @- H5 h# {& i2 o
qryItem.addRelationship(bomItem); $ I* S! _4 Q( b8 b9 b7 |2 C) ]3 @
0 w. n# S* Y& f6 J- j- A" d
// Perform the query. 7 }' U0 W2 w, v) U9 a- C
var results = qryItem.apply();
6 M( X9 p: q, N2 M7 s0 j8 e6 T
5 R! X1 J4 \+ n9 J! A// Test for an error.
/ V( T+ r: W1 V3 g# c1 }& Tif (results.isError()) { 0 E+ f4 | s& ?
top.aras.AlertError("Item not found: " + results.getErrorDetail()); ) w( R" y9 x3 ] Y- G) D" s6 R& C
return; , D3 B" l) t0 o6 q, C" w' b4 [$ k1 |
}
6 x8 Y( M: X! L$ F4 {$ o& E
( z' \2 W2 U1 w4 N// Get a handle to the BOM Items.
8 ~# I& s9 C! D, n) R5 ~0 A4 j' B: evar bomItems = results.getRelationships();
$ u2 }6 U, F k6 Yvar count = bomItems.getItemCount();
9 P7 K5 f2 q, ~# }! c+ {2 k + a) d/ R' j4 ~5 |$ q& q% Y
// Create the results content. ! d% w+ t" l% f* h1 |, v6 k: z" ?
var content = "<table border='1'>" +
/ G h7 t- a5 }2 l4 A; ? "<tr>" +
1 \. H! t) z O6 N% l" s "<td>Part Number</td>" +
8 @* d% ~2 I4 Q0 k8 k4 k "<td>Description</td>" + / X/ U9 Q+ y4 w$ b
"<td>Cost</td>" +
' \/ z" y3 k8 [' c "<td>Quantity</td>" + ! m9 m# }; ]) q/ m/ n! y
"</tr>"; 1 S+ |8 Q' |% t1 \/ h( l9 {
, K9 V- @1 z8 c4 F& W! g( {
// Iterate over the BOM Items.
- Y2 ^; V! O, c1 s* Wfor (var i=0; i<count; ++i)
x3 v% M" Y4 E, z7 `& V{ $ F- d9 y. m. H3 i& O, t
// Get a handle to the relationship Item by index.
& t4 j; V2 {7 n6 b var bom = bomItems.getItemByIndex(i); " D0 D( S; F( T& Y8 P
// Get a handle to the related Item for this relationship Item.
7 a3 i; l6 v* E5 N var bomPart = bom.getRelatedItem(); ' L% z5 q& s+ {& d) A5 D
/ c7 c, o- i) a3 a1 u% h* B! j content += "<tr>" +
3 b$ Z8 A& u" s "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 F( P. n& A5 Z "<td>" + bomPart.getProperty("description") + "</td>" + 3 ^5 a+ l$ }2 c- F( s) i' l% _
"<td>" + bomPart.getProperty("cost") + "</td>" + + b0 o# g) W- E2 q
"<td>" + bom.getProperty("quantity") + "</td>" +
- x: P' D2 a* F3 I5 m. D7 Z "</tr>";
- e' Z8 n9 Q) q0 t1 I} 1 C) T) C8 R+ F; P3 q2 W8 f8 d+ u
return content + "</table>";
( {& c3 j" M; `5 y: `
" n Q3 U- z) i" }5 o
4 |; Y: S5 U9 n1 d
9 B. z" q1 C) ]* \2 H/ q, e0 B* e3 N; i% ?7 Y
C# 3 }# M$ C Q+ S# I2 b5 k
Innovator innovator = this.newInnovator();
+ X' K) z7 r' g0 s( e - k, k _9 {" _
// Set up the query Item. 9 W0 F4 Y8 \7 _% q- ~% o
Item qryItem = this.newItem("Part","get"); " y: X( q9 b& q9 ]1 i, X& N, G& U
qryItem.setAttribute("select","item_number,description,cost");
6 V3 p2 O# I4 l+ p% d% dqryItem.setID(myId);
7 @- o1 [- \+ U: P# S 5 S' x6 w; v( \+ ^; f' O3 P1 `. E
// Add the BOM structure.
2 U k; M6 b- v/ w6 H0 h( G; CItem bomItem = this.newItem("Part BOM","get"); 6 b1 W: Q3 o4 n4 g' A
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
, q5 f9 S5 |+ ~. }$ KqryItem.addRelationship(bomItem);
0 h8 D/ `: ?6 D
1 p. m& S# T T2 b3 k: C- S, ^// Perform the query.
$ k8 x) ^+ h1 D1 W5 N$ R0 `Item results = qryItem.apply(); 5 n6 y3 d* ~" A0 V0 g; d- T+ y
0 f1 B1 `. z: d+ I) s. s& V
// Test for an error.
/ b8 G: H3 E% ]# xif (results.isError()) { 4 m/ m0 Z/ D9 s7 G3 w) p: ?$ w: m
return innovator.newError("Item not found: " + results.getErrorDetail()); # i. ^5 I; O5 R0 G8 f
}
5 Y5 {; {% B2 \& Q% m: x0 {% z " Z* X9 D+ \+ `9 W4 X6 Z' _1 i
// Get a handle to the BOM Items.
0 G0 S7 E6 m( i' zItem bomItems = results.getRelationships(); # |0 C, {, } }6 _8 z0 N; H
int count = bomItems.getItemCount(); 1 ?* u5 ]7 P/ M" x
int i;
8 q1 g$ m6 u2 y% H/ j2 S
- _. C* T# B0 n4 g. ?3 O// Create the results content.
! b8 \/ l4 [* R) U0 m3 estring content = "<table border='1'>" +
5 U) H S; Z1 u& C3 h s "<tr>" + " d& X+ j; g |3 O) a4 `7 l
"<td>Part Number</td>" +
# ?. {, O8 `5 g' U' Y- {8 H "<td>Description</td>" + + h& }; R. q9 D* x
"<td>Cost</td>" +
. {/ m' ^# p6 Q% u; d "<td>Quantity</td>" +
6 K9 `4 R) n( ]5 F& U) A1 {5 f6 i "</tr>";
8 Q8 P3 J# V! L % [4 S7 Z6 y8 @
// Iterate over the BOM Items. # @) G+ i: G3 F
for (i=0; i<count; ++i)
7 c( Q2 ?# u- g7 e) d& v4 v{
0 I& I9 p/ H G& k; M/ M! h// Get a handle to the relationship Item by index.
/ f7 o* z5 J. n. K5 E, k1 v/ |* d Item bom = bomItems.getItemByIndex(i); 5 u/ D) X# }" Q0 W; m+ E7 z# H' d
// Get a handle to the related Item for this relationship Item.
! o d7 s1 z" V0 d# P" z Item bomPart = bom.getRelatedItem();
/ L5 d8 x, S- \1 F q8 y
! K+ S/ J7 [6 F5 ^ C9 f content += "" +
& e- s1 S3 o1 ]2 _* H# L3 P5 [ "<tr>" + " \: T% w# k' E6 p9 m
"<td>" + bomPart.getProperty("item_number") + "</td>" + : N8 L" _/ o/ J
"<td>" + bomPart.getProperty("description") + "</td>" + , D/ Y* U o1 ^: r- C+ i2 u
"<td>" + bomPart.getProperty("cost") + "</td>" +
U# V3 J" h1 `: X- l" v: d1 i ` "<td>" + bom.getProperty("quantity") + "</td>" +
/ _5 Z0 }4 {9 x. O+ y4 _7 M "</tr>";
" Z. d1 e. \$ ~* A6 S% ~4 \} " t$ h: `% A* t: @1 I0 u( o' Q" C
content += "</table>"; 6 A9 w4 o$ {) ^; m1 W
' d2 A' l' S( B- F9 M ?
return innovator.newResult(content);
& ], p' K7 _2 e" u
' ~( p# `) t8 `* Z# v
$ w) r9 ^ l% ?. E0 _. I( n- R; n0 x0 f
7 T( `8 D& {4 u% m$ v$ ^ ]% X4 h: u' n
' _1 `" Q; Q$ z0 B V4 _9 e ' B3 `0 n5 `! {3 l" s" n
Page 46 9 c# k7 q9 N, B- k
' d, w/ F6 H h+ U. ECopyright 2007
A: W2 A j9 A: Z$ f& xAras Corporation.
$ |; R& s1 A) |+ c" YAll Rights Reserved.
& i# D" x9 F9 c4 x' x/ o5 LVB.Net
1 v2 U5 o& O; }' hDim innovator As Innovator = Me.newInnovator()
0 W* b# {+ L/ k: r
. x# ^1 n/ }1 W7 H7 s: j. y2 `, D' Set up the query Item. 9 W# R( G% \# M; W& }
Dim qryItem As Item = Me.newItem("Part","get") 7 S" q8 x# n3 h5 ~/ i6 n @* W
qryItem.setAttribute("select","item_number,description,cost") 0 @! m# A/ f7 X# _) U0 J
qryItem.setID(myId) 7 F% A; a v! G$ B' C! A
5 Q. A/ r; j ^' O1 @8 T
' Add the BOM structure.
/ O: e- P+ I' m% V* VDim bomItem As Item = Me.newItem("Part BOM","get")
+ F9 O& c4 B' c$ |! pbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
3 p! T5 `- R: FqryItem.addRelationship(bomItem)
- O' P" H# Z6 n" L* x& l( s
& [- q3 A/ p9 g9 ^: s' Perform the query.
2 W# w% [. D* |2 L4 z& @& g2 r/ pDim results As Item = qryItem.apply()
: Y( Z& p b# g7 {1 t+ ~2 ?% ]/ [
" ]) A5 q: r/ h3 D* @' Test for an error. 8 m( N, n3 w0 H/ ~7 k
If results.isError() Then / w! N1 i. K9 u; s e! n4 {+ E { r: z& \
Return innovator.newError(results.getErrorDetail()) 1 E" E6 h- h: x* i( H$ ~+ K
End If
" @" F; x! U* m* Z
; S s2 Y/ l6 K+ e" O' Get a handle to the BOM Items.
) l! L' \+ p4 [7 sDim bomItems As Item = results.getRelationships()
+ X+ Z; P$ f7 u. n U+ ]Dim count As Integer = bomItems.getItemCount()
# \2 H! |+ o; k: ?$ B, W7 y+ bDim i As Integer ) `; m) i8 n, H. v$ I
6 ^: l# e! [0 k: c, F) p5 r7 ^7 H' Create the results content. * R' A( J& [. y% r2 I+ ?, j5 m
Dim content As String = "<table border='1'>" + _
* J' \1 A* L9 B& r3 h9 R "<tr>" + _ $ u$ S0 p3 n/ N0 ~8 }, m6 u
"<td>Part Number</td>" + _ 8 n6 o* Y+ g2 T( g; @) r
"<td>Description</td>" + _
0 N; n9 @0 b7 J: E" H' V0 z "<td>Cost</td>" + _ 0 F" a+ }+ w+ t, Q$ S5 T( J4 @
"<td>Quantity</td>" + _
, g( z9 ]& W3 t* l8 A* ]4 c "</tr>"
; \. J" ~6 h' ~7 ^) _ ' ~7 z5 C4 r; E8 o+ K& ~
' Iterate over the BOM Items
7 _" v! m5 b4 L# V4 [; vFor i = 0 To count - 1 2 w; w4 y. @- @
' Get a handle to the relationship Item by index. 6 g1 Y( {4 i4 e' k7 W5 l8 E5 x
Dim bom As Item = bomItems.getItemByIndex(i) $ j& O! O$ l) s6 Y# b" x3 r7 E
7 [& c( r: S/ J j! c, Z3 C7 i
' Get a handle to the related Item for this relationship Item.
0 O8 T {4 Q# q9 U4 F Dim bomPart As Item = bom.getRelatedItem() ' A. ]6 }( _6 C/ R' s' u. {
- \$ B) G0 S0 ~ V0 W9 f* g
content += _
9 u3 }) D1 J6 \3 S "<tr>" + _
; K$ k/ i& ^" A9 _( A2 [0 @ "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ; s9 c+ `2 u+ c- E+ ~* S
"<td>" + bomPart.getProperty("description") + "</td>" + _
4 k2 j5 a+ i/ i "<td>" + bomPart.getProperty("cost") + "</td>" + _
, E9 F7 k& |; R! K" j! L- R "<td>" + bom.getProperty("quantity") + "</td>" + _
, g+ C9 `$ l; a. h6 j "</tr>"
0 ~. M4 T9 j8 x8 dNext 8 X; W- d" t- @2 L& P, ]
content += "</table>" 0 y4 S9 h1 U# b% w1 a
5 R- E" b6 d: F0 O3 ~1 Q& [* v
Return innovator.newResult(content)
5 R8 ~3 @1 D$ G# u% M g
7 j H. b3 Y) x# K |
|