|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique # T& @, Z" }( Y$ K
To query for an Item and retrieve its structure you build the query as the structure
0 U8 d4 y1 M8 Y- t( J' a6 X. hyou want returned. Use the IOM methods to add the relationships you want and
) S q) f+ N. w O' t' _+ ~build the structure in the Item. The server will return the structure that follows the
$ R* |& A, m6 n* b+ H2 w: T+ `request structure.
+ y: b$ h7 N8 j1 K. u1 A, CThis recipe illustrates several related concepts together, which are how to get a set / t% ]- i. y# a: B
of Items from an Item and how to iterate over the set, plus how to get the related 3 u2 ^3 S8 c; q2 F1 D* Q* e6 T
Item from the relationship Item.
4 L1 k! u* h* q' J. @" NJavaScript 0 b! }2 g! F- c. J% {
var innovator = this.newInnovator();
0 i' x6 T- Y) w& g4 `3 K
& ^0 R$ y+ N3 C/ k w% M1 ~// Set up the query Item.
4 L j* e9 Q; y7 L& \: w3 S0 Svar qryItem = this.newItem("Part","get");
9 c' x: S/ u2 g& Z4 z6 I3 L4 BqryItem.setAttribute("select","item_number,description,cost");
6 @0 h3 e, Y( A) t( T% X$ n2 GqryItem.setID(myId);
, k6 O, z, n# c4 u" T3 k
4 M1 _3 F4 }5 D" i1 s0 H1 f. o// Add the BOM structure.
9 ^* k3 e2 i3 q3 s2 C6 P" Q1 Nvar bomItem = this.newItem("Part BOM","get");
8 b! t0 Z$ {% J& ubomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 5 t- g1 G7 f/ O% }5 b' n3 n
qryItem.addRelationship(bomItem); $ F% `5 D1 U$ e7 k. q7 V+ z
+ a# M& d; \: n* `! j// Perform the query.
( e1 K0 h5 H$ _' X. c8 q fvar results = qryItem.apply(); 1 ` W1 Z- t; k7 S) _
4 [7 ]7 `5 K' X
// Test for an error.
, \. W. _6 N# D( H+ z( u$ T2 h. fif (results.isError()) {
& z# s2 V3 j* B' V6 c& H/ r top.aras.AlertError("Item not found: " + results.getErrorDetail());
& E* h8 o4 i7 D/ \/ O0 D) k return;
6 B+ D7 [ F: v0 ]( G7 @5 i}
8 c, ^8 T: ]3 }
- ]# A% r5 R2 D6 q: ~// Get a handle to the BOM Items. 0 Z1 U* ~% c. e+ P v; Y0 |; b. q) N3 t
var bomItems = results.getRelationships();
6 [" o2 ~3 J* D4 }* c% nvar count = bomItems.getItemCount();
" x% H) d! d. M1 Y, p2 B+ a) D. f + {! ~3 D, z; `% `5 L. D, s0 ^4 f. }
// Create the results content.
$ z \! Y/ g2 P) W, p2 K! ovar content = "<table border='1'>" +
2 ~0 c" ` g" N& N+ M1 X4 c "<tr>" +
( b! q. O& q& I+ G1 g- {( j, e "<td>Part Number</td>" +
5 M/ o/ |8 i8 N* r s$ L6 W5 Y "<td>Description</td>" +
' ]" S1 M9 I7 S2 T "<td>Cost</td>" +
% b4 b- |. c/ ]/ Y7 G, ? "<td>Quantity</td>" +
$ S. U% m0 `! P6 K "</tr>";
6 I4 P- F: V! J* P0 x% A N u 2 K$ E! P0 `" j, l9 K8 f6 D* _
// Iterate over the BOM Items.
: Z" ]# \( t7 H# c) Wfor (var i=0; i<count; ++i) $ ~ A% N3 N G2 B0 |, V0 K
{ 4 i" n5 J% L& c0 H2 Q, R9 G
// Get a handle to the relationship Item by index. ' O. o e/ w. Y! J+ W& k; _ i0 X1 D
var bom = bomItems.getItemByIndex(i); % r: _8 X9 x% k4 |* Z- a4 N
// Get a handle to the related Item for this relationship Item.
4 O* T/ e$ r0 v& v8 C, i var bomPart = bom.getRelatedItem();
% q' ~+ w' }! w
+ L( D$ Y+ y& g {3 V# _# O content += "<tr>" + 7 q7 I# k! P: c6 Z3 K
"<td>" + bomPart.getProperty("item_number") + "</td>" + 7 w/ |2 a$ a3 p3 ]$ G7 j
"<td>" + bomPart.getProperty("description") + "</td>" +
* X. b8 z, c0 e' r" b1 K, @ "<td>" + bomPart.getProperty("cost") + "</td>" +
: D- H# J+ t+ P' I5 A "<td>" + bom.getProperty("quantity") + "</td>" + 2 `) t0 i* u3 U0 g( Y
"</tr>"; 0 C7 Y5 T c' Q9 a* O& _3 f8 [
} 5 `% e: ` \9 p' l4 Q( D
return content + "</table>";
]% K* a( X5 s; F4 @3 U
2 ^ n6 O! H- w9 l* r+ k$ X- k( _1 T O8 C
0 K9 H4 D4 q1 _7 t% y( m0 v
" l# z$ \' q5 H: \, O
C#
+ E% c: `; R1 w0 x6 RInnovator innovator = this.newInnovator();
6 G2 n A- u! o% k' h& _4 [. [) t
) i: p0 p! { m* h g7 w// Set up the query Item.
. d. _' T! l. sItem qryItem = this.newItem("Part","get");
4 y8 y/ N7 q7 a# JqryItem.setAttribute("select","item_number,description,cost");
6 @. A* h1 w( v0 W4 y/ C GqryItem.setID(myId); 9 r5 ~" q' {) M" k0 }! A& w# A4 I
! P! D+ K6 L) F9 E d/ _// Add the BOM structure. & D5 Q! V' u6 F* d! K1 T2 T0 t
Item bomItem = this.newItem("Part BOM","get"); - a' B. A# V( z
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); / z; d. f& ?8 H* z
qryItem.addRelationship(bomItem); $ b* Q4 L0 h1 A
3 \2 w3 {. ^* Z: ?// Perform the query. ) l8 `, S$ y$ E5 Y
Item results = qryItem.apply();
3 \* h; ?# P( G! H6 W
3 ? Q% O" I( a; A" ~9 r% h// Test for an error.
0 K& i9 Q, C& V8 V6 uif (results.isError()) {
, ?' [" p' B. U M- _+ i$ \ return innovator.newError("Item not found: " + results.getErrorDetail());
; D8 G- _# _+ U}
; C+ w% ?. ?: ^; o; h" w % q9 k. I f9 j4 J& F
// Get a handle to the BOM Items. + I& w! H) R5 |+ ]5 A* {- U! a# a+ q
Item bomItems = results.getRelationships();
; h9 }! B2 _" Z9 s8 I0 m. Zint count = bomItems.getItemCount();
" d4 ` k+ g; U, }- Fint i;
3 |( I' F5 x6 Z( ?4 p( M! A / K' y" Z: ], M7 C6 n; v& Y6 {
// Create the results content.
# _" g$ A2 D8 h( Hstring content = "<table border='1'>" +
+ [; Q% a0 _& n! o "<tr>" + / V* U8 B: n) Q: ?/ `2 o$ ?5 z
"<td>Part Number</td>" +
- P/ y0 C8 V7 z6 `; I' I! T "<td>Description</td>" + w0 A! ?3 e% M y8 [ M; D& l: U' j
"<td>Cost</td>" + [0 B0 E4 u8 b* g' n$ l# I
"<td>Quantity</td>" +
6 ^& `9 w+ ?+ b! ~" Y" O) |; n "</tr>";
- K* q L/ C+ f
' u* r& w- w, g' ^! L// Iterate over the BOM Items. 4 M* a. `8 k+ x7 ~& {
for (i=0; i<count; ++i) 2 H. ~2 y0 e6 h1 c! r) t8 W2 s
{
" }% `2 G, r. X4 a/ [6 P8 @// Get a handle to the relationship Item by index. , F& U. a, [. F
Item bom = bomItems.getItemByIndex(i); ) @% C' E+ c, |2 a! E3 i% d+ ~8 j
// Get a handle to the related Item for this relationship Item.
. L {+ h. @; V7 u: m; N! e' A+ P Item bomPart = bom.getRelatedItem();
$ u/ v4 e6 `( p: x8 y9 W
% O6 O+ v* v K3 N$ T8 H content += "" + - M! v# {9 R5 g4 x1 p. b" Q
"<tr>" +
3 s* B+ F: C% ? h "<td>" + bomPart.getProperty("item_number") + "</td>" + , w8 M! o2 f- Q# \
"<td>" + bomPart.getProperty("description") + "</td>" + 6 i/ a4 u1 \1 |0 w
"<td>" + bomPart.getProperty("cost") + "</td>" +
1 W4 R1 m: \. ^4 y, g "<td>" + bom.getProperty("quantity") + "</td>" + 6 W8 ]/ h7 Q. H% N1 Z
"</tr>";
* _/ N( W" a6 S2 \1 n} 5 C4 I! A3 F* n8 l+ l+ U
content += "</table>"; 4 N. Y$ v) y, j9 |! o
( z& G" R# c% `9 C E+ Lreturn innovator.newResult(content); 1 \0 {; g; `1 E
8 i. F! T& v* p% o1 w J( L7 T3 X5 }1 m/ M( B, n
: w4 F4 A& U% O" S6 b" b K$ [6 ~9 p- I+ t! x; _4 W- d
. s: u; `0 `! `: Y9 B% p/ D {: S
1 Y* b4 o" O7 G: F1 t, [/ ~
Page 46
! M) [5 C6 H5 i7 U3 d" M9 U * V/ [+ B8 V' T% o# j( r
Copyright 2007
& Q7 @$ S1 `* i: C$ q5 w: ]# N; [Aras Corporation.
5 L3 C* ^4 N. D+ WAll Rights Reserved. / D4 k' |, j3 K, Q7 Y" d6 @9 e( l3 u
VB.Net
1 j, H0 U5 O% G3 t$ r# G; [Dim innovator As Innovator = Me.newInnovator()
# G: K) G5 s x& g* [5 X 8 y, X% p$ m- {* E3 S
' Set up the query Item. # S1 N. B, ^9 _+ Y+ r" l5 s
Dim qryItem As Item = Me.newItem("Part","get")
- ^6 e+ B ^% |1 q6 U/ x) YqryItem.setAttribute("select","item_number,description,cost")
) J! Y5 |+ n% m% _; K! {% D8 yqryItem.setID(myId) 8 D3 z( O- ]; u1 j1 j
V Q0 m! X, ^* O6 |/ g0 a' Add the BOM structure.
5 m5 l9 N$ x5 TDim bomItem As Item = Me.newItem("Part BOM","get")
_# Q8 s5 O, H8 r6 |' m* [: |bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
; n+ g- Z. s* x3 O0 _qryItem.addRelationship(bomItem)
0 q/ T. Q$ v! `, u+ ?( o" ] 6 d7 H- v$ E" n& X V
' Perform the query. + ]6 J& w4 k3 u2 q4 g5 ]/ ~
Dim results As Item = qryItem.apply() " ~1 f% q( l; u, b
+ l6 h9 \, H8 i' q. E3 T
' Test for an error.
% o) t6 v/ R$ v4 yIf results.isError() Then
& P0 u* Q1 c# Y1 E6 G/ ` Return innovator.newError(results.getErrorDetail()) 9 G& P" \ h2 ]5 T, B' A6 \
End If
: a4 W. s$ h& q# m & A* I8 }, H: Y* w/ k0 |: V
' Get a handle to the BOM Items. ! z4 P/ v9 M+ v6 y) d
Dim bomItems As Item = results.getRelationships()
1 K* R' u0 O8 d: c. q, x( rDim count As Integer = bomItems.getItemCount()
. h5 u9 f! b0 wDim i As Integer + m( _/ v' v, Y, T6 L- r# @
9 g: a3 I6 g2 _' Create the results content.
T2 \( L# d0 m/ s* k# Z1 ^Dim content As String = "<table border='1'>" + _
& d' i* G Q/ z [1 b- D$ S "<tr>" + _ 5 Q7 J; a) K" C( k
"<td>Part Number</td>" + _
5 Y2 l& X& s# R- I7 { "<td>Description</td>" + _ * r# N0 r+ h1 s
"<td>Cost</td>" + _
( X% q' B* y3 X: Q5 L3 T7 Y' T "<td>Quantity</td>" + _ ) D2 ]) B1 f" Z0 G
"</tr>"
/ q3 ~# w" Z! l 2 g1 `) r; V" k7 v3 V
' Iterate over the BOM Items
+ e d" G0 h. {0 g( y+ d. YFor i = 0 To count - 1 5 K' ~: S$ v1 ], O
' Get a handle to the relationship Item by index. ( L2 Q+ x" Y% E/ C/ o* m$ T- T
Dim bom As Item = bomItems.getItemByIndex(i) ! a5 i) ?, F. u; j4 U1 K6 i
, M% P4 e2 I, a& a( t
' Get a handle to the related Item for this relationship Item.
" x. p9 H, p- Q+ q; S3 _ Dim bomPart As Item = bom.getRelatedItem()
! t ^$ x8 x9 D- e, T* | , R+ |, O; q9 C2 M( i
content += _
, P1 M( o- ?1 [) d: ?8 @2 H% S3 K: Z "<tr>" + _
" }, m% B* y7 j' C9 D$ s "<td>" + bomPart.getProperty("item_number") + "</td>" + _
- `9 v* m% v3 c% n, ]; c "<td>" + bomPart.getProperty("description") + "</td>" + _
v, I+ C1 l! L g: Z& [ "<td>" + bomPart.getProperty("cost") + "</td>" + _
" i9 E0 Y9 c" i2 b- E "<td>" + bom.getProperty("quantity") + "</td>" + _ # {3 x! p8 q; m
"</tr>" ( i. \2 V$ D/ X2 l4 I3 z
Next 8 k' ^' s0 t$ F9 S& `! |' W
content += "</table>"
* D+ T) Y, s5 Q* {" _3 K* U # g6 x3 R! [8 [; ^
Return innovator.newResult(content) ) R, R* o( D4 R7 L% r' A0 B% `
! h9 C. Q3 _' b! Q2 ] |
|