|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique . m& L# _+ j9 W
To query for an Item and retrieve its structure you build the query as the structure 0 \5 N) V/ k. S1 D. ~6 {4 }
you want returned. Use the IOM methods to add the relationships you want and & R; W* x7 v) n9 Z
build the structure in the Item. The server will return the structure that follows the $ N& i* b; P9 \3 r2 ?( c
request structure.
H5 F9 V5 T' @1 z' WThis recipe illustrates several related concepts together, which are how to get a set 6 P4 ^" {, J0 h* X4 ]! C+ h
of Items from an Item and how to iterate over the set, plus how to get the related
2 C! m/ a# S: {% C4 T+ |$ h! vItem from the relationship Item.
% m$ h {! |( s9 m8 v9 t9 K7 W5 L. W! wJavaScript 5 P1 O7 |1 C( F( a* K* M
var innovator = this.newInnovator();
1 P" P0 b* K3 G8 F+ T 0 m! A1 |- w. q0 n& u- b
// Set up the query Item. : c6 o8 [+ ^& V1 @& a8 i
var qryItem = this.newItem("Part","get");
% s9 e' X4 u. ]8 ^9 F J$ g2 hqryItem.setAttribute("select","item_number,description,cost"); ( Y) n/ m$ v% K( I5 R; x% F
qryItem.setID(myId);
3 B2 Z2 V' |) t" I* W
0 }, u4 D& h1 y// Add the BOM structure.
* S( I& z. Z2 svar bomItem = this.newItem("Part BOM","get");
% @0 Q) ^& u1 f& Z: `bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); % b3 Y7 T1 y) ?0 t# g+ y% g1 H
qryItem.addRelationship(bomItem); # r# A6 q6 C& u1 m) E% A1 H1 M( ~
* W4 [: z6 f) ?) S8 ]+ m
// Perform the query.
_, B/ M7 C* lvar results = qryItem.apply(); 1 \( t6 p6 F, {# y; m2 [
, y; f4 P1 N" j. \+ x/ a// Test for an error.
4 N1 E# ^( {* k+ R# D. Fif (results.isError()) {
0 h; Y+ y8 m9 j5 S; b- ? top.aras.AlertError("Item not found: " + results.getErrorDetail()); 9 G9 S; t2 T* B, s* }+ n
return; ! q) D( L( U, W' q& I4 }& J
}
5 f9 m% Q: P2 J# v- E: p4 x
6 h- h2 j: e5 x1 F u// Get a handle to the BOM Items. ( a Q) S- J4 p/ C7 Z, U
var bomItems = results.getRelationships();
+ s0 A) F% N; lvar count = bomItems.getItemCount(); " A' l/ b j/ F& z4 R7 O
9 h% E2 j5 c# J% J Q) d/ M// Create the results content. - O2 J' w' G [# z4 Y6 W
var content = "<table border='1'>" + 9 r3 T; f) ?- m. o9 F e) k' V( h
"<tr>" + 1 R& h5 x0 f- a; H- S" }
"<td>Part Number</td>" +
( e8 `; o/ j$ N$ P: V& { "<td>Description</td>" + " E6 D. J) B) i3 T7 W
"<td>Cost</td>" +
1 M( ?' H& Y7 p7 o- C* a5 R0 I "<td>Quantity</td>" +
i4 @3 e( Y% ?1 F# O: G$ s "</tr>";
, \ K" {4 q9 c% r9 r8 J
* O) M% Y0 s% q- j; u" E R// Iterate over the BOM Items. 8 \. N D% y" J9 A
for (var i=0; i<count; ++i)
1 O# i7 S; E0 q. b Z{ 7 B% ^3 ^8 j1 u e4 K: X6 D
// Get a handle to the relationship Item by index.
5 H! F3 P7 E6 Y" z+ V: j! s var bom = bomItems.getItemByIndex(i);
5 i0 a7 w$ S3 Q6 \// Get a handle to the related Item for this relationship Item. ) @. H$ L' w/ o% Q1 ]* D0 k
var bomPart = bom.getRelatedItem(); / i$ o& M$ a" G: B- [0 |* d: K( ^( U, X
) p: h& D6 G" o0 M# A' I- J
content += "<tr>" + , x# q! I# C( @9 p4 `7 \6 l7 w. K
"<td>" + bomPart.getProperty("item_number") + "</td>" +
# ~0 r% O9 H+ |7 ~, `0 R) o "<td>" + bomPart.getProperty("description") + "</td>" + 1 }0 Z# x$ T6 \( e; r( m) a
"<td>" + bomPart.getProperty("cost") + "</td>" + 0 y; [/ v# Z8 X& ~0 x; u
"<td>" + bom.getProperty("quantity") + "</td>" +
2 i2 |/ ^% @, N) B% V E- d, @3 [6 G "</tr>"; 2 F, u2 r( h- m0 k; D9 }; Y8 y
}
% E* n) u! c6 {9 wreturn content + "</table>";7 O+ e$ y9 _" `! U* w. f; g& w5 w
3 f3 h( d% j& H- ~) O& M
7 U/ ?7 m: j0 ~. P& c7 Y
# S: t E2 D# k% r3 j" e Z/ S* g3 B, Z8 u
C# ) ~4 x# L, z% j- D; ]& H6 t- e
Innovator innovator = this.newInnovator();
3 z1 j( X0 L) i8 G+ V# B
) L% L) W+ C1 v" M$ `2 a// Set up the query Item. ( W* l8 i8 ]+ e; {5 h! }
Item qryItem = this.newItem("Part","get"); ( w/ m: J' @) L4 b8 E* A
qryItem.setAttribute("select","item_number,description,cost");
% a" z$ M! d1 L1 Y) WqryItem.setID(myId);
2 n# {7 A* [; w! j0 U $ B: x9 \' B" ^, O( {2 l& [" F
// Add the BOM structure.
# ?/ q+ A a! fItem bomItem = this.newItem("Part BOM","get");
: i+ e7 b2 U: P) T9 tbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
5 [/ T/ ?8 \$ r6 AqryItem.addRelationship(bomItem);
$ C( u4 G! ^9 N1 ~7 e; o " c3 ^ @4 C: S9 X: _. D
// Perform the query. ) ~1 o+ b) E4 e& s0 x. z( Y8 X
Item results = qryItem.apply();
. J) U# W6 G& T9 N1 y' B
) O% v! V4 k8 P) M, s p) U) c// Test for an error. & d# s1 Q) q% K9 x6 ^
if (results.isError()) {
+ v. t& }7 {% d8 p2 a: e return innovator.newError("Item not found: " + results.getErrorDetail());
; u& g& r* s: O- M; g, m# b% ?}
9 o" W* K1 w* g. P
# I" \. `6 }$ z2 W- j7 o" X// Get a handle to the BOM Items.
! v; \2 \( J+ K' a. v* N' I/ CItem bomItems = results.getRelationships(); ! ?" j+ \$ D+ g7 d4 D! A. Y
int count = bomItems.getItemCount();
, `: I: z8 r- n% Wint i; 6 ~7 O# Q! r0 }- z$ p2 B
+ `5 z6 I* s! C" k
// Create the results content.
# ^' r0 y+ l; e0 x, c6 [! z$ Q- Fstring content = "<table border='1'>" +
" K* Z) N6 U% m% W$ a5 g, v* {- x "<tr>" + . g: R9 ] Z. e5 ~/ Z4 S/ c& w
"<td>Part Number</td>" +
' Q/ ~4 Y7 L& p5 \$ f5 q- r% Z. p "<td>Description</td>" +
* |2 I. n3 c0 M) O3 a! X+ i7 U "<td>Cost</td>" + 4 {5 H% N2 K( _' r
"<td>Quantity</td>" +
# L8 ^) D6 O7 y2 z6 p% ~5 H "</tr>";
2 I$ @! a: Z6 K# U! g) y! p0 B ( o4 R( m' ?6 E! z9 }
// Iterate over the BOM Items. ! a$ i3 N' R/ `# o- I) \! J
for (i=0; i<count; ++i) , |; @4 o* f% _+ F2 j) N7 Y* i
{
# ?1 \6 P) z, }$ r6 x// Get a handle to the relationship Item by index. 7 t# L2 c4 ~4 K5 [% M; a, ~( F
Item bom = bomItems.getItemByIndex(i);
% N/ Q4 B. B' T0 I$ W// Get a handle to the related Item for this relationship Item.
6 P% Q. |4 ^9 l3 I& j- r! y, V6 ? Item bomPart = bom.getRelatedItem(); 2 P, u- W* C9 r* ]( f' J
2 L8 R* g. S/ L; m$ B( b5 @. W
content += "" + 6 f( G: o. H+ @9 W% f( d* G
"<tr>" +
8 J0 W+ [8 S5 w( Q( Y3 A" K" ] "<td>" + bomPart.getProperty("item_number") + "</td>" + 3 Z4 {' }0 G; _& ~1 l0 p) F7 A1 B! U
"<td>" + bomPart.getProperty("description") + "</td>" +
6 W! v. l1 T4 D7 q( { "<td>" + bomPart.getProperty("cost") + "</td>" +
9 Z$ \7 D% e! Y* O3 x4 ^/ Z+ T "<td>" + bom.getProperty("quantity") + "</td>" +
- H+ a6 V& z3 }1 g ~ "</tr>";
7 A7 j( w: O: D9 |8 F# |} + U/ V* z8 i& `" _- r4 P) x
content += "</table>";
* y5 i& q/ r' d0 a( ?) A ^
2 o- @1 u+ g4 X! G3 X3 @; Hreturn innovator.newResult(content); & D% {1 B @0 K: |
& s, M# p) y' B$ b
$ }# Z! F- m/ ]. z! f- K' W) h
5 ]9 J2 [) i Z8 n, ]* o: Y# S4 s$ y% x4 T" h6 W
8 [! I1 |9 u6 G3 G. Z! c3 _2 r2 q
0 n( ~1 U" h2 M- w
$ A. j" t; v6 U- k1 k
Page 46
8 t+ Z7 u% J( j. p
4 h. E- R% K3 R1 JCopyright 2007
$ ]7 \$ _: ?# t- @8 y ^7 aAras Corporation. 6 y4 N. B( {. T: x8 {2 j3 V0 m
All Rights Reserved. : I: `3 _' F7 |! y, O4 W6 b
VB.Net ( V8 R% o4 L9 N
Dim innovator As Innovator = Me.newInnovator()
4 R# o# F( E6 M3 V: q" c
, P8 R" A) p2 m2 Q- V' Set up the query Item. 7 o/ A7 _& t/ l* K; v# I2 U6 k
Dim qryItem As Item = Me.newItem("Part","get") 2 l6 j M d( A" j/ ]
qryItem.setAttribute("select","item_number,description,cost")
1 ]* d' h9 I0 Z) w7 GqryItem.setID(myId) 6 F, B, y5 p/ H9 v
8 k2 k& ^. M8 O/ V
' Add the BOM structure.
& d4 b4 g* j4 F2 D( oDim bomItem As Item = Me.newItem("Part BOM","get") & d1 j. \. W' M$ _% _6 I
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
- K" T, E! P+ ? e j3 @qryItem.addRelationship(bomItem)
6 W$ k, \# x2 i" g- E7 q/ j# E
v" A J$ p$ c2 |' Perform the query.
/ A: o! `* J- j5 T1 f' b6 N9 v* _Dim results As Item = qryItem.apply() 8 \% K+ c8 W5 f: C
' C7 p3 g9 L! m6 N5 e' Test for an error. # I/ ]! K8 {, ~
If results.isError() Then ! u( m$ a2 E) n9 l1 |% j. _' B2 s3 X
Return innovator.newError(results.getErrorDetail()) 2 L! x% }' c) |8 D/ w
End If
. I( b) f. B9 a5 x. A N9 g3 a; \; o
/ j5 K3 [+ o9 T7 d' Get a handle to the BOM Items. 0 v' y9 j) L0 T7 W; p! i
Dim bomItems As Item = results.getRelationships()
8 m$ T8 u* h: w* ]* _Dim count As Integer = bomItems.getItemCount() # [ s) k& T, K6 W, d
Dim i As Integer / Z( V0 z* r: ?: X; A% v* J
" _# k3 |* `! C+ z+ |1 ?/ j$ r' Create the results content.
1 E: O# [& c nDim content As String = "<table border='1'>" + _ ; ~/ J3 N" b" C+ \% H% ?$ U
"<tr>" + _ , B# k& _, P6 ^+ k
"<td>Part Number</td>" + _ 2 e ?& n" ^ \8 k' A7 s
"<td>Description</td>" + _
3 J# s; F$ S4 v- [% a9 K "<td>Cost</td>" + _
0 X& f/ J: b) v# H+ [& K "<td>Quantity</td>" + _ ' ^$ A: x1 O& w' o; Z, W8 B
"</tr>"
- w" q" v1 s: s1 a* J! M 7 z) u. I% P8 H; K) R% Z/ q
' Iterate over the BOM Items
3 f, O+ {& E7 UFor i = 0 To count - 1
+ j' P' A1 @% U# g2 R' Get a handle to the relationship Item by index.
- Y, N6 k3 J" ~- I Dim bom As Item = bomItems.getItemByIndex(i)
1 v Q; H+ Q* c8 T( ^( d
3 ~% ?5 h: Z, _, Z( A' Get a handle to the related Item for this relationship Item.
2 I- L5 d: ~ R+ j: o8 Q+ Y Dim bomPart As Item = bom.getRelatedItem() 0 D3 s$ a( V2 i8 L2 f
|9 ~# Z2 b* R$ w- _% |2 P- p
content += _ 2 J {0 D0 |1 T! {
"<tr>" + _ , V& b6 T* O+ R+ B1 p
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
6 X2 `- u4 V" |6 a "<td>" + bomPart.getProperty("description") + "</td>" + _
5 q' r7 {8 V' Y "<td>" + bomPart.getProperty("cost") + "</td>" + _ " y3 F! O7 S! M% P
"<td>" + bom.getProperty("quantity") + "</td>" + _ % h. w! j: L+ C: J R
"</tr>"
5 Y- a5 g' J; V" y RNext 0 Y% _, b( Y7 |2 h; ?/ }4 J, x& K
content += "</table>" ! u- ]9 h1 j) E7 q0 v, O0 E+ l
4 W5 u5 K: g6 x# _$ |, b
Return innovator.newResult(content) 4 K' J& N- C/ I% ?; m
* x% v7 f! f* [+ B7 O& E2 g5 l
|
|