|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
% e2 S: ~( C7 q! F7 X2 ^5 Y8 WTo query for an Item and retrieve its structure you build the query as the structure ! k3 M1 G$ k x7 y$ B* V! ^
you want returned. Use the IOM methods to add the relationships you want and 6 g9 r. |: `4 m5 F, a( I+ s2 V
build the structure in the Item. The server will return the structure that follows the 3 J# @6 V% \& C$ ~
request structure.
: c0 x( z; C! FThis recipe illustrates several related concepts together, which are how to get a set ) j( A$ Q- r. K
of Items from an Item and how to iterate over the set, plus how to get the related
/ |+ j' m2 c# b$ h9 q# U& s& vItem from the relationship Item. ) o* y6 S4 N( {
JavaScript
# B! _# q' j% _var innovator = this.newInnovator();
]$ T# w$ T9 h8 g. W
- R8 c" Q5 ~) j4 K0 Q) ~// Set up the query Item. * x5 j5 O8 g& f5 X& ^
var qryItem = this.newItem("Part","get"); 1 k" J0 l& |7 S
qryItem.setAttribute("select","item_number,description,cost");
1 o4 f9 o8 T2 i3 Z* c7 LqryItem.setID(myId);
# R7 [3 C% r" ~- ~
- B/ ]! N# u: E$ {// Add the BOM structure. , q( |# y1 _4 l
var bomItem = this.newItem("Part BOM","get");
1 q2 Y2 Q& b; J- v {0 c1 p" TbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
/ X( p% z6 e p* j1 SqryItem.addRelationship(bomItem); . Q% }% M2 R+ i7 V" e* D
/ Y5 `' d3 f2 B// Perform the query.
# E# u+ W* E: x% S# I9 dvar results = qryItem.apply(); g* q5 V p! Y( Y+ j
$ c Y! S( Q% D: c: K& b
// Test for an error.
# V6 ^; G2 Y" y cif (results.isError()) {
9 M$ U8 C1 ^- Q& T6 T2 a top.aras.AlertError("Item not found: " + results.getErrorDetail());
' D: p! i. G; Y return; 9 f) C% C9 o. U" U% B/ V, W1 E
} & u" Q% @. w% m& v
) e. P. [: A" U* Z! x, F. e
// Get a handle to the BOM Items. ; q6 G: H2 x4 g- t* {+ X
var bomItems = results.getRelationships(); # D1 O: [' Z* b. \" k5 u* l' a
var count = bomItems.getItemCount();
# k. o& O$ }7 z8 c" m , @- a7 P; u, A y: V
// Create the results content.
6 H' W" v3 t+ x9 v% Fvar content = "<table border='1'>" + # s- p* ^' t9 M5 h- O- g4 X
"<tr>" + ; y4 N/ Y5 G# ^ k" |2 C
"<td>Part Number</td>" +
2 v- W! y4 ^: `: `" w6 l- r "<td>Description</td>" +
4 B8 t3 q3 h% u "<td>Cost</td>" + " c$ A+ d! z7 {+ H9 E) c* ?. L' E
"<td>Quantity</td>" +
- M* O% N$ V. F1 o, | "</tr>"; 9 u! N: M2 K, z) M
& a9 s- r0 U8 u2 x0 i9 v! d// Iterate over the BOM Items. $ w; v4 c1 E9 a6 f. t X& [8 H: \
for (var i=0; i<count; ++i) # x j3 r! S/ X$ C T
{
4 Y: ~1 m# c1 v0 ]% g- k// Get a handle to the relationship Item by index. . y1 H; G" T9 p7 Q
var bom = bomItems.getItemByIndex(i); ; h3 n2 {% p9 r5 M, V/ P# B
// Get a handle to the related Item for this relationship Item. 9 D6 ]9 ~3 m! t1 m2 ]3 l
var bomPart = bom.getRelatedItem();
. z" _ F9 H' D; [7 Q $ |7 X8 U! s4 h8 E, a
content += "<tr>" + 0 ^0 J" [9 m/ {) E' J, p% n
"<td>" + bomPart.getProperty("item_number") + "</td>" +
! b" P4 ?. v* J. a' i "<td>" + bomPart.getProperty("description") + "</td>" + $ C9 U+ S( s3 k3 O$ Q% P: H( }
"<td>" + bomPart.getProperty("cost") + "</td>" +
! x y: j R- R) q7 n# a. l# [ "<td>" + bom.getProperty("quantity") + "</td>" + 5 T/ s" _) P# j# R% U# S7 K
"</tr>"; % P2 K: s) T" n( d3 U; V
} ( W. `# \7 L* R' i) E1 W `" Z
return content + "</table>";5 G. D5 y9 D ^, M9 U* V( {
: i, X2 Q+ d( Y2 W- o8 L" `
# m7 q' |( |: d/ D1 o$ v! X
8 h0 k! [0 X$ z o/ w) I) K' Z9 X* _2 l2 x. B
C#
) @# Y' P1 `6 [3 GInnovator innovator = this.newInnovator(); 9 z5 B8 e* T! i+ V2 t
- }7 U+ z2 o2 h9 y& L# Q// Set up the query Item.
t; G+ K" [8 |0 yItem qryItem = this.newItem("Part","get");
8 V! m* O. F1 }- Q1 i F, e; uqryItem.setAttribute("select","item_number,description,cost");
$ P* L: b# b5 N9 x* |qryItem.setID(myId); / H0 V2 k9 E$ [0 |% ?6 |8 I5 x u0 |
3 O! d3 |% l! Z! ^9 B1 a ]4 H4 u// Add the BOM structure. ! M6 c/ S4 u% J0 x/ }: V* n
Item bomItem = this.newItem("Part BOM","get");
: N9 X1 H+ P: m! H- r& p$ dbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
3 I2 H% @* U5 ]6 f4 U# C7 f' HqryItem.addRelationship(bomItem);
( S7 [! {& `/ g+ d$ P9 ]. |8 g5 X3 p, J
7 B- L/ F! M9 T) x ]// Perform the query. / R& x. Q' J( p: b
Item results = qryItem.apply();
0 A, j9 N; d* S" i
+ R8 j) `! L" _) H4 @// Test for an error.
( w* `6 p# y. N. \2 q0 B; ]% Uif (results.isError()) { 9 F( [7 C- I& f( t# [( V: Q
return innovator.newError("Item not found: " + results.getErrorDetail()); 5 G5 c6 ^- C3 {8 u% {# v. m4 O w2 G
} ; T$ y/ Z7 Q9 `
: B8 P+ Q' v9 `" x
// Get a handle to the BOM Items. Q" L' \( ^# g. d
Item bomItems = results.getRelationships();
) ?% I" V$ p8 X0 Dint count = bomItems.getItemCount(); : n" Q. k' X/ v0 y- j
int i;
; j1 o/ \% N/ T% A: h
B1 r& h; y4 X// Create the results content. 7 M8 e- ?+ D3 ~! }1 G
string content = "<table border='1'>" +
: _/ S, X4 j6 l "<tr>" +
/ H( ^0 [+ S5 a* ^ y) }9 s) B$ S! v "<td>Part Number</td>" + 7 N0 K1 c1 V4 f1 K7 l" s
"<td>Description</td>" +
6 Z2 y/ l+ O( |* v/ a4 }3 v "<td>Cost</td>" + k/ T" z5 i4 ^
"<td>Quantity</td>" + ! M5 a& x! D5 a2 u9 O
"</tr>"; 7 K' s7 ^! q0 A' B+ ?& O+ p$ t" S
+ r3 W7 H) J9 f2 {
// Iterate over the BOM Items.
% \1 o8 L! U) n- A' [9 k. E. \for (i=0; i<count; ++i)
) D$ l8 s: v0 A% F8 g8 {{
5 a5 I/ x; d* U+ ?. u# q( h$ ]( P// Get a handle to the relationship Item by index. 3 z& s+ r, k' T, _
Item bom = bomItems.getItemByIndex(i); : g9 n6 z2 E0 m M
// Get a handle to the related Item for this relationship Item. 2 O% s, E0 [! [/ {4 j
Item bomPart = bom.getRelatedItem();
6 S3 A+ M' y0 }. F5 ~0 [
/ H+ d+ Z3 h/ `! Y# q content += "" +
1 _5 b) k2 ~. i2 i "<tr>" + " v6 R, A7 ^6 v+ U: O$ @' s
"<td>" + bomPart.getProperty("item_number") + "</td>" +
4 b" w+ y; t0 w% ^ "<td>" + bomPart.getProperty("description") + "</td>" + 8 T: H. @! `: {8 c7 i- {
"<td>" + bomPart.getProperty("cost") + "</td>" +
- h9 L0 X% x- N9 |% Q( `5 N "<td>" + bom.getProperty("quantity") + "</td>" +
2 q8 i$ g x4 o c "</tr>"; $ x: { X& M$ O. k. s
}
6 N- \0 H! \* G/ ~& tcontent += "</table>";
3 `: h* s, C. ?( u4 O
5 l. O8 u* W& @6 [/ ~return innovator.newResult(content); # K( b7 w; w+ X( n
2 a) X$ Q, x: P' ^4 D, T- V0 P9 {2 V. B9 u; m% l* S9 R
4 t, v4 }+ U) @5 X
3 {" H9 @7 H7 f# |) D3 e- a! W
4 f. Y4 o ^0 _. q# \1 L2 p7 {4 o5 F- M8 q9 w- T/ q
! x; w, u0 m9 n& c Page 46 3 ^3 {3 J% \! r, _
) y" _% _/ a# o3 _Copyright 2007
3 w2 i( X% _9 R9 [Aras Corporation. , ^. l$ _: m; h
All Rights Reserved. ! e" ] x( B! v2 n% h
VB.Net
! c; s: U* G+ y$ E9 A8 FDim innovator As Innovator = Me.newInnovator()
% J- O1 v+ G+ l % ]# w# p4 i3 j/ W+ ]! ^
' Set up the query Item. 9 K9 D' L3 s# d. L1 p
Dim qryItem As Item = Me.newItem("Part","get") 3 H* ?* B% Z0 Q: A% }3 H! e
qryItem.setAttribute("select","item_number,description,cost") E& F6 v$ L8 H, F" C
qryItem.setID(myId)
( `) A1 `. @9 s8 }1 w/ x
0 N- j" O6 E7 ^' Add the BOM structure.
# n; Y( q) q3 s3 t% qDim bomItem As Item = Me.newItem("Part BOM","get")
. E( k6 ~# ?1 F; _1 U2 ZbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") : y/ ^! ~: b/ L, h5 O
qryItem.addRelationship(bomItem)
& b& t! b! x Q/ h8 V1 Z) H) Q3 S, O 8 l9 l9 r/ ?" u, V' ]7 I! I0 d5 r
' Perform the query.
# `2 E: D+ ]4 T& ODim results As Item = qryItem.apply() , `, ?1 D0 y* I- i3 o& b' v3 N
5 T. }0 Z& {. K! K& ]' Test for an error. 2 o: U" x- w1 n# `) v
If results.isError() Then
! t5 a7 H2 O6 Q Return innovator.newError(results.getErrorDetail()) 7 `5 `& I, B) X* r
End If
& r! c2 P% [( Q) y9 f ' h5 \7 ~9 j, \+ D: D
' Get a handle to the BOM Items. ( W! y/ k$ W; |% N9 n3 H" x* ^1 s! D
Dim bomItems As Item = results.getRelationships() - T1 ^' `+ l* p% c1 s& A$ ^
Dim count As Integer = bomItems.getItemCount()
/ Y% k* U( r' L/ G0 `Dim i As Integer
" c; W" a2 A2 {- a/ N$ ~% d, d
- M. s! b3 U6 A _' Create the results content.
+ w) A, p2 J! i; m! VDim content As String = "<table border='1'>" + _ 6 c# X4 _6 l6 ? t" f1 G& t
"<tr>" + _
9 r) i( A) u6 K6 ~/ O% ? L "<td>Part Number</td>" + _
3 [* G: e" B2 X# P "<td>Description</td>" + _ 9 B3 W$ v# j/ {' }$ x
"<td>Cost</td>" + _ # ^; M! U5 T6 ?
"<td>Quantity</td>" + _ - X% M* \5 ?; ^; ~
"</tr>"
- n; L( \0 g1 D [ u J9 V
' w6 l# [2 }, e2 m/ z! ]0 @' Iterate over the BOM Items
6 G5 w$ N2 f+ o7 b. |! VFor i = 0 To count - 1 " Y) ^3 U, ]4 p9 ~. w: r$ |
' Get a handle to the relationship Item by index. / l2 p" z S! K- ]- a2 h3 ]
Dim bom As Item = bomItems.getItemByIndex(i)
. U& S: ~( t9 k b ( B8 w" n2 e; d" m
' Get a handle to the related Item for this relationship Item. 9 g- R9 [* x" x, H7 J5 ^, ]
Dim bomPart As Item = bom.getRelatedItem() ' t0 J. p% b0 M6 C+ Z9 k( C' q
/ i, C9 K2 N E/ t9 k( ?) a: r
content += _ 8 o$ X8 A- k2 R7 |! T
"<tr>" + _ : Y( M n2 ?: }; q1 ~
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ . `& H' K; ^! T
"<td>" + bomPart.getProperty("description") + "</td>" + _ ; K' M! B7 R# J
"<td>" + bomPart.getProperty("cost") + "</td>" + _ 9 y( n7 s$ n+ s/ A- ]& g/ h
"<td>" + bom.getProperty("quantity") + "</td>" + _ , L5 \+ ^) ~' m+ Y
"</tr>" c7 u0 k5 j; @* a& ~ s% e; n
Next
) y m- k! |2 ?9 wcontent += "</table>" 6 I/ z! ~' a+ `
0 B1 O6 G) M' }, R$ f" @+ j0 `Return innovator.newResult(content)
# j! Z% b/ W: M/ E, h2 h
, d% o. u/ o1 V/ c |
|