|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique & L/ P w q. ?) D4 ~
To query for an Item and retrieve its structure you build the query as the structure / g2 F9 r9 j& o
you want returned. Use the IOM methods to add the relationships you want and ( C j* J0 I+ H
build the structure in the Item. The server will return the structure that follows the
* W* \4 `2 H$ `3 X5 }0 Prequest structure.
7 W) ?4 j1 m% w4 [# nThis recipe illustrates several related concepts together, which are how to get a set j0 g0 S, @6 H, G! O0 c7 T
of Items from an Item and how to iterate over the set, plus how to get the related 1 ^4 b$ J8 i# G2 ?# p
Item from the relationship Item. 3 F# \4 C* X8 S3 e$ }2 _# T2 H2 Y
JavaScript
+ x6 A* Z' N* C4 R) C a( r( mvar innovator = this.newInnovator(); / n+ @% [+ ]3 o4 M
; D2 j) l3 U3 y( c
// Set up the query Item.
6 O2 K) J$ l3 @# pvar qryItem = this.newItem("Part","get");
5 G( j1 v2 J9 O4 d/ U- OqryItem.setAttribute("select","item_number,description,cost"); 5 D0 ~/ L% B, r' j
qryItem.setID(myId); 3 J2 L, _5 R9 U0 ]; e$ o0 _
; C( O! l3 V" z
// Add the BOM structure.
. Q& }8 E9 X# e8 }' bvar bomItem = this.newItem("Part BOM","get"); 2 x; g4 R. \5 t+ i- `
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); / J( V1 Z. x$ b! ~
qryItem.addRelationship(bomItem); 5 [2 o8 q+ b8 e9 V8 m B
( Q! k" r0 \& [4 T% l; a// Perform the query.
. _8 o# C& | l7 p% E: rvar results = qryItem.apply(); ; i1 p2 j4 b. p1 G9 L
" x$ t) I$ c+ J
// Test for an error. 2 } q5 V q! P- C6 r$ k3 l
if (results.isError()) {
1 |: a! c3 v! ]5 O2 @/ R top.aras.AlertError("Item not found: " + results.getErrorDetail()); 5 `& h& u: a. Q Z- u7 i
return;
* y/ ^2 q ?# q6 B}
4 W2 I* v# V' n7 m& |5 d8 y " C" n8 T& t0 N
// Get a handle to the BOM Items.
0 \( i- N9 R* i% H% V3 X4 Ovar bomItems = results.getRelationships(); ! J( c: V' c, z8 M, R4 D( {4 b4 [
var count = bomItems.getItemCount();
: F9 F: N0 A+ h9 p
# c2 {1 E( v& `// Create the results content. & l% L9 c# p- ?$ m& l3 r
var content = "<table border='1'>" + # w0 H/ B8 ^8 M" v
"<tr>" +
2 `: H# D* e3 d1 P5 c "<td>Part Number</td>" +
b1 F" j# `7 @ "<td>Description</td>" +
, n: `% f {, q* v. ]) F% @: ~' V "<td>Cost</td>" + ' h1 T `. J# { c( m# Y+ Y& x
"<td>Quantity</td>" + % S; u2 Z" T. m; x) c
"</tr>";
4 [+ S( I" p6 Z: m ; q# j) {. Q; ]
// Iterate over the BOM Items. $ @6 W7 l3 i( Q/ h$ W N* r9 @# J( |6 M
for (var i=0; i<count; ++i)
' g: P3 _+ @* `$ W8 |) S e2 z{
& Y; e" E' [( p1 J% k! J5 P// Get a handle to the relationship Item by index.
4 ?" D# m+ [) z var bom = bomItems.getItemByIndex(i); , O5 s& z) L. E+ I$ g
// Get a handle to the related Item for this relationship Item. ( x% ?) N( j* Q! z5 f/ l/ g) h
var bomPart = bom.getRelatedItem(); & u/ s) I- v2 [; E, F
2 M; @# |( v" X( s6 a3 f9 M. X content += "<tr>" +
8 Q+ [7 u9 c3 D+ C. R. c$ X _0 e: ? "<td>" + bomPart.getProperty("item_number") + "</td>" + $ M7 ?8 C7 [1 C5 }
"<td>" + bomPart.getProperty("description") + "</td>" +
& J8 s7 h7 `- o2 O$ L "<td>" + bomPart.getProperty("cost") + "</td>" + c8 u k( ]" R: s* }8 \1 ]: d6 i
"<td>" + bom.getProperty("quantity") + "</td>" +
+ c! B% A6 X; n& I* W; z+ J "</tr>";
% j1 }8 L; M3 v! ]}
: r$ |: y8 ~0 D' d5 G4 Kreturn content + "</table>";
C2 E" |3 x" s+ @0 N6 a) v |% G+ S$ z. D/ m5 U& ?# D0 ?
, d, v7 z0 B2 x& D; K
0 B# d+ Y% r+ p1 h/ j! o" i
( q5 c' b: |' K/ O( a, ~1 DC# ; g5 }8 i# C/ t- n; z
Innovator innovator = this.newInnovator(); 8 m' i' C, x( z5 g
! V1 ` }+ O0 u. d! x
// Set up the query Item. 5 H' i; i. R8 t. i
Item qryItem = this.newItem("Part","get");
" y. [) D& T( SqryItem.setAttribute("select","item_number,description,cost");
9 I- X4 T2 Z. H' c, v! CqryItem.setID(myId);
# r6 N, s7 A; Q( @
( R8 T" F$ u/ H; U1 F1 {// Add the BOM structure. 2 ?# G3 L, \1 h5 r, y
Item bomItem = this.newItem("Part BOM","get");
/ o c+ ^8 L/ v. Q' k' f( _bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
# P% I# e/ e/ IqryItem.addRelationship(bomItem); # P9 W7 K6 ]3 O5 W* V
7 `2 G6 z+ y: u" F m% g( K
// Perform the query. . B2 h x8 P! f$ J- t; R0 r6 _: Z
Item results = qryItem.apply(); 2 [+ {: I$ o- L. o9 a
" U1 N B5 { N8 H5 m$ H; g7 l, h
// Test for an error.
3 ^4 d- {! A/ w; r) N, P; Pif (results.isError()) { , j5 N8 `3 K6 ]- t" O" n
return innovator.newError("Item not found: " + results.getErrorDetail());
$ P, w1 t. K$ u. ?* U7 M} + x! d9 h9 O* M/ N
6 a/ N2 R0 X5 J m4 ]9 v// Get a handle to the BOM Items.
. C# Z) N3 ^" M, z! n2 wItem bomItems = results.getRelationships();
3 R$ j& M/ b( L: O" Q; ^int count = bomItems.getItemCount(); 2 J5 R7 B, v" q& L
int i; 0 t6 G$ R, ^4 x8 [) V5 r
) R6 A! c5 [; @- f& \5 k" R4 N
// Create the results content.
' B" _3 i7 e- H( S% Q3 wstring content = "<table border='1'>" +
2 t. N: D: R4 U "<tr>" + $ i! P' e4 `7 ]/ D
"<td>Part Number</td>" +
' @: o" ]6 n( e6 D( O/ ? "<td>Description</td>" + 5 s2 I5 ?3 s4 K3 W6 ~" @& J0 n+ |- y3 A
"<td>Cost</td>" +
( p$ N- E2 x# Z% X( X; W "<td>Quantity</td>" + 9 H2 o* _- s3 P; [0 j
"</tr>"; 4 E/ d5 k, W. s( F3 T
- j- }% k& D7 M' T
// Iterate over the BOM Items.
7 O" y! q' y8 B" [& Afor (i=0; i<count; ++i)
/ l8 w/ @% k/ @' f$ `5 F" Y, L1 ~{ # c* _) {0 z! t( y0 I+ j: h
// Get a handle to the relationship Item by index.
V" b! P# k+ r+ q Item bom = bomItems.getItemByIndex(i);
$ o) n3 A9 \0 D* @% [8 r1 e" J// Get a handle to the related Item for this relationship Item. ( }/ |0 P5 P/ [
Item bomPart = bom.getRelatedItem(); 1 q% u% U( r2 T! U& M
0 A& M. ]* ~+ V4 I
content += "" + , i, F# \; k' n
"<tr>" +
( a, J0 M8 C+ s "<td>" + bomPart.getProperty("item_number") + "</td>" +
+ u4 V) f* \ f- `! l; r "<td>" + bomPart.getProperty("description") + "</td>" + ; c7 V1 o" J1 E
"<td>" + bomPart.getProperty("cost") + "</td>" +
0 {* n6 G$ S& ?/ g6 P "<td>" + bom.getProperty("quantity") + "</td>" +
, U/ J* F- ~! D3 E: { "</tr>"; % H0 R: s2 a& ?" P( E9 t+ P
} 4 O" c x! ] s8 O0 G
content += "</table>"; 2 [# q7 F# N6 |0 q
- v4 g( e4 ~" T# p3 ]% N
return innovator.newResult(content);
; O5 C- e X$ n! S* i0 G7 D
7 }5 ?" R p6 D& D* H
, x& ~: y* L# S9 N3 [
# C2 g( _) |+ c+ ?% q( r$ ^' z1 O$ V( Y( u! z/ N6 m8 [
3 @2 a1 t: e/ T* T l! u
& f! m% ?4 c8 w% `! G: E+ G( Z8 N
; P9 v* {$ Z% V4 E& s Page 46 - @; e E- \7 J( D7 t# l
, `) ^" o! g$ J& l4 O
Copyright 2007
0 b5 ~8 @% T- ]% EAras Corporation.
, Y- c# }* B9 O1 DAll Rights Reserved. : F/ r# C) `: N; e3 Q( l- N
VB.Net
' D6 S" I8 x, Q- tDim innovator As Innovator = Me.newInnovator() 1 Q3 y* s) x$ S" ?
- V: d: G* T, `5 }5 o. `- t# C' Set up the query Item.
8 z" N. M6 h0 a) ]& B% J) Q& HDim qryItem As Item = Me.newItem("Part","get")
2 z' D' U4 r: IqryItem.setAttribute("select","item_number,description,cost") $ Z, K4 q n' m& S0 Z! x |
qryItem.setID(myId)
6 Z0 t' H" C3 l, r, \! }- q, l. O 8 A/ ?( t5 F5 g* q9 m
' Add the BOM structure. $ Q; r0 M0 g+ f; [; R
Dim bomItem As Item = Me.newItem("Part BOM","get") 9 K3 P( [1 H. @- Y3 f
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ' Y+ y3 G4 |: q, I$ h
qryItem.addRelationship(bomItem) & D, K% a% S( K- ^$ w6 x
; \ v( ]) |& W, ?+ h
' Perform the query.
H# A4 P3 o/ Q% a7 T8 i4 J' aDim results As Item = qryItem.apply() 2 [, c1 g& F0 W4 A7 p
$ Q& M2 |. k5 ^2 g' Test for an error.
/ w# S% n, s$ D; n+ O- V0 lIf results.isError() Then / `# q+ \' w$ N0 N
Return innovator.newError(results.getErrorDetail()) " s7 l5 }; n a% i7 B" X6 v5 g! L
End If
6 w9 [% L, i8 d) c8 x/ s2 W. t1 `' ` $ |$ R' k9 C& o, Z
' Get a handle to the BOM Items. 3 W) e+ @+ }) v0 t0 N
Dim bomItems As Item = results.getRelationships() * C, ~8 l/ o+ _9 E
Dim count As Integer = bomItems.getItemCount() , u8 {: y( n b4 F/ J) B* ]
Dim i As Integer
4 j$ p- ^+ i" ?6 Y( `" h/ W' p) r
* Y2 {! }2 u& p, X3 e4 k. L' Create the results content.
( ?) S- T$ W7 G5 T/ g4 U' jDim content As String = "<table border='1'>" + _ n( _9 v( T4 T n6 g. h
"<tr>" + _
0 k4 a7 ?5 k" D9 ~. t: M "<td>Part Number</td>" + _
* W% Q, R. B1 z "<td>Description</td>" + _ ( H# z E; K' s& K
"<td>Cost</td>" + _ . ~ S9 F+ B- |
"<td>Quantity</td>" + _ 6 L8 M# Z2 H8 e; C
"</tr>" b w. d3 ~- I2 E; u! ?
7 L% k" H9 L1 c4 B
' Iterate over the BOM Items + i u7 k/ Q! n/ p8 ~' c
For i = 0 To count - 1
: m( K: X! w! L# T) s4 L' Get a handle to the relationship Item by index.
7 T8 l# J5 {& w/ F6 _7 j: O" j9 o Dim bom As Item = bomItems.getItemByIndex(i) ) |9 K0 t7 [ l1 q
& ~# C9 b: ?( L1 [5 `( `' Get a handle to the related Item for this relationship Item.
: u* P1 A% o; h6 l K# z( y Dim bomPart As Item = bom.getRelatedItem() 4 P8 [9 i/ @ N: }0 N q
4 G/ P# g, {1 ~6 k6 ?, H4 z! v content += _
! M+ M8 S/ b3 r- B "<tr>" + _
8 C0 ]# g; d, N2 r) v, l- @ "<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ w5 J$ k6 L# b) X6 S
"<td>" + bomPart.getProperty("description") + "</td>" + _ ! Q" S* B; r7 i8 \4 Q) _4 {
"<td>" + bomPart.getProperty("cost") + "</td>" + _ & l( ?& _1 F& K2 T- I
"<td>" + bom.getProperty("quantity") + "</td>" + _
( G5 i. y n" o$ j0 S% j6 Q1 K "</tr>" * f. L$ ~& c7 {4 B* l5 o) S" X9 P/ D
Next ! Q9 g% P @' n* Q/ Z/ e
content += "</table>"
) y0 |4 y6 Y! r' g3 U- i * d0 v" n, ^4 V7 C- ~7 ^
Return innovator.newResult(content)
! ?* w) x0 G! Y) g P
s& e! h, Y3 P. O9 ^$ ]7 ]6 S |
|