|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
, s( `4 i) m7 z9 [, M# v: LTo query for an Item and retrieve its structure you build the query as the structure
/ S# m1 a5 s; @0 y$ Yyou want returned. Use the IOM methods to add the relationships you want and # Z/ @% n% A% u! \3 w; @4 ~
build the structure in the Item. The server will return the structure that follows the
1 C/ I7 N2 ~. z* F7 e0 hrequest structure. 9 |# T2 f v7 h" k y
This recipe illustrates several related concepts together, which are how to get a set
4 U1 s2 Q0 Q7 a, Vof Items from an Item and how to iterate over the set, plus how to get the related ! V* c- e7 b I
Item from the relationship Item.
) I, k' o9 }9 `5 Z! {8 vJavaScript ( `6 y( j+ E% @
var innovator = this.newInnovator(); . Y" Q- M( P1 d0 D. k# B
% E- h2 ]/ z* V4 G5 ^1 `3 z9 g// Set up the query Item.
W. H4 j( \ ^& Z9 ^0 v2 X2 i9 A0 }var qryItem = this.newItem("Part","get"); , p" K% H! ?0 r+ h* \
qryItem.setAttribute("select","item_number,description,cost");
( c: p/ u( Q; `2 w3 g0 RqryItem.setID(myId); 8 i3 a' K1 O6 L/ a4 Q/ J* I+ d
' o' z/ \6 A' H9 e/ |! U- { s5 ^
// Add the BOM structure.
4 \) G! t5 v- {: X. Z; ?var bomItem = this.newItem("Part BOM","get"); ; l& f z" N3 ?7 V1 N' h
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); / R2 T9 w6 n2 Z. R
qryItem.addRelationship(bomItem);
1 v/ u3 ?' T. X1 j" T $ K. U7 s) F# f# B i3 F H U; x( h
// Perform the query. 6 X( v, y+ R8 [9 F: H1 T- W5 V1 x
var results = qryItem.apply();
' O* x5 n+ G9 W: P1 S9 f- D
% F3 I# }; N m3 T// Test for an error.
, v7 c7 ~! q1 J$ fif (results.isError()) { ) Q( n$ @" p9 W% B* l
top.aras.AlertError("Item not found: " + results.getErrorDetail()); 1 }! n( ~$ M2 u# \# G" }6 C3 K
return;
4 |. ]) D4 ?6 H" R' I P} 4 b/ H' @! c# R& e
$ k$ D! _; o- }$ K; D
// Get a handle to the BOM Items. . q' {& y5 m# n$ ^
var bomItems = results.getRelationships(); 7 r& K( R/ ?0 H7 F% ?3 a
var count = bomItems.getItemCount();
% A9 p0 D9 x$ X" S: `) A
3 A0 | S" C9 P4 S& I5 K: W// Create the results content.
1 _' T' `5 R7 R8 S9 @var content = "<table border='1'>" +
9 O3 [1 h( [% V5 B "<tr>" +
6 d4 K8 _) R: R% ?( k "<td>Part Number</td>" + 2 M% X7 K$ k5 Y) ?& Z1 G
"<td>Description</td>" + 7 a7 @, v6 F3 x. W
"<td>Cost</td>" + 9 v$ Q& _" m% E; x6 T, N T
"<td>Quantity</td>" +
+ S% S* X/ S5 g6 h, h2 ]7 O( Z "</tr>"; 1 y% w+ n( s4 f
" _( b$ \7 M8 K- r
// Iterate over the BOM Items. ! j% u8 F5 M" o4 z9 S$ r5 Y% F* c
for (var i=0; i<count; ++i) - r' k! T# P$ ~ C' t6 w
{
! z; d% S8 f$ N0 Z. q+ k6 v// Get a handle to the relationship Item by index.
& ]& o6 N) N$ R2 ?* d. K var bom = bomItems.getItemByIndex(i); - ?/ b r, B. C# q' C3 z
// Get a handle to the related Item for this relationship Item.
( d5 ]( x( M* ~7 b' d var bomPart = bom.getRelatedItem(); % |' ^0 n# ?( n7 o5 ~- T
' g& y' h: H3 T9 m content += "<tr>" + 4 p8 h. T- z- @) |
"<td>" + bomPart.getProperty("item_number") + "</td>" + 5 O9 a1 {6 R& n5 ^' i6 n
"<td>" + bomPart.getProperty("description") + "</td>" +
8 l" y- o# a- i5 F, k* H2 ]0 f "<td>" + bomPart.getProperty("cost") + "</td>" +
$ _. k7 d- E, e6 N3 D' m& l2 v# V, } "<td>" + bom.getProperty("quantity") + "</td>" +
. C4 n/ h' F4 @0 J "</tr>"; 6 U6 f3 E; k1 k0 r
} ( p p& w+ y, _
return content + "</table>";
# ~* D% E% T8 w# \7 U! y& Y
8 P% s! F- {% E( z2 p& b* }
$ k Z$ Y, {5 v; W# m/ H2 W- x& d8 U Q; a# W( n4 J: F( J
2 ^/ o: k$ T! X+ y7 P( r1 t$ q* R
C# . F, x$ [% B* l) q/ @/ L
Innovator innovator = this.newInnovator(); $ ~: k' W+ H% C9 w4 D( p( ?7 n
2 ] h' {% n' f2 \" `' D/ A// Set up the query Item.
. Z; ^7 B( } f4 M1 h: C0 a' kItem qryItem = this.newItem("Part","get");
; Q# i4 t2 m5 F0 e4 dqryItem.setAttribute("select","item_number,description,cost");
& W+ I2 b3 R' N f6 @qryItem.setID(myId);
2 p" r( E2 o5 c. c& ^
" w9 \! \% o7 W, n5 S' }// Add the BOM structure. 4 |2 A2 A# K; L- W; n% i
Item bomItem = this.newItem("Part BOM","get");
( @( |4 J/ a$ u/ j" zbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
5 m. F2 \0 ?" T+ W. J. w% mqryItem.addRelationship(bomItem);
& U, H. {9 f. B3 K0 D, `5 b- o
# }8 |3 f/ f1 [3 ?; _2 J; W// Perform the query.
1 A, C7 X4 @2 vItem results = qryItem.apply(); 7 i2 ?2 D9 y$ j! O
! l/ ], r* o- K) _
// Test for an error. # b% w% g, U. W( C; X
if (results.isError()) { 2 S9 ~ k/ ?1 w$ r! w
return innovator.newError("Item not found: " + results.getErrorDetail());
2 z+ R- A1 P! H) |) @! D6 w}
( e) a% y, W/ L( P
1 h# k1 E& a/ G( c// Get a handle to the BOM Items. % Y% {! L7 W/ M+ i
Item bomItems = results.getRelationships(); , J1 S' R7 l4 ^
int count = bomItems.getItemCount();
/ n9 R Z" F$ |2 o$ K( p7 \8 E% gint i;
; `1 r" D$ p/ P; p ? / i3 ^% n% }2 P4 D5 ^% B
// Create the results content. 1 u* A1 J' Z. M# [) L: m
string content = "<table border='1'>" +
1 v( G- ]" z+ |5 C- \ "<tr>" + ; |; Z4 [! M9 U( \/ `
"<td>Part Number</td>" +
; K {8 O' z+ c: S0 c+ M, n "<td>Description</td>" + ' A5 Z- v. |& a3 t% ^! r$ y
"<td>Cost</td>" + ; G2 t& P" O, {; F b
"<td>Quantity</td>" +
/ g9 y! t- r+ } "</tr>"; 5 S/ a: n, g4 B5 _6 @1 ^
, `% ~) {4 b% |( |// Iterate over the BOM Items. 0 P9 {% C" _9 m6 `2 y
for (i=0; i<count; ++i)
3 N0 E: p7 A; U9 M{ 5 p% B; w! D& @# G T6 P
// Get a handle to the relationship Item by index.
& u7 B$ l( _9 r0 P& n6 X Item bom = bomItems.getItemByIndex(i); - D: X; |7 H- k# u% G% j
// Get a handle to the related Item for this relationship Item. 8 i0 v8 n7 W) ~( l/ m) w
Item bomPart = bom.getRelatedItem(); 5 N1 N6 k" u9 x5 X+ ^6 S
- {* j; K+ R3 E8 V9 z! S0 a content += "" + : i9 f# s7 u! J$ n' H
"<tr>" + o5 ^ n6 K, `0 z% |9 B* c! t- {
"<td>" + bomPart.getProperty("item_number") + "</td>" +
4 d8 ?$ ~& m$ |( y" G* L! t0 i "<td>" + bomPart.getProperty("description") + "</td>" +
. m2 P. j# f2 A4 B9 J; k9 s "<td>" + bomPart.getProperty("cost") + "</td>" +
* |5 i9 E. |' C7 n( c "<td>" + bom.getProperty("quantity") + "</td>" + & Z0 i5 w$ _+ @# ~+ u7 U f' i
"</tr>";
# o/ i. J# m+ g2 W) ^+ N}
+ S) Q# g) O% ]0 t( S0 m- h# Vcontent += "</table>"; 6 U2 M! u7 C2 D' W9 E4 x4 ?
! w, ` G/ s1 l. H6 R) ^+ V" q
return innovator.newResult(content);
: x! m; ]' H9 O2 f) b$ N0 J6 \7 K' b5 T n; y( u; c* r5 B5 l
. a- @ U, G6 K" U; T
5 X% K7 M" U- n; s- ?7 P* t6 n1 A+ X% I2 R. i2 x4 x1 p
: }6 R/ _* y5 T/ ?5 c* P1 b
2 P7 N. W7 b: R1 g% b % c% B, ?: |- I a$ W, N1 ~6 h
Page 46
* _9 K# |* r. V) {, O, e. h
s8 v( n8 e9 GCopyright 2007 * `# _$ @" i! v' p) ^
Aras Corporation.
6 M! Y, |% [. l9 x$ B$ z6 Y; rAll Rights Reserved.
* Z( @- P- {+ ^8 z7 jVB.Net
- Q3 V2 f E* P9 ~) N1 ]Dim innovator As Innovator = Me.newInnovator() w7 z, N; \) U7 m; l# X
@/ O& f: ], j |' Set up the query Item.
. _ h6 M% c- t3 _- jDim qryItem As Item = Me.newItem("Part","get")
* f0 s6 k$ e* O8 l# K& C3 DqryItem.setAttribute("select","item_number,description,cost")
9 O( P! d$ a H9 LqryItem.setID(myId) ) g: H4 s6 k9 Y% t {6 S
7 n4 R j& D4 e; _5 F' Add the BOM structure. # E: b" L3 w4 ~' u- D1 T' [
Dim bomItem As Item = Me.newItem("Part BOM","get")
7 I( [0 s% N9 n7 A8 ?bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
( W& J& e8 a& |. A6 kqryItem.addRelationship(bomItem) 3 K- e. e$ V ?3 {
6 C N- h9 S( r8 \- @6 y' Perform the query.
& W, U8 h( F) JDim results As Item = qryItem.apply() 7 ^# D6 |8 j; @8 Y. A
3 z+ l8 E* Z9 J, q) h" F
' Test for an error. 9 P$ \1 k+ o$ o3 }4 z) B: N8 | }
If results.isError() Then
7 ?8 I4 ?6 W. `; | Return innovator.newError(results.getErrorDetail())
! ~9 g( F( I! a4 \6 f K" {. g) oEnd If
; a9 N; a7 R. k9 q2 w & Q; l8 ?1 p! P( y
' Get a handle to the BOM Items.
) l) S. T1 \* W7 C, H: H* GDim bomItems As Item = results.getRelationships()
- T( f$ X1 D0 tDim count As Integer = bomItems.getItemCount() 8 [: h5 y# q; }# @6 P# ?
Dim i As Integer
. b3 {$ b$ z' N1 h- Z+ i# z
( P D5 `# O" C' Create the results content.
# ]6 p$ E1 P% o$ \1 ?Dim content As String = "<table border='1'>" + _ $ y% X7 m! p! P+ X0 Z
"<tr>" + _
2 y6 q+ W. x- H2 u) @5 K "<td>Part Number</td>" + _ & U3 [ C2 q: H& ]2 I
"<td>Description</td>" + _ " D6 {! B" r7 S! O+ F9 q0 A
"<td>Cost</td>" + _
5 I6 D4 S: O9 R9 o "<td>Quantity</td>" + _
0 a; k& b6 q2 q$ ] D1 W( @3 a6 B* t "</tr>" . H/ j0 i. X. i
) M i! j. w0 q+ F3 N
' Iterate over the BOM Items 3 E9 K1 V, {5 s- {) i: a' S
For i = 0 To count - 1
1 k* ]. Q- y2 N- m0 [' Get a handle to the relationship Item by index.
/ E) s+ }/ Y6 C" t% w! Z- s# n0 S Dim bom As Item = bomItems.getItemByIndex(i) $ J2 g" v' s6 e( c4 @1 ]* W
1 [, @2 ]' K" M; K8 x* C' f' Get a handle to the related Item for this relationship Item.
9 N! K/ e0 s. S% h( h Dim bomPart As Item = bom.getRelatedItem() 0 U4 U0 ^1 W/ c7 s' C% f
' @5 }; C, B% T$ P
content += _ 4 P$ H! ]# S ~4 Y
"<tr>" + _
5 j' \% P. X2 O8 c7 V+ @6 f2 `. u "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 4 D, ^0 e8 `* J& ]- S+ ]# B
"<td>" + bomPart.getProperty("description") + "</td>" + _ * q2 N, t" D) x% R' @% T
"<td>" + bomPart.getProperty("cost") + "</td>" + _
) Y3 ?" G5 p* T: M# a0 M+ } "<td>" + bom.getProperty("quantity") + "</td>" + _
/ r1 a; s9 C \# w, U- _) q V# q "</tr>"
6 x$ S/ c9 d; H* o: X+ M, TNext 3 m% y5 S5 d/ F. \- ?
content += "</table>"
& s3 @0 G6 ]3 S: ]7 l( C6 n . Z. L8 G0 x' @* V/ o: I9 }; Y( ?
Return innovator.newResult(content) + C' F% p9 O$ v/ t0 X
! H( m: D, s+ [% B4 C; _; x3 Z* x |
|