|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ! n! C! _/ I& L" s
To query for an Item and retrieve its structure you build the query as the structure
' s4 X7 g4 b- v2 Qyou want returned. Use the IOM methods to add the relationships you want and
, ^4 F2 l7 J/ q' j& P9 C2 C2 Pbuild the structure in the Item. The server will return the structure that follows the
- u0 x- _( S- {4 i6 Z2 Hrequest structure.
) Y2 R: K) J G& d( p/ A5 _This recipe illustrates several related concepts together, which are how to get a set 7 B2 N; C* S$ f* E, ^; m% i
of Items from an Item and how to iterate over the set, plus how to get the related
: U5 R2 F) T7 yItem from the relationship Item. * `4 R" k! K8 ~" q. x& Y) t9 ?
JavaScript 0 C1 X( {$ t8 m. I% b- p. l
var innovator = this.newInnovator();
o8 G8 F2 K* a1 g
5 A+ p! C( z5 l, q7 O F$ {// Set up the query Item. ' g( ~) a/ I6 Y* N# c
var qryItem = this.newItem("Part","get"); 9 |: Y9 o2 ^2 {$ Q \
qryItem.setAttribute("select","item_number,description,cost");
; b5 e& p* m: D+ }qryItem.setID(myId); 0 t4 |1 d# |9 r Z( K) ?
& L, J" d4 e* J
// Add the BOM structure. 8 d1 O9 S$ N9 P2 w: @* p
var bomItem = this.newItem("Part BOM","get"); - G5 j5 v" R4 D) u' S/ f
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
2 o7 @( w+ y: y8 e; V! i7 cqryItem.addRelationship(bomItem);
% ]% Q. k* V- g1 c) @
2 {+ v6 `! x9 H// Perform the query. # D' O- O; x, v, m! C
var results = qryItem.apply();
* x8 l" A% T# h) l. ~( j8 u. ]+ Y / ?8 |8 J' B4 u
// Test for an error.
6 b( k# Y- s+ H# z/ G: e( Hif (results.isError()) { . ^% f( {& j5 b$ `" a8 X7 w
top.aras.AlertError("Item not found: " + results.getErrorDetail()); 8 |. s% g! Y( q" F/ W
return;
& n$ }8 C; X9 `# Y' a% Y" Q} " }. o& _1 Y$ y0 S
5 ^) G/ |# H( U( u) N) Y/ u
// Get a handle to the BOM Items.
/ s4 y, t( d% f* V. fvar bomItems = results.getRelationships(); * Y! Y# v: y- O' I6 P
var count = bomItems.getItemCount(); % z( r- a& o3 @, ?' b
, @. s6 s1 t$ }7 ?6 B9 ?// Create the results content.
" i+ R- e5 `1 ?var content = "<table border='1'>" + , d+ s' }+ D2 l: w
"<tr>" +
, f4 a$ |% W1 q "<td>Part Number</td>" +
. N" d0 c6 R& t" b5 } "<td>Description</td>" + 6 A* Y- M, q2 [
"<td>Cost</td>" +
- ^6 R4 p$ C3 {# [ "<td>Quantity</td>" + " b& e' d' i3 S3 Y: X; e& `
"</tr>";
. e v% T S9 K# Z9 L
$ L$ L& s$ |7 h. C9 f4 {- K// Iterate over the BOM Items.
! }5 \: J4 r, C/ C) j4 ffor (var i=0; i<count; ++i)
P' _+ N$ K5 w O4 v: @{ # k8 m( y0 m* K
// Get a handle to the relationship Item by index.
- l: Y" p x6 \ var bom = bomItems.getItemByIndex(i); , g& m- H- |# z2 C5 `% z5 C7 u
// Get a handle to the related Item for this relationship Item.
* ]' G4 ]5 f; M var bomPart = bom.getRelatedItem(); 2 f( h; R0 z$ K/ e- `' a/ O
" N( k& N& X/ w2 u content += "<tr>" +
* I$ ^, V+ P5 R& Z% k; _ "<td>" + bomPart.getProperty("item_number") + "</td>" + & S; [4 w$ I, q3 Q( u
"<td>" + bomPart.getProperty("description") + "</td>" + $ M# K+ ?0 C! t& g% Z2 f
"<td>" + bomPart.getProperty("cost") + "</td>" +
$ x0 g5 U: b) B8 T& n; Q1 _ "<td>" + bom.getProperty("quantity") + "</td>" +
7 h2 [" I5 X+ C' `$ F( S8 z" F! ? "</tr>"; * {; W' h- s9 x* v7 e d
} ! e- ~+ E9 G# W0 O+ C! y9 `1 t4 \
return content + "</table>";! F6 n w" W. q Q
! s& r y$ [% a# N! I7 s+ E+ x
; C6 Z% G' | b; q/ f/ @8 i) s' C! W8 R6 u7 A
! e) W9 E' z0 [/ e& r. I0 T: n. PC# 7 i, P- z; Q/ J0 J
Innovator innovator = this.newInnovator(); ' c1 F" B$ M4 L) ~2 o6 C$ R
6 N% X o* O, f7 w( E- b. X
// Set up the query Item.
+ n+ U* s' H: _" B) gItem qryItem = this.newItem("Part","get"); 8 H; p2 X1 _5 j! b, V- X q
qryItem.setAttribute("select","item_number,description,cost");
' u* [- \: Q8 f2 T( L8 y; ^1 ?* mqryItem.setID(myId); 7 t0 K( R. g4 S* B' W' s9 i; E
& u' `5 ? u% o
// Add the BOM structure. ! \, d M' ~6 [! V
Item bomItem = this.newItem("Part BOM","get"); 4 q4 a1 G: A/ B J! ~5 `! q+ F. h
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
/ X: p; a1 q2 M3 E1 wqryItem.addRelationship(bomItem);
j/ _1 y" ?, L' m% A; R; g 6 p- E1 w" W3 ^% D; Y2 O& @% X1 M
// Perform the query.
, t: s) m [1 d: H$ J" V3 fItem results = qryItem.apply(); + D' E D7 a4 v% s1 X$ {
1 C9 c/ }1 ~# a0 D# L
// Test for an error. V. s h y- {5 Z
if (results.isError()) { - R! f4 z6 M. a5 H0 E
return innovator.newError("Item not found: " + results.getErrorDetail());
# i/ C. z% C8 V1 [: [$ w' L} - K C: I |' C2 V J6 @: D9 ~
, e9 Y( J& E- a- c3 |// Get a handle to the BOM Items.
. B" K) A: d+ z' k% M$ BItem bomItems = results.getRelationships(); $ o; u7 m3 v, ? o
int count = bomItems.getItemCount(); / k. X9 s3 O8 b& m' o
int i;
6 Q- s! u! @3 T
0 \9 u+ `+ M5 e/ i& |: G// Create the results content. ; ?$ H) Y4 K/ H; W5 f' R) z" Q+ e
string content = "<table border='1'>" +
" K/ W1 W& v8 F7 u "<tr>" +
( E9 R* [/ ?/ z: w "<td>Part Number</td>" + % D' G! Q$ c$ }) t
"<td>Description</td>" + 8 k( n5 ?- A) r
"<td>Cost</td>" +
+ F4 m# q' k" H/ j "<td>Quantity</td>" + 1 x" u5 T2 p+ c! Z( E
"</tr>"; ' v1 s9 m) k% P2 D" i6 N' R' v
9 o& u; A% H3 k2 d4 F/ \" x// Iterate over the BOM Items.
* D; V$ u5 \8 F( x/ Ufor (i=0; i<count; ++i) - i# Z0 j' l! l6 A2 c- F
{ , j# R- e; m3 L1 ?, `6 H5 E; w) u8 t% G
// Get a handle to the relationship Item by index.
r; r2 t5 c2 X$ e' t Item bom = bomItems.getItemByIndex(i);
; y# V4 X" ]7 f' E" ^+ ]// Get a handle to the related Item for this relationship Item. 5 F: J n E4 s- W5 Y
Item bomPart = bom.getRelatedItem();
# X. O# J$ [; w. E( A# ?4 S3 W
; {, i9 ^* S! d7 W r3 j; [) {2 V; C content += "" +
3 P# I4 H; j' W# `( i "<tr>" + ; d$ E; D- ?" a) m
"<td>" + bomPart.getProperty("item_number") + "</td>" +
1 I' M2 c/ O$ f6 v0 A "<td>" + bomPart.getProperty("description") + "</td>" + ( q6 B9 T* o9 T0 s5 g
"<td>" + bomPart.getProperty("cost") + "</td>" + + X; P% z+ K! g8 {' `* Y5 p
"<td>" + bom.getProperty("quantity") + "</td>" +
' ]+ _% y8 D, L4 e+ t "</tr>";
4 C* f$ p3 v) w" a# l- d+ r- U}
1 R2 y u! `$ L+ scontent += "</table>";
6 `5 p3 t `0 @; ^ K! k/ F( t 8 X7 x4 \( K. R/ G! i; A: _3 b
return innovator.newResult(content);
9 x4 [' s3 K" d( r' Z7 m5 [% p: A% ?
9 e/ H. B& r5 M0 X8 ?( ~' u5 \$ a/ M$ C' Z0 N( ]
1 `. L6 f1 }- w( w1 h
) p- b. a3 L5 Z b: F- h1 a- p+ x9 y9 c& h4 ] I% E8 c- d r
# D! D3 q5 t1 F( y) Y- F
# D# M: C& Z9 @3 X2 a' t Page 46
0 s% _7 D7 f: V% P$ b6 g/ L# ^
# Z4 |: @6 K# {3 d& UCopyright 2007
1 l6 {" k$ I1 U. V, b- H3 PAras Corporation. % q& r% Z2 ~8 R4 p
All Rights Reserved. % c5 |* U( q4 }3 a; z- Q2 q( b
VB.Net # |: B$ X" n; `' r7 [5 u
Dim innovator As Innovator = Me.newInnovator()
8 I( p8 H$ F+ ]- H& t & t" z& e0 Y2 [+ O2 I
' Set up the query Item.
1 Z$ _/ H3 w4 B: m& y; Y% r% D9 zDim qryItem As Item = Me.newItem("Part","get")
+ N6 Y5 z. i `1 w" A3 aqryItem.setAttribute("select","item_number,description,cost")
0 N2 E- W i, W0 KqryItem.setID(myId)
6 H' q W! z: z% ~. t: p
: R" h0 g" |! C7 N3 n8 ~& w- F' Add the BOM structure. 7 L( H5 D( z. ~2 r/ k
Dim bomItem As Item = Me.newItem("Part BOM","get") $ P7 C: b7 R4 f
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") * A' L/ X- d8 ^; R4 c& y
qryItem.addRelationship(bomItem) 3 [) Z/ b' e' ^8 n( r: s
' s& C8 e& M8 Q4 L0 T" @8 x Y" a
' Perform the query. / ~5 X+ D1 h8 p- ~- E6 ^! G
Dim results As Item = qryItem.apply() : V, r: g: F, b9 B* A* z6 Q) {4 J
2 f& q0 E1 [. J* L; B3 M% j9 E7 y
' Test for an error. 1 x/ h* _$ _% T0 P& w3 {
If results.isError() Then 6 z4 Q5 `$ s' p R# W t
Return innovator.newError(results.getErrorDetail())
. x. W1 {6 H0 v! f* yEnd If
% u9 Y( O. h* U6 n2 g$ _
8 C- e1 C% Z8 \! g9 P9 D: A$ y% M' Get a handle to the BOM Items.
: {. t. _& W) N( p& P: H% `Dim bomItems As Item = results.getRelationships()
/ f# I- y$ P+ `1 g& HDim count As Integer = bomItems.getItemCount() K S/ |% c& n
Dim i As Integer
7 k- n- K: [0 r8 R " V/ x9 A* L1 ~* Q q" o
' Create the results content. ! s' t0 ?- [" y2 q) k
Dim content As String = "<table border='1'>" + _
$ D: Q- Z: y& } h "<tr>" + _
# K5 j# {/ u+ W* V "<td>Part Number</td>" + _ 8 n" w" k9 I9 j. R) ?
"<td>Description</td>" + _ , v, R1 N. A ?! h6 N# R
"<td>Cost</td>" + _
3 K3 L, h U' K; i "<td>Quantity</td>" + _ 3 }- M& k: l4 S% p
"</tr>" 5 T! ~& u9 t+ M' O0 }2 S
4 V* g* U. N' o
' Iterate over the BOM Items
3 q8 V' o# z/ d% c. _For i = 0 To count - 1
* D1 z( l) m2 }+ D/ Q' Get a handle to the relationship Item by index.
) [, U+ U9 C/ t Dim bom As Item = bomItems.getItemByIndex(i) 3 x P) O# N& M# k
5 E( x! x5 ?- D: P! L. \& d$ F- u
' Get a handle to the related Item for this relationship Item.
' b) J! R8 y+ K L Dim bomPart As Item = bom.getRelatedItem() ; K1 t: Q2 ]* Z0 p$ G" d- Q0 J
: {' Z$ o! ^; }: X8 d
content += _ , Z7 t. x. q8 v' _
"<tr>" + _ : R: G5 c% v$ |, ~; m2 U3 q
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
: q' B( u1 e4 Z "<td>" + bomPart.getProperty("description") + "</td>" + _
: }2 q7 { Q2 K5 H7 q& ? "<td>" + bomPart.getProperty("cost") + "</td>" + _ % g; M/ B4 v; \, q$ Q5 G
"<td>" + bom.getProperty("quantity") + "</td>" + _
/ u! J! A Q7 L% g6 o "</tr>"
/ e' o7 O) g4 t* M/ R, @ n4 iNext ) D& y$ D v3 p7 x
content += "</table>" 5 s- R- O3 ^" y8 h; w. J' v
# `% f9 q6 y [3 e
Return innovator.newResult(content) ) E* @! [& h1 O; ?/ l6 ]9 t
* |* D* ?( [' Z7 }; Y4 C |
|