|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique . C2 l* X; }" r0 D& k2 J
To query for an Item and retrieve its structure you build the query as the structure
# f4 j- `) w$ l/ Byou want returned. Use the IOM methods to add the relationships you want and
- ?+ t! O) B( [6 a" Jbuild the structure in the Item. The server will return the structure that follows the
0 t: D' ]0 f qrequest structure.
0 Y2 h7 V$ N9 t3 Q$ f7 A) rThis recipe illustrates several related concepts together, which are how to get a set ; w; ~! T" N6 [3 g
of Items from an Item and how to iterate over the set, plus how to get the related
6 B3 a7 a( L! q# iItem from the relationship Item.
7 t5 h* m# \- ~$ p5 k7 D2 w/ OJavaScript ! \+ X6 h! I/ \
var innovator = this.newInnovator(); & g* R* Z9 j# H' Y+ d
# r5 T4 I E5 T! b" J
// Set up the query Item.
& h: r" g( W+ N+ S& S9 ~var qryItem = this.newItem("Part","get");
$ t! R/ x. }+ r$ y3 HqryItem.setAttribute("select","item_number,description,cost"); . T- A8 Z9 G7 q; V
qryItem.setID(myId);
) d7 |0 S V: j% @6 K. [ 2 S4 T B: f+ @6 W5 x# J" S
// Add the BOM structure.
# f; t( z/ x) b2 U8 Z) N2 b1 {8 k ^var bomItem = this.newItem("Part BOM","get");
$ n6 B6 k/ ?+ w+ K. }bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 4 D7 f+ S8 t9 \" o$ C8 ]! T
qryItem.addRelationship(bomItem);
& j9 m: [( e5 t' K$ _+ l! C& O) g* G0 o % Q2 V- t K9 s5 R
// Perform the query.
: V& o7 W* Z, H1 d9 lvar results = qryItem.apply(); ( i8 ?. X: v$ E$ H! @* x
7 p9 H0 ]( L% n5 @+ K! R4 M
// Test for an error.
# C5 q5 e y7 d( r) Mif (results.isError()) {
* I: A$ ^+ G. _& ?% _ top.aras.AlertError("Item not found: " + results.getErrorDetail()); 4 B3 k2 Z% t) p7 h. T- t
return; , e8 r( i1 A- b# s
}
* i8 w* S" O: J' }# n' S4 r3 ?
1 Y3 p5 T: u8 j9 [/ {// Get a handle to the BOM Items. 7 W, A2 Q& X, M/ }/ c( M
var bomItems = results.getRelationships(); 2 `7 F# z# R5 |( j i# m
var count = bomItems.getItemCount();
) }6 ^0 ^ T$ j0 w j
+ E9 f) n% l6 `; S// Create the results content. # V- z/ B% t, {6 f
var content = "<table border='1'>" + , t6 E& u) r: Y0 U8 M- \
"<tr>" +
! z f8 N* D( ~4 n0 J, v "<td>Part Number</td>" +
& G5 k( V7 w8 L2 U' `) c% k "<td>Description</td>" +
" g2 s5 Y3 C: l! x" e5 Y "<td>Cost</td>" +
2 n( t. T0 q3 r- ^! _& R "<td>Quantity</td>" + . w& c2 i5 p: s& X9 h" a
"</tr>";
' Q% O8 X* a, }
9 K; V4 B+ ^3 Q5 ]3 y9 P// Iterate over the BOM Items.
& j8 |1 m" d) ?% P) afor (var i=0; i<count; ++i)
( G0 \6 i* ~1 d7 x2 k2 W! Y2 a: Z{ ! Q ?7 r. w) k
// Get a handle to the relationship Item by index. & W9 t% F4 j9 \5 H6 B8 ]9 |
var bom = bomItems.getItemByIndex(i); 4 T1 P/ K; I/ I$ U
// Get a handle to the related Item for this relationship Item. ; J/ ~; c0 ?7 d
var bomPart = bom.getRelatedItem();
3 b3 E1 ?9 D5 B7 s( E% O) V . M5 L. q' S9 v7 W1 O. @
content += "<tr>" + 8 n! m# s5 b8 N, }1 K/ n1 Z8 R& A5 E
"<td>" + bomPart.getProperty("item_number") + "</td>" + 1 w/ U! _4 ^% _
"<td>" + bomPart.getProperty("description") + "</td>" +
8 F& y/ W( S; X, o& Z5 [/ W( r "<td>" + bomPart.getProperty("cost") + "</td>" + / d0 d% w; g" H3 j! n; q* W
"<td>" + bom.getProperty("quantity") + "</td>" + 7 T7 V# ~& Z4 h6 B4 |/ q
"</tr>";
# ]0 A* m, A+ x+ @: A2 `} 6 M9 U8 l; y$ h1 l+ l& {, V
return content + "</table>";
* S9 u+ [/ M* @+ t6 E' Q3 X& R' x* i2 {* L! ~' k
3 C8 K/ w/ T& V; S# B6 M2 ~ P7 \3 u |9 F7 C
5 R6 X3 d9 q& ?
C# 3 h: A5 v( x b, D
Innovator innovator = this.newInnovator();
6 @' w9 w C9 y6 h. E4 t! s ; C# O; h+ [1 z; ~: o" [) {% J
// Set up the query Item.
+ W' s" H4 D1 S; A6 sItem qryItem = this.newItem("Part","get");
) i, l2 _" H E$ NqryItem.setAttribute("select","item_number,description,cost"); h: T% @+ n0 v* Q
qryItem.setID(myId);
4 E( ]6 e9 ]% y# L( u5 o 3 a6 e8 ?6 \. {+ ]: O* Y
// Add the BOM structure.
; r" R( O: G+ Y% FItem bomItem = this.newItem("Part BOM","get"); 3 i/ ^, ^5 w/ ^8 V8 V% }& C
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
+ U+ H) N: |* y6 L3 V) D4 v$ lqryItem.addRelationship(bomItem);
. s* ]3 `9 M5 v; h; z, G 6 B' D7 q1 i& c2 a
// Perform the query. ) x1 i; i' l1 E3 X2 V- Z
Item results = qryItem.apply();
' B: {* {* l& z' W
! z, n# H! z0 G; u) I' t// Test for an error.
2 S9 |* o- D5 m+ |* U" y( ?# \0 K+ _if (results.isError()) { 0 f r1 M: E+ n( k8 Z. R
return innovator.newError("Item not found: " + results.getErrorDetail()); & F" ]* R- X" e# u! D' [
}
+ ^3 _! ?6 \" @# X& | ! h+ O; O- b$ |& A) X7 `
// Get a handle to the BOM Items.
l: _6 T* B2 x) ]' Y; nItem bomItems = results.getRelationships(); # N, Z7 W- j) O' l" H, m
int count = bomItems.getItemCount();
, o; G3 n' h3 ^+ w* t+ l( nint i;
8 T/ N. Q s7 Y8 E3 v9 x& r : @0 r# F4 N! Q1 `, K
// Create the results content.
: f7 v. Y6 U* B9 ~string content = "<table border='1'>" +
1 s0 Z# @) I' V3 w( L "<tr>" +
& W7 X0 ?6 y7 D+ \9 f8 p) n6 i: B "<td>Part Number</td>" +
: F; a6 ]/ Q$ A7 D8 X "<td>Description</td>" +
& }: \! q! y* d3 y0 J "<td>Cost</td>" +
' v6 y+ `: |) Y "<td>Quantity</td>" + ) s8 h" w" }2 g
"</tr>"; $ @9 v E% t% g4 d8 ~
% B2 C4 A, W! e0 W Y9 O
// Iterate over the BOM Items.
# t4 J( O( X6 Jfor (i=0; i<count; ++i)
- ~- E8 A# a, m! a{
3 ?- Q& e" N' Q9 f9 }// Get a handle to the relationship Item by index. ' r) G! L) y. p& R. \
Item bom = bomItems.getItemByIndex(i);
0 I8 l, y# @' `+ U5 y: |// Get a handle to the related Item for this relationship Item. 7 j* R. b0 l0 A% ]4 B! u
Item bomPart = bom.getRelatedItem(); 5 x; @' b+ ?: x( b" @
: V$ {9 R( X( x: C& a/ K/ w
content += "" + / ]& \8 J, a9 t& E2 m0 ~
"<tr>" + * M2 _/ [' r: S6 p( L2 F" C
"<td>" + bomPart.getProperty("item_number") + "</td>" +
' ?1 `, W2 M ~( `9 c "<td>" + bomPart.getProperty("description") + "</td>" +
# ]; P0 e( e4 Q3 P "<td>" + bomPart.getProperty("cost") + "</td>" + ! g9 L/ T. Q0 q2 V$ \
"<td>" + bom.getProperty("quantity") + "</td>" + ( n0 J2 g7 f, F! L, |
"</tr>"; ; S/ x: V- x: z) \( O
} ' O9 L1 G6 q# U, F! x, s o7 Q( A
content += "</table>"; ( u7 H$ ]+ C5 }' b4 h% A) U8 [
/ C# o: U5 ~0 b" ]. Q
return innovator.newResult(content);
% T* @ m, e [& ? ~+ i1 U# R7 T) Y$ t% l( u) P
4 O6 j- D5 N$ W5 o* ?/ O4 g* v- s7 z. T8 z
! u) l- Z: T0 `- [1 ?2 i& A( F0 e
( i/ S1 d/ i) z, v: l: v
1 k6 h1 ]) S4 f- s& C- l$ ] 1 {, X# `) F& L
Page 46 $ G& R2 \8 N: Q9 \/ J- l6 I4 D
- n0 W8 i2 G3 nCopyright 2007
_ `8 _1 l3 v# o P5 ]( v) \. h; @Aras Corporation.
" ^& _8 B) g0 s+ UAll Rights Reserved. 1 C5 f! C9 O0 e& t* X5 N
VB.Net * F# h: N- i: [* Z7 b
Dim innovator As Innovator = Me.newInnovator() $ w+ T2 T/ u3 Y+ z' J
2 h0 Z; @7 p( x1 {; e
' Set up the query Item. + l3 _9 e5 l0 ^) u: A. e6 L; a
Dim qryItem As Item = Me.newItem("Part","get")
1 Q4 ~( a/ e) k- ~1 y0 b" n3 h lqryItem.setAttribute("select","item_number,description,cost") 0 {7 o: h: r- j' B6 e& G6 \
qryItem.setID(myId)
7 N0 q6 ? u" m
" b( W( J# y/ V r/ c& f' Add the BOM structure.
# [, y) t7 ? t* t4 W8 A, MDim bomItem As Item = Me.newItem("Part BOM","get")
5 S* U& ?5 [- G0 n% \: V- V# `7 [bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 8 c# ~" B7 J! [8 y
qryItem.addRelationship(bomItem)
8 f( n, a- ^; h( N% m! [ - k! v8 I9 k# H
' Perform the query. ! i- c* q8 N7 Q
Dim results As Item = qryItem.apply() " L. Q6 ~ L8 {+ z# ?9 `' I) M
3 S" b7 E- L8 _+ |% K' m$ e
' Test for an error. N& w% N% p, |
If results.isError() Then 4 {) v& ~- T P7 H& ]& N9 P
Return innovator.newError(results.getErrorDetail())
7 R7 ~- O3 m1 Q( \2 M* F$ V# aEnd If
( j9 P! ~; p' @3 M9 x. k1 B 7 r, |( i- B& T
' Get a handle to the BOM Items. ' B$ g! o$ c1 k, G- ?: g2 f) E
Dim bomItems As Item = results.getRelationships() & e8 `! V8 t5 X1 z* W/ N w
Dim count As Integer = bomItems.getItemCount() 7 _+ D1 z% w$ I
Dim i As Integer
3 F5 r+ I4 i' a' d U: c. C: r- {! F 7 i% G V) E' ]% f8 X4 i
' Create the results content. 1 q6 L! p; @" [) L
Dim content As String = "<table border='1'>" + _ # t8 w& j8 C, F
"<tr>" + _
! c, [: e* o0 ^ "<td>Part Number</td>" + _
. t6 t. ?) @4 Q: p+ D, J "<td>Description</td>" + _ * H* Z0 _' J2 k: V, c+ O
"<td>Cost</td>" + _ % V$ B, R* Y6 Q9 Q- ]$ v2 m4 l
"<td>Quantity</td>" + _
$ _2 |6 S; U1 U6 P "</tr>"
" x b4 q% F; y! P4 d' g/ Z7 J' t 5 L" Q0 C+ K- [9 n4 A9 n
' Iterate over the BOM Items
5 D% u8 U; E) x* C( S- TFor i = 0 To count - 1 " P: ?. _9 A/ k* a i
' Get a handle to the relationship Item by index. * U& X4 e0 V- G5 ?$ k- D) ~
Dim bom As Item = bomItems.getItemByIndex(i) 2 r: i: G, s/ l! a$ W
g% C( z/ f' h6 p/ J
' Get a handle to the related Item for this relationship Item. 3 T+ O7 o% E1 e( g2 ]. U6 t
Dim bomPart As Item = bom.getRelatedItem()
4 E# ^5 n! ?2 o- k- T5 z l
0 M* x. C G, i content += _ % P# E( q4 W- G5 i# V' L3 k
"<tr>" + _ 4 z7 P; t* R* K* r1 a
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
) ]# d9 I( ]2 v2 d) Q1 Z "<td>" + bomPart.getProperty("description") + "</td>" + _ " }5 t" s( n; O) t# V/ y
"<td>" + bomPart.getProperty("cost") + "</td>" + _
% a! O6 e4 ?( o) F; G, a3 D7 W "<td>" + bom.getProperty("quantity") + "</td>" + _ ; Q$ F; J: n. z! \1 w# k
"</tr>"
& N' y& G/ u7 `' G- @' H' mNext
2 g$ B9 o( P/ U' h4 C% j$ u) w1 @content += "</table>"
+ j! x4 j% I( v/ Z4 c * k% e5 J$ _- c( l$ L+ C
Return innovator.newResult(content)
|5 e1 [8 \. O' c) r1 [5 @7 n0 L- j5 F; e, ^
|
|