|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
3 @ H1 y" g7 r2 d* N( ETo query for an Item and retrieve its structure you build the query as the structure ! i3 \3 x4 e2 j$ A6 k2 r
you want returned. Use the IOM methods to add the relationships you want and 6 j' I2 W8 w9 C" a1 H+ c
build the structure in the Item. The server will return the structure that follows the , m" Q' f9 B& t
request structure.
% ~1 ~) s; H/ U/ U. P, hThis recipe illustrates several related concepts together, which are how to get a set * v- i" Q$ \4 z, |" S& I* j" a
of Items from an Item and how to iterate over the set, plus how to get the related
$ o& _. y! V0 t1 y+ A' QItem from the relationship Item. # O J# V H* @7 y
JavaScript + H# R" p D. E+ F. k
var innovator = this.newInnovator();
. C3 ^+ m- \6 p" N2 |, b5 [: K# b
/ K: E' z1 Z. M! u6 S// Set up the query Item.
3 |' p: a, c" T# }) |var qryItem = this.newItem("Part","get"); ' t9 b' `& H: g1 t: X2 k; {4 k5 L
qryItem.setAttribute("select","item_number,description,cost"); 0 L: v. K; W2 t0 E
qryItem.setID(myId); ( ~: I0 n2 {: D
% {. r k+ J. C3 B9 q1 n" p1 ]// Add the BOM structure.
$ C1 {! {) S; c; Wvar bomItem = this.newItem("Part BOM","get"); * J! Z; ]9 M" T* A' H, n0 F7 ?
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
# m/ I! D1 z' n- f* `: L8 }* L1 WqryItem.addRelationship(bomItem);
D( z& v/ F7 P/ \: d! a; y x# m4 \5 Y% P1 \
// Perform the query. 2 o+ r$ N% G. m7 N( D
var results = qryItem.apply();
+ x& P/ c3 d8 r- r: h: K% @* c & `" |9 [8 F4 ]% m
// Test for an error.
) j' ~2 g. p) ]$ r0 Pif (results.isError()) { 8 G5 W7 B; n: w9 {7 }
top.aras.AlertError("Item not found: " + results.getErrorDetail());
8 |9 D+ Y4 l5 l' K2 M: @ T return;
' H' I: K& M; z} 9 K1 S& m: d. t8 e: A5 s
% j" R! c! ~# s0 t' }: _// Get a handle to the BOM Items.
0 n" n) I$ f6 F2 `, t, Z# Zvar bomItems = results.getRelationships();
& X! L0 w/ C. P2 _7 pvar count = bomItems.getItemCount();
3 }. \4 H5 p( J
5 v1 i8 Q0 {7 R- d7 O// Create the results content. * X2 b4 j5 s1 _$ `) q
var content = "<table border='1'>" + / C* U( p: O4 {7 q$ t
"<tr>" + 7 y. I8 O* A# }; k+ j7 e7 Q8 {
"<td>Part Number</td>" + 0 G7 X) Y* Y* ?! K0 g+ v. x
"<td>Description</td>" +
2 ^ V, c8 Y3 f- J7 Y8 O2 V) g ]3 G "<td>Cost</td>" + 8 A) k* m1 v' t1 d: C' _
"<td>Quantity</td>" + # f7 k' m: b* B+ r8 W* A
"</tr>";
6 p7 R: x# l7 T% Y3 K$ } . |7 O$ k8 x; M" ]) U. \/ m
// Iterate over the BOM Items.
% R+ T* D& q5 ], m) @! efor (var i=0; i<count; ++i)
! d, M! J5 M8 k# B6 B; }* o7 S{ - Z% J& l/ |4 {: B
// Get a handle to the relationship Item by index. ! ~. t7 J( {9 ~; ~1 C5 a
var bom = bomItems.getItemByIndex(i);
$ p$ i8 A& \. S4 M! C8 e% g6 L// Get a handle to the related Item for this relationship Item. 3 c( h5 ^9 P/ S2 [
var bomPart = bom.getRelatedItem(); , V0 m) W+ R1 w: K$ a
) m- s4 h! Q" ?+ K& b' v" Y: J content += "<tr>" +
* N7 `% u0 q% R5 K+ v "<td>" + bomPart.getProperty("item_number") + "</td>" + ! @: d/ R9 `7 K$ Y4 z% W( R
"<td>" + bomPart.getProperty("description") + "</td>" +
& A# n, B7 A' C0 @2 n% x3 L5 U2 N: n "<td>" + bomPart.getProperty("cost") + "</td>" + 0 x }! ]. q* K! w
"<td>" + bom.getProperty("quantity") + "</td>" + ) a4 ?( m) E+ H+ T5 ?$ _
"</tr>"; 3 c* M8 v, u5 q; a6 y
} - `4 x$ G# ?9 M
return content + "</table>";8 V5 J& B0 m) w$ Z3 r( _( e$ ~; [5 y
: f) [+ ^& w7 o) d+ v, `) [0 I$ \
" U% y5 E3 u7 g6 x; o' h, \; s; Y u. C" g7 C( V$ [
8 P- R: b H6 _9 PC# 1 P& e8 N0 n( K. ~
Innovator innovator = this.newInnovator(); ~% T b5 A7 _% E+ h# |) N' W" @
6 Q, j* U7 o @// Set up the query Item.
; ?( u) H" W8 aItem qryItem = this.newItem("Part","get");
$ a {0 k% L. V4 m8 ]qryItem.setAttribute("select","item_number,description,cost");
" b: h, K/ s5 ]% ?qryItem.setID(myId); 8 ^% A, B! M- l. d' Z2 V% J
: V# L) J. G9 a7 A! f9 q
// Add the BOM structure.
. _; B; r- q7 @: pItem bomItem = this.newItem("Part BOM","get");
; k" S# r' o4 z5 e/ JbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 0 R0 @0 I- }- e( r, n+ ~% `
qryItem.addRelationship(bomItem);
2 h. |8 L$ ]" b! S! }+ \
8 T8 r' y0 D8 v5 Y1 {2 F3 X( b// Perform the query.
( G* Q7 n) Q$ k% kItem results = qryItem.apply(); ( s+ q) y, I/ k, z/ d2 ?0 m) }9 a
5 c7 E( v- j; u7 E// Test for an error. ' `- U+ k" l1 p6 h5 A5 S
if (results.isError()) { ( q2 b3 O' u, _& s0 n
return innovator.newError("Item not found: " + results.getErrorDetail());
- x8 N+ Q3 |+ T/ A$ V1 t9 }8 M} + P, [2 a' c% K( U, t& n1 E
$ [! l$ X+ J# r3 _: O
// Get a handle to the BOM Items. 8 [1 n( t* u1 o
Item bomItems = results.getRelationships(); 6 u" c& |; o5 h8 _+ g
int count = bomItems.getItemCount();
" S5 K }" p0 J/ Zint i;
- D; x( q# R/ W: A ( b, p' i0 k5 `0 V9 d+ j
// Create the results content. ) C; ?7 G9 t9 a
string content = "<table border='1'>" +
, f5 u* ~: Z1 T "<tr>" + 0 @5 N* o6 H0 S1 @
"<td>Part Number</td>" +
' W; H7 @( w \6 h "<td>Description</td>" +
1 B$ `! H. w0 `* K; A- d7 R+ s "<td>Cost</td>" +
; t. k* h' C: ^ ~! e "<td>Quantity</td>" + # L) {: Z+ L4 V1 ~) k8 y
"</tr>";
! ?7 I/ H2 u4 L
/ k8 c- N; E# \: h* u8 l// Iterate over the BOM Items. $ n. Q- O% a) Z+ d* V9 F
for (i=0; i<count; ++i) - I0 }+ U \7 H
{ , G, D; g) F" x D2 ~# j
// Get a handle to the relationship Item by index. 8 K B% T6 d& K [) D
Item bom = bomItems.getItemByIndex(i); : f! I' j7 i% N1 d, t3 m* ^
// Get a handle to the related Item for this relationship Item.
: d0 o# R% F& H- e: p# F Item bomPart = bom.getRelatedItem();
$ ]+ e, G. A0 c7 M8 j( I
$ }3 F5 X% D; u% C; w content += "" +
; T) \, G! _( ]' A. m "<tr>" +
, y, J" o9 W L! B& c4 a "<td>" + bomPart.getProperty("item_number") + "</td>" + ; \$ G& I+ l. y/ E
"<td>" + bomPart.getProperty("description") + "</td>" +
- e; z, S9 \8 y% A: Q0 b+ F "<td>" + bomPart.getProperty("cost") + "</td>" + 8 t: e$ [1 S8 w, m& v
"<td>" + bom.getProperty("quantity") + "</td>" +
8 l! R+ w b+ [! |# t @ "</tr>"; ; h! ?) n* }9 p
}
( Z3 G) T; j7 ycontent += "</table>"; 2 {" H2 {! n% f" c# d8 _" {) g
# h) N( l9 ~& d6 Z/ ]2 P2 y
return innovator.newResult(content); 3 p% }8 ?$ n+ a( K% P" Q6 U' q
" e( `4 A- m' a" D* h9 w& S: l; T% X$ N( E8 R2 x* d
- D" P3 i8 n1 x, d; n
( a: B) C5 ~9 w; z+ h
9 i J/ S- ?) s% n$ Q5 g, \- p" H8 O5 |
& l0 H% F! [0 \$ T Page 46 $ V% L" u" X% T. O- @7 S
* A, S& E6 u2 [0 B
Copyright 2007
2 y& ]0 N% m+ x- t: zAras Corporation. 3 ]9 E9 \% \) e6 u
All Rights Reserved. % n( ], K6 d% t( T& N1 T# c4 d
VB.Net $ p% N5 t/ g0 W0 J- l
Dim innovator As Innovator = Me.newInnovator() " T) {" Z+ h+ Z
8 U, E! [! t4 z. e
' Set up the query Item.
; s8 n2 |' q' S* N* i( \$ qDim qryItem As Item = Me.newItem("Part","get") 8 p+ O6 _% k. p5 n) u
qryItem.setAttribute("select","item_number,description,cost")
; _ z$ \0 l/ K1 [8 z/ _+ g4 rqryItem.setID(myId)
3 R8 x" y1 j+ A9 y& B5 U; [4 o 3 C8 U2 q) z* ?& @" V
' Add the BOM structure.
2 T" j6 Q, J+ Q6 W4 WDim bomItem As Item = Me.newItem("Part BOM","get")
) k+ e) P* L$ jbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
p7 |9 C, i! }2 \9 F5 e$ kqryItem.addRelationship(bomItem)
% }/ y( v9 x, [8 u7 Q. W' t/ @9 P, W! L 6 q3 G2 b1 t# W4 }3 p
' Perform the query. 3 A4 v+ `( ?2 {0 `2 J" y$ [/ u
Dim results As Item = qryItem.apply()
1 ~: O8 ?. O4 A6 J y* V 6 | M' F; V3 [, d6 R; [6 p, T
' Test for an error. # A' r% i* h4 |* w# h9 q4 i
If results.isError() Then
! y9 _* i& g) f" e- X Return innovator.newError(results.getErrorDetail()) ( N; [, k$ ?5 k5 F! M
End If ( i; E4 ~, x) k! _( h; F- `
+ m# c" c' @ x: ~ h/ R' Get a handle to the BOM Items. 9 d$ x: j. E v8 F6 {* S- H0 Z0 g
Dim bomItems As Item = results.getRelationships() ) ` f" Q# s" \) m% |
Dim count As Integer = bomItems.getItemCount()
; ^* V1 F( D3 U% z* R- t, N5 UDim i As Integer
& }! v# ~8 W. p 2 L2 b! N8 N7 u0 q$ V) Q
' Create the results content. , V0 O- {4 e1 H( e
Dim content As String = "<table border='1'>" + _
& @/ T7 g, {; M% V2 K "<tr>" + _ * n7 f% [: `- H/ `3 n+ M
"<td>Part Number</td>" + _ $ P! M$ b v. U: k8 l9 }$ f. h
"<td>Description</td>" + _
( a! S) E! R$ a "<td>Cost</td>" + _
7 t0 M* |+ l6 N a ~! K "<td>Quantity</td>" + _
' A9 W( D0 q- n! _7 J: d "</tr>"
# l6 W6 g F+ r! U/ [% I" w 2 C1 Q' ]. O. M
' Iterate over the BOM Items
: J/ I4 N+ o+ V: SFor i = 0 To count - 1 " {* y# G) b8 W
' Get a handle to the relationship Item by index. 6 X. x3 d0 Z) j: H, L( |" ^: I
Dim bom As Item = bomItems.getItemByIndex(i)
: Z5 L1 d) D$ \% ^+ @% O( Q! Y0 I - r0 R& j- r7 F0 g' x1 f+ C
' Get a handle to the related Item for this relationship Item.
/ F/ D2 J( y2 ] Dim bomPart As Item = bom.getRelatedItem() - g5 F2 H j a, I" e
; p) @+ }, D: D }
content += _ ' e/ |2 k/ F! s$ o) u; D
"<tr>" + _
/ ]+ g' x9 E* U0 n& {: T: w4 i "<td>" + bomPart.getProperty("item_number") + "</td>" + _
' B0 U( f8 o$ l# h( V "<td>" + bomPart.getProperty("description") + "</td>" + _ - X% E0 g% e0 a8 f! {
"<td>" + bomPart.getProperty("cost") + "</td>" + _ 4 k5 |9 M/ `& O$ H( _1 R4 B7 o3 r
"<td>" + bom.getProperty("quantity") + "</td>" + _
: g6 k( l7 F8 G5 K/ `& e& d "</tr>" ' ~) s7 B0 N( W0 z- O |/ a, U' r
Next
: U/ d( l% v) V9 `+ Ycontent += "</table>"
. Y& q0 a& ]. @- g0 j: u + d! O9 [3 F& i" e1 R
Return innovator.newResult(content) ! X( l/ Z. ~4 b. w2 ]# ]. ^1 y
" S. ^9 m4 M/ `/ y4 m7 \. S3 ^' a |
|