|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
3 u( l/ `$ r: ~* eTo query for an Item and retrieve its structure you build the query as the structure
G3 H$ l6 U/ |& `! J; ^* R* ]you want returned. Use the IOM methods to add the relationships you want and
9 h, ^7 W- P( p' O L) j: h, vbuild the structure in the Item. The server will return the structure that follows the * G+ w# z' _5 a
request structure.
2 s" R j& k2 F% ~. w- ?This recipe illustrates several related concepts together, which are how to get a set
' G1 a b7 X N7 }! e$ B! wof Items from an Item and how to iterate over the set, plus how to get the related 0 v$ ]" U. @9 ?" _7 P5 t
Item from the relationship Item.
" y* D0 l1 g; h& n, q _JavaScript % ^# J- \' f" j( x
var innovator = this.newInnovator(); # ~3 E! O: u0 b# O
6 ]$ J# G; T1 t, p2 p// Set up the query Item.
7 \# R2 p9 L7 `var qryItem = this.newItem("Part","get");
/ _- Y; O. ]5 j+ W9 o7 Y( PqryItem.setAttribute("select","item_number,description,cost");
% x$ a& Y% Q5 S6 o" S( B' CqryItem.setID(myId); 1 e# o. S5 i5 X0 U! y
2 d3 A4 r6 u" y& r$ d// Add the BOM structure.
( |$ T& p6 |; _var bomItem = this.newItem("Part BOM","get");
; [: r; j0 w: {% i+ @0 d7 f1 \9 vbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ! q, _5 Q' e! [/ X+ J0 [1 j
qryItem.addRelationship(bomItem); % o; n; n' S: @0 {6 O
: B: M ~6 [! b5 E' |3 y
// Perform the query.
[/ C( ?- K0 A% u$ Z4 Nvar results = qryItem.apply(); ( J0 R, c& u, T5 c* {
! G t9 ~: q5 e3 r) M G// Test for an error. ( ~, [* @3 U- B# y9 \8 D
if (results.isError()) {
* t( X L4 X3 T, R( t& i top.aras.AlertError("Item not found: " + results.getErrorDetail());
4 i0 E! A% h a8 a) x( k return; 4 `' \( e0 p/ ~" b- N3 a
} + b5 O- C# f7 R4 ^
& T* ?! d' A V$ g8 f! {6 W" {& t// Get a handle to the BOM Items. ( H$ @0 ^3 v* W
var bomItems = results.getRelationships(); + b7 h& H) i: j; ^
var count = bomItems.getItemCount();
; W# F+ U! _( k9 R% v% t, d$ z# H
, E- B0 p$ J' p1 G// Create the results content.
g! I$ p$ }# o, z/ y7 zvar content = "<table border='1'>" +
7 u7 _$ R q: u) c+ B "<tr>" + 5 _% \8 ^! B- O. K
"<td>Part Number</td>" +
, ]% {+ k3 l! I$ P) Z" t) o "<td>Description</td>" +
3 [+ A; B. Q0 \2 f% g& F6 z+ b "<td>Cost</td>" + ' d2 u/ L7 I j: V0 _! ^
"<td>Quantity</td>" +
8 d. Y( ]# _- f9 \ ?) W "</tr>"; 2 w+ n$ m G( c: |1 @* z2 @
- ?3 @6 ?0 c$ M2 [# p
// Iterate over the BOM Items. , Y) U. ^% _! B
for (var i=0; i<count; ++i)
# i2 U% |& g$ W I3 P4 b- u8 A# l{ * T/ @# Q. w0 f% C. d( f1 R. Y
// Get a handle to the relationship Item by index. # I* c- F& m/ c9 T% x7 o" M; m
var bom = bomItems.getItemByIndex(i);
7 F( T% g5 t" F3 `( N9 y// Get a handle to the related Item for this relationship Item.
' O0 H1 C$ |- u I5 [, I var bomPart = bom.getRelatedItem(); + V8 u% C f* m3 g. f' t% [ s) y6 Z
6 @9 q. {3 j+ X7 x1 I$ W5 W content += "<tr>" +
& ]0 I) Q( E* c "<td>" + bomPart.getProperty("item_number") + "</td>" + , z4 P+ A$ V, m7 t3 ?4 O# R
"<td>" + bomPart.getProperty("description") + "</td>" +
% [7 R4 D; n% A! | "<td>" + bomPart.getProperty("cost") + "</td>" + % R* Y+ X# U9 x2 u; `/ @
"<td>" + bom.getProperty("quantity") + "</td>" + 6 ]9 G# N Y l s
"</tr>"; ) s2 m6 }, m3 y- ]
}
& G& {' V( U z* s# p$ t7 L% wreturn content + "</table>";* S& j# k0 N, R b
5 O. A {8 @) o R% l, Q" I2 V5 ]9 E0 b" C& w
- q" z+ {) W2 I, G
/ h( r: _$ N9 ^) _- ZC#
1 |/ G5 k" }* r6 `Innovator innovator = this.newInnovator(); ; D' @, R y( S+ k- }' d# Y
9 x; T0 j9 k* R/ x2 e// Set up the query Item.
! n9 U. Y; q% q: b) T* w& NItem qryItem = this.newItem("Part","get");
! B0 p1 E) M0 s. k. g: nqryItem.setAttribute("select","item_number,description,cost");
! a1 c4 P" B4 I) c' LqryItem.setID(myId);
$ H6 C3 S) X* q; Q * a7 Y, O4 I- l# E6 z5 B
// Add the BOM structure. . G! c! d6 a! C6 |% |8 T- f
Item bomItem = this.newItem("Part BOM","get");
4 f3 y, O% }# ]& S( J7 j# U9 ^) ebomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); , |- O6 C& ]" ]: K% U- h, t- p
qryItem.addRelationship(bomItem); ( p$ \0 k' V" d6 `! H, [
5 a% s; b* Q8 i7 d% f
// Perform the query.
! r2 K- R8 f' E3 J% mItem results = qryItem.apply();
! j% q- ?2 G" [% `3 B/ z
( A( e5 G- R9 t- m7 J// Test for an error.
]1 W8 E0 m* a- C! P* `# L$ qif (results.isError()) { * C; ^& |8 P3 j
return innovator.newError("Item not found: " + results.getErrorDetail()); / S4 o7 U& c1 B
} 5 y9 F) w/ M+ B3 T% U* V
2 N$ e; E; U2 H( [, w" ]
// Get a handle to the BOM Items. ! ~5 u9 \+ t/ f
Item bomItems = results.getRelationships();
, J# _9 b; A% K8 d* aint count = bomItems.getItemCount();
) G5 M# S+ j; I3 r0 Z) q2 `int i; * Q8 m. F. @8 o; r. g
0 k3 E1 S( ^- w1 j% ?+ [; n
// Create the results content. ; @+ ^# R( p7 G
string content = "<table border='1'>" +
3 F' R: X8 I. L4 F. |" n3 d "<tr>" +
, {3 D* l6 D3 }: R "<td>Part Number</td>" +
9 U: W0 \3 Y* x; T$ S/ j$ h) p "<td>Description</td>" + 9 j9 Z P2 c2 G. k7 }8 X* L r. Y
"<td>Cost</td>" +
/ H+ f7 q" t8 M4 g. h "<td>Quantity</td>" + g; s# e3 P1 u0 c/ s
"</tr>"; ; h: f3 G& @# S, j$ I0 v& u# Q
; l- [2 k3 B. G8 h4 }$ @
// Iterate over the BOM Items.
H! o; W5 t3 ^: g cfor (i=0; i<count; ++i) 8 X5 n( C1 e: p4 ]7 p3 w
{ 1 }* L5 S; d" X* f
// Get a handle to the relationship Item by index.
6 X+ l1 s1 V1 H Item bom = bomItems.getItemByIndex(i); # G6 w- D, |3 R) m. j ^9 ?4 W
// Get a handle to the related Item for this relationship Item.
7 l6 r& w& B6 B- T7 b- ~ Item bomPart = bom.getRelatedItem();
' U: Z9 U; t9 o$ X- O1 \ % n4 V. ?4 ]( t& w; _& ~
content += "" +
+ D9 I: e9 E$ ~) c) N3 ^# t: T "<tr>" + 5 o/ K H# D% q- O. A- B
"<td>" + bomPart.getProperty("item_number") + "</td>" +
5 u: Y- e% {+ [0 m "<td>" + bomPart.getProperty("description") + "</td>" + - O! W8 g4 Y& q) @0 K0 T
"<td>" + bomPart.getProperty("cost") + "</td>" +
4 y4 t9 Y; B+ M( b" P2 g "<td>" + bom.getProperty("quantity") + "</td>" + & S3 G7 C6 ?. n' z( Q
"</tr>";
3 |) u" G! o" w$ _, c4 \/ g) P}
8 j, v2 x$ v8 Ocontent += "</table>"; |& \! A6 c4 B8 k6 y
, X& t8 x+ d1 E. W* [return innovator.newResult(content); 1 ?# y) x% J n* q' K9 O
+ j h) } }2 A# j6 T
2 q J) x& X; k+ c6 R& y( Z4 k+ B r
) [ {: e- w/ `6 ~- v* X
$ ?* Q$ D3 F) F1 k" M
- M' y5 B9 c8 x' _9 G* I# E ; U" }% I; |! ]) q9 e/ j
Page 46
# _, U3 M) S% D: t/ \
4 z5 L0 y! [, ^) }$ ECopyright 2007 / b2 Q2 Z, D. I6 D) |9 ~
Aras Corporation.
. k7 Q+ j) Z3 v/ a2 L& j; J& dAll Rights Reserved. 5 s5 p0 b5 w! m* D$ ?
VB.Net
( B8 D+ @+ o U- L0 h( K3 n1 P9 eDim innovator As Innovator = Me.newInnovator()
' o: \9 d9 x1 Y& o q# }+ } V Q
4 x. C& q" B: i& X' \' Set up the query Item.
( B) b# f$ ~2 [5 Y. \7 y9 ]Dim qryItem As Item = Me.newItem("Part","get")
: o: m( u+ N* k$ R' I3 T; U" dqryItem.setAttribute("select","item_number,description,cost") 6 k F, G7 Z" \. Y/ Z2 Y- ~' j
qryItem.setID(myId) - Q5 _ \- V2 w' D# K
" L/ E2 B3 z- Z1 t7 n& g, _' Add the BOM structure. : c9 M: b% e7 r& u
Dim bomItem As Item = Me.newItem("Part BOM","get")
+ ~9 ^- U( a! Y( X JbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 6 t5 p; @5 N2 W: u9 f
qryItem.addRelationship(bomItem)
9 c" [4 C$ N5 T, j 0 m6 {0 Z% ^+ }( |" j: B( v. W
' Perform the query. 4 d% k; G1 U, b' j, ?+ z+ k' E
Dim results As Item = qryItem.apply()
/ x/ B8 ^7 Z( {$ M e6 T9 f 5 \0 U! A# D$ c2 j
' Test for an error. # F: W6 f5 p y* v( v
If results.isError() Then
6 }$ P% n* h/ h# ^ S, a, \6 g Return innovator.newError(results.getErrorDetail()) . [4 F( ~" U2 M0 i: L* D$ ?5 A
End If
) V' D/ Y! O9 m: X * v6 d; {0 K; h) y
' Get a handle to the BOM Items.
8 m7 z& l. \1 t9 B K3 }! wDim bomItems As Item = results.getRelationships() - ~6 M: ?$ n$ V
Dim count As Integer = bomItems.getItemCount() 5 q/ i% C" {3 D
Dim i As Integer
4 {% m% ?2 f; n g; s& X" T$ c
: U, A! G: y2 ]( `+ ^: }' Create the results content. $ {+ S' ]. n2 S9 A9 t! x
Dim content As String = "<table border='1'>" + _ ) c8 S+ [3 A9 W8 ]# }2 Q! P
"<tr>" + _ ; Q2 \, G2 O2 o2 `
"<td>Part Number</td>" + _
' n$ _( d) E5 s "<td>Description</td>" + _
# ?: T/ y% o- N# s6 M "<td>Cost</td>" + _
# d% z2 I) ]4 r- j3 l8 _7 P "<td>Quantity</td>" + _ 1 ? D3 O& g& {$ a% w! M! h s z
"</tr>"
$ ~+ E6 E$ w7 w
% X3 R$ j8 v7 o' Iterate over the BOM Items & U- D a3 |( a3 D) P) T) \
For i = 0 To count - 1
# d) e$ @1 A' T) R7 i" ~' Get a handle to the relationship Item by index. / n, X$ w& X7 B0 b, y
Dim bom As Item = bomItems.getItemByIndex(i) & }0 E0 O% a _, D& X: M% q' h [
0 S( S0 j/ a/ p0 Y' Get a handle to the related Item for this relationship Item. 1 O0 a" T* ^' V9 q: j
Dim bomPart As Item = bom.getRelatedItem() b9 t" q3 E! d+ C8 H5 R
+ k# b! @! _6 g9 ~9 e% i
content += _
& H3 M0 [; g8 ~7 Z5 P8 Y "<tr>" + _
- A. @; H* `5 D "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 6 b/ Q$ T ?/ j' [4 `
"<td>" + bomPart.getProperty("description") + "</td>" + _ 2 g9 B2 e4 O7 S
"<td>" + bomPart.getProperty("cost") + "</td>" + _ " I/ R/ l- ^$ L- l/ Q# m+ \
"<td>" + bom.getProperty("quantity") + "</td>" + _ 7 e. B. @- y: M1 `
"</tr>"
2 r+ ?3 E0 M9 F$ D% h$ ?+ {, HNext
. u6 R8 ?" f( n' B) xcontent += "</table>" * Y' c! F0 v( q+ v
; A7 t( y* e; l( lReturn innovator.newResult(content)
& b3 t: K. h/ ^5 t B; y, H. ]7 X; w) K) U3 }" H2 g- T' r3 l2 Q0 w* R0 x
|
|