|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique : O0 A d5 Y) R
To query for an Item and retrieve its structure you build the query as the structure $ A6 S! [- A: U' n
you want returned. Use the IOM methods to add the relationships you want and
1 J0 A; I6 Y. g* u' [9 Rbuild the structure in the Item. The server will return the structure that follows the # F3 z% s! ]/ T0 ^) C6 E
request structure.
$ n D i$ i5 |( pThis recipe illustrates several related concepts together, which are how to get a set
5 M( _9 v+ Z J8 O3 \% x; \of Items from an Item and how to iterate over the set, plus how to get the related . y: {0 w2 ~& m% E; H
Item from the relationship Item. 4 S( x$ e/ P) p
JavaScript 9 D9 B, X2 b) }5 K
var innovator = this.newInnovator();
# [8 { E I$ v3 r
6 o1 x, I5 I/ ?3 U" w; d/ Z1 n// Set up the query Item.
: x. y. K) K% K6 n% F7 T* Dvar qryItem = this.newItem("Part","get"); * d% l3 w0 w- w1 @0 ^
qryItem.setAttribute("select","item_number,description,cost");
. I; j% |- z4 ?9 T0 l, o$ DqryItem.setID(myId);
8 T# D* T2 b/ W1 q7 q" @4 M
u, Z. D% ^# t// Add the BOM structure. * l$ l- l+ L0 V( \) n
var bomItem = this.newItem("Part BOM","get");
! _% D% c9 G4 H7 `bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 2 M/ D$ U- E( H
qryItem.addRelationship(bomItem);
* j7 s' ^, ]: T5 {: n8 s! L
% K% ^" f+ Z3 K5 _. S4 v; F// Perform the query. 4 w7 Q5 g, y* G' b( l/ i+ x- O
var results = qryItem.apply();
O1 u% q) r) D, n 9 P- r3 R( }+ h f1 L
// Test for an error.
8 v8 f( P0 k0 h: V. ~# Jif (results.isError()) {
. l& F6 v: b4 \1 z& w: v top.aras.AlertError("Item not found: " + results.getErrorDetail());
8 X& J- }9 V( o5 e I6 { return; ( R! p' L$ C$ n+ x9 z
}
) g9 e7 [. V8 t8 l- l$ x
/ ~. f7 N/ a5 l, q: v: A e// Get a handle to the BOM Items.
& |& X9 v- D7 ]var bomItems = results.getRelationships();
8 k& i0 Z- E1 D$ Lvar count = bomItems.getItemCount();
7 V$ X3 a! E. w$ o8 T5 A n2 J
3 `# L$ ]7 Q% |( s0 _// Create the results content.
; x5 [! O# T/ ~var content = "<table border='1'>" +
" {' z* e F7 v3 ?3 f2 A "<tr>" + 8 _; {" _/ H) j, V" `$ G8 ]5 s
"<td>Part Number</td>" +
0 z# n8 D" }4 ` "<td>Description</td>" +
* h7 z/ n4 h" Q4 R# F+ {/ t "<td>Cost</td>" +
" k+ g9 b( \8 E( {, k+ k4 L3 L "<td>Quantity</td>" + # H- k1 f$ ^! \- G. U
"</tr>"; 3 T/ }. j; o, V I* V- G
0 i" ]: _/ c" q( V [2 ^
// Iterate over the BOM Items. 1 M" v2 R$ N0 Y7 [: v, F
for (var i=0; i<count; ++i) & o, X! O& ]+ n0 |
{ ( @' }% f9 \( e: a+ x1 D: g) _/ l
// Get a handle to the relationship Item by index. 3 t( M9 i: A8 v, _2 L# a$ Y4 m
var bom = bomItems.getItemByIndex(i); . J+ _& F- O. S4 s+ @3 U/ t
// Get a handle to the related Item for this relationship Item.
! ]0 Q2 @, X1 Y! y var bomPart = bom.getRelatedItem();
+ S) @6 N0 M/ R$ C/ k6 g
8 U' Q/ r- p- E9 ^ content += "<tr>" +
3 d3 p0 Z8 ?# l r Z "<td>" + bomPart.getProperty("item_number") + "</td>" + 3 [1 }) M# L: W/ g/ S. m
"<td>" + bomPart.getProperty("description") + "</td>" + # g3 Z) v$ f/ j" L4 q. u) `
"<td>" + bomPart.getProperty("cost") + "</td>" +
4 O0 h" r, U3 b( a9 v "<td>" + bom.getProperty("quantity") + "</td>" + 0 o, a# }% y8 R, @, W P# u
"</tr>";
% J3 N9 w# T% A9 D+ M}
: h& r, b) l ?- j% U) G, dreturn content + "</table>";1 w6 M- V' K3 r& F4 F
! Y2 Y# r. `1 Q4 T1 P2 g: ?, h/ o9 n: I) i0 C4 u5 F, D5 |; f
4 Z! ^" }# u6 ~
/ v5 r3 U& v1 e F
C# 4 J$ D( @6 D; \4 c3 l
Innovator innovator = this.newInnovator(); 2 O7 V( }% R- b: Z: u( s6 m2 a
2 x+ g, i5 @4 u( c' {// Set up the query Item.
8 R8 Y. S; ?3 H9 Z3 \) X/ d) EItem qryItem = this.newItem("Part","get");
1 Y3 S- d- c8 r/ n7 s* n ?3 y$ ]! r9 jqryItem.setAttribute("select","item_number,description,cost"); / z, j$ S% `9 Z5 ?
qryItem.setID(myId); 2 j5 P9 {* H- o: K# j$ d" V/ S
, ]' z, p1 B. R4 z// Add the BOM structure.
7 n3 N0 `) B& pItem bomItem = this.newItem("Part BOM","get"); 3 }% J2 Q& D& g! }* d
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
5 ~ s9 H% T5 w# o3 ?qryItem.addRelationship(bomItem); 8 u2 Z: e2 k" r
. ~; ~9 } x" g# [$ O3 }
// Perform the query.
5 J# M9 T- O9 m1 N1 ?( Q. z; s) CItem results = qryItem.apply();
* k* J1 F2 N. n6 v, u 3 N& X: b# c* R3 m' M
// Test for an error.
+ A5 ?; r4 d8 r$ q N& Zif (results.isError()) {
0 c/ T S y3 n% S9 B return innovator.newError("Item not found: " + results.getErrorDetail()); 8 y5 j* v0 x6 L) f2 S
}
+ j- {6 \" [& U% ?5 R% X7 b
$ @4 K: V4 b O2 \. P. \// Get a handle to the BOM Items.
* S/ l: r! C# `, I7 uItem bomItems = results.getRelationships(); 5 P$ D. B4 v5 r& a s
int count = bomItems.getItemCount();
0 a* m( X' I% |! Nint i;
1 L8 n( i1 G' T# T- i0 P ) N* I* M6 r' J4 x. `8 [0 S
// Create the results content.
! ^- `9 \0 W2 tstring content = "<table border='1'>" +
+ Q# ]: |. ^* `- j, F; C$ m "<tr>" +
9 i) X' E4 b1 p0 T- p) E "<td>Part Number</td>" +
; m7 o2 I: N9 h( Q9 z4 B% N "<td>Description</td>" +
1 b6 y" q! \ Z* m$ ? "<td>Cost</td>" + 6 Y8 Z- k% C& H0 f T: ~& t
"<td>Quantity</td>" + : O( ]$ y m- e- ]* g3 z
"</tr>"; , d) S8 B, J( i/ P f
) ?4 N: z' r, E4 }
// Iterate over the BOM Items.
% S$ {3 ?2 `: O5 Z( S0 jfor (i=0; i<count; ++i) ' E9 ?3 Q( ^, Q; G$ d
{ 7 a- I4 o {3 r; z, E
// Get a handle to the relationship Item by index.
7 W/ r( |6 A7 g; A! S, ^ Item bom = bomItems.getItemByIndex(i); 4 q/ L% K- E; R" }, e# ?" |
// Get a handle to the related Item for this relationship Item.
6 ^7 a2 T, v0 K# M: _# [/ `$ I Item bomPart = bom.getRelatedItem(); 2 C. R9 O ]- D3 ` N9 n
1 M7 l0 U$ G2 [/ r" \" e content += "" +
& u. h' z; H1 R "<tr>" +
& q) a4 ~4 G8 l9 c3 e "<td>" + bomPart.getProperty("item_number") + "</td>" + _9 `" r/ b; ]. x# C2 U
"<td>" + bomPart.getProperty("description") + "</td>" +
0 t5 Z$ n: w( s7 |: `8 l "<td>" + bomPart.getProperty("cost") + "</td>" + p4 H2 l# J& R+ z: b4 ~4 Z6 i6 G ?
"<td>" + bom.getProperty("quantity") + "</td>" +
& H* T8 W Q; l! R } "</tr>";
0 C9 S2 z, ^# Z( h0 R} , U" c y$ w9 s" f+ G- G
content += "</table>"; 6 ~5 S; X' T% x- Y" f* Q/ b
/ r# o5 d$ S5 l4 a$ n2 ~
return innovator.newResult(content);
4 s8 D* R$ O4 L
( S/ u0 M" c2 K" L, `, L( J! l% {2 q
" A3 I' ?9 W [% ]3 Q |- v
p4 a4 F" D) {- {; g$ P
! n! ~- H* J o3 f6 D$ B( y
, y' l8 |3 n. [0 O* L% C, i
& Z# ^0 Y( P8 ` Page 46 + S! x* _4 ?: d+ X7 }
, V0 q2 j' H; r: R7 o/ u. TCopyright 2007 9 H6 K+ W/ ]" \, u" L
Aras Corporation.
( i- \5 g2 w8 O, {All Rights Reserved.
' }, X8 Z" \5 f! T: n& Y! a7 h4 FVB.Net
4 Z2 n! J- p, D5 @1 UDim innovator As Innovator = Me.newInnovator() 5 |2 L# ?( x/ J3 P1 `' Y
& I' _% u6 H: g* M' Set up the query Item.
. P- i4 `: z6 z! k$ X0 @# f- k6 [- iDim qryItem As Item = Me.newItem("Part","get")
z+ F: f o! i9 ^5 C* @qryItem.setAttribute("select","item_number,description,cost")
5 b- ~" O4 h* GqryItem.setID(myId) - l. E( L) m; \4 V
2 P, R, f" Z2 z% @1 d9 f' Add the BOM structure. ! g( J1 Y j+ k& a0 ]) Q U( i
Dim bomItem As Item = Me.newItem("Part BOM","get") ! F; G7 X7 U4 ]$ _9 W& Y6 j% P# E
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
$ u$ w- H/ a! c* v0 x. `qryItem.addRelationship(bomItem)
8 b |6 T4 Q9 f9 B1 c
3 a+ @) _2 ^% _6 u! N9 M: C' Perform the query. " m U! ^2 M/ S
Dim results As Item = qryItem.apply()
( Q! ?! d0 \; \0 z6 t; O/ g
( {1 h g& ^$ W. `7 V( J' Test for an error. + a+ R1 ~2 e. p* B6 @
If results.isError() Then
4 t6 H1 K1 {. X) D3 U* R5 \6 X Return innovator.newError(results.getErrorDetail()) . w: C$ i9 N0 |& e/ Q
End If ) K! e) u2 X4 T6 Z
% O: w5 S2 s7 d2 H' Get a handle to the BOM Items. / H8 M5 j7 S+ |" d- `
Dim bomItems As Item = results.getRelationships() ! ]7 c; H3 B7 y# L
Dim count As Integer = bomItems.getItemCount()
. {% b2 A/ X/ t7 {" {# s# tDim i As Integer 5 ^9 p) w4 c+ o$ i
- `/ z) K0 k$ |3 K
' Create the results content. + j- f* q/ I* z4 X* l/ C x7 x0 G- O( a
Dim content As String = "<table border='1'>" + _
- s/ c; ~+ h. l/ w "<tr>" + _
3 j1 [' e# \3 f8 M "<td>Part Number</td>" + _ 5 k; h( n; \7 U6 u& Y
"<td>Description</td>" + _ , I- ?; b1 O9 [1 k
"<td>Cost</td>" + _ 4 g t9 R: R9 A4 q/ y0 I' M* A% p
"<td>Quantity</td>" + _ - i5 i+ v( V( _4 g" K
"</tr>"
: Q+ G, D! {/ A2 M 7 R* E6 O$ E+ s+ y. V4 Q3 m
' Iterate over the BOM Items
* s6 ?* Y' g) a+ o' @7 @+ cFor i = 0 To count - 1
) o' j( |% W9 o$ Z' Get a handle to the relationship Item by index.
% I: T; p5 U7 p2 @0 M! B8 Q Dim bom As Item = bomItems.getItemByIndex(i)
3 l% G. H# T" {! O! l; L( K 2 G) F* v( N% V) V
' Get a handle to the related Item for this relationship Item. 0 M4 w* n) Z* D) k
Dim bomPart As Item = bom.getRelatedItem() - }( Q3 X0 L. {( Q
$ H' N7 }2 X& ~- T$ T+ R- N r& h content += _ 3 L! D5 J/ v3 `: ]' Q3 v
"<tr>" + _
l2 ?3 J# P/ B0 a2 C "<td>" + bomPart.getProperty("item_number") + "</td>" + _
1 d# e; F$ y: }8 z "<td>" + bomPart.getProperty("description") + "</td>" + _
+ Z5 A' o1 p9 |, D% x& P "<td>" + bomPart.getProperty("cost") + "</td>" + _
9 s; `; g, h5 l9 K6 k "<td>" + bom.getProperty("quantity") + "</td>" + _
( s2 c) ?% M( \ H4 Q* B "</tr>"
8 L. O! C& u$ H1 |+ _' N; y6 f4 tNext
; N7 s/ m2 |! Qcontent += "</table>"
6 [3 v( C: E$ Z Y& a ' |4 L. v: V) r
Return innovator.newResult(content) 1 s: A( N0 D+ y0 O6 k5 D
+ V A, {3 I6 d8 D9 i! W! m |
|