|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
' U0 z8 \9 H4 ^" x# aTo query for an Item and retrieve its structure you build the query as the structure
5 Z) O4 Q" \+ p8 ~! k# }you want returned. Use the IOM methods to add the relationships you want and
+ W. Q$ Q/ C1 V. E/ C$ P c9 Hbuild the structure in the Item. The server will return the structure that follows the
& O, j9 n6 k/ L6 V, M9 L7 Mrequest structure.
6 ^9 d9 p+ _& Y- J! E) PThis recipe illustrates several related concepts together, which are how to get a set ' ?% g, u2 ^( u% U
of Items from an Item and how to iterate over the set, plus how to get the related
]3 s& F" w7 g, bItem from the relationship Item.
0 q4 Q$ u. y# ?9 R- IJavaScript . n$ Z) z5 ]- v1 M9 P
var innovator = this.newInnovator();
% X& D. K% a; H2 X & A; @3 d. v8 e- w4 l% x+ |3 t
// Set up the query Item.
# w& Q3 f5 }* F' G, V, N* Lvar qryItem = this.newItem("Part","get"); 3 ^" C- G' N9 N9 O3 P" t Z
qryItem.setAttribute("select","item_number,description,cost");
- H& |, a3 v! \0 UqryItem.setID(myId);
- } R$ d8 S5 r; U6 B ) M- m3 ]% Z. M# T
// Add the BOM structure.
5 Q- j2 T0 a" l* t1 Z" Avar bomItem = this.newItem("Part BOM","get"); . k& G* y1 W" p( g
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 0 d: [* C: a2 @/ `0 @% f9 a G
qryItem.addRelationship(bomItem); 1 m6 {9 d3 {& L: L
/ @+ B8 q' Y) r$ j// Perform the query.
; `6 A; n) ?* ?) }# o$ wvar results = qryItem.apply();
, {1 n$ A: h5 X+ k" h : v# Z. o [" ?! E: n7 N$ f
// Test for an error.
|5 ~, J7 ^# Z/ oif (results.isError()) { $ A g/ d' c1 J# F- Z
top.aras.AlertError("Item not found: " + results.getErrorDetail());
0 r3 A( A9 t$ d' V return;
- ~+ @1 \2 g- _7 W( E' @# k7 F}
4 a, E1 r# z5 w' p% R, c
. |5 z+ }& }" g9 l// Get a handle to the BOM Items. . z6 K5 j5 {5 q% |
var bomItems = results.getRelationships(); % z, y9 D. P/ p$ b1 S
var count = bomItems.getItemCount(); 4 p. w4 |) W% f" S, `: s
& W- X0 {: ?2 M5 m. C" k// Create the results content. ! J7 K$ V8 `; W, |! s
var content = "<table border='1'>" +
1 W8 U# q2 y8 w. ]/ @ "<tr>" + ( J) U- }8 S, O" h' T
"<td>Part Number</td>" + 6 I3 z. y* X! w4 } o& S
"<td>Description</td>" + : J3 l6 f, F4 J7 L2 V# w
"<td>Cost</td>" + ! d1 q5 W- p3 v% w8 |+ a3 [% d7 t
"<td>Quantity</td>" + , {, q2 O6 o0 Q8 r8 M
"</tr>"; , |, A, P1 }3 S& N
7 g+ H, j# S% O' o/ U* o
// Iterate over the BOM Items.
6 M" d* C+ o( d1 k4 d6 h+ }for (var i=0; i<count; ++i) ! K: K' \+ W- ?# Z4 h& x( G
{ ' L) ^6 e0 ~2 Z0 k; |# G8 C
// Get a handle to the relationship Item by index.
, c9 X& E! i; t# u" ~; m' O var bom = bomItems.getItemByIndex(i);
$ s/ a! D; o; u) G( o// Get a handle to the related Item for this relationship Item. " P' E% k) |" f0 x
var bomPart = bom.getRelatedItem(); 0 M6 C( o6 n' ^
3 G9 S% `/ ?3 v _ content += "<tr>" +
6 k' b' G" D0 |; A- ^3 ~ "<td>" + bomPart.getProperty("item_number") + "</td>" + 2 M" p [: N6 d1 Q7 ~ R' f9 I
"<td>" + bomPart.getProperty("description") + "</td>" + 3 a( q$ Z& e: T9 M& g
"<td>" + bomPart.getProperty("cost") + "</td>" +
- ^; [# S8 e3 o( B2 D "<td>" + bom.getProperty("quantity") + "</td>" +
" l+ \3 U) j1 h) V$ l "</tr>";
4 e$ O7 ?5 D- t. U0 ]1 I ^0 i4 E, u}
, S; n9 P. [& e& k Breturn content + "</table>";! [5 s7 M/ T( o; _1 k
5 o# u" k# w8 x. I: C* u
) f( F) d9 }5 a5 G' s% v9 v0 U
$ W# [7 ]- h' i* c5 S7 j! {
2 S4 G1 d& c1 |: {C# 7 c5 P. s# d Q3 y( M
Innovator innovator = this.newInnovator();
1 A: {' N8 r$ U 7 O0 H& I4 `; {, L
// Set up the query Item. ! ~% R, T3 t9 N$ B6 ~% V
Item qryItem = this.newItem("Part","get");
4 W. u' n: t" Y l* J$ XqryItem.setAttribute("select","item_number,description,cost"); " b0 x% J* K. [' [& f
qryItem.setID(myId); " ]2 P. g3 Q% R4 }" H( }
! i9 l1 A- j& D+ D. h, g _// Add the BOM structure.
! E i: z- B+ k; XItem bomItem = this.newItem("Part BOM","get"); 8 Q$ o! M& n" N$ c' H3 D0 G" t, ]
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); % g2 e# Z! x$ U
qryItem.addRelationship(bomItem);
+ N) J. k4 M" D K5 A! }
4 ~& l j3 f9 ~: j' D& o// Perform the query.
1 A7 W1 [7 z7 l$ p/ y! Z3 o) _Item results = qryItem.apply(); 2 _8 q2 L6 D8 o$ ?) |* R
: h8 C: z6 I" e% S& ]! z// Test for an error. : u' I- G$ x8 I- O* ~! x
if (results.isError()) { : {9 N5 |; @% j
return innovator.newError("Item not found: " + results.getErrorDetail()); e$ }% G7 l8 f3 h& q& Y$ X( X( c
} - ?/ D% e8 \0 R0 u3 K3 j, v
, ^$ w4 @! u; E3 {; [/ ~& s' P8 q// Get a handle to the BOM Items. $ _+ Z5 m+ ?' \3 k
Item bomItems = results.getRelationships();
; M; o& l( u. T R/ jint count = bomItems.getItemCount(); 6 B5 {' y/ t! p, `! _) v) F4 f
int i; 7 M" G0 K6 I5 _6 M) ^- C; @
0 v5 U8 L' k" N
// Create the results content.
' I- [# n, a- X" t% m+ v0 S9 Q0 i& ]string content = "<table border='1'>" + $ ^* N; N# q6 N) }; y: p% {
"<tr>" +
; a/ J: `8 u, m6 E: z "<td>Part Number</td>" + 0 c1 n7 q0 c+ b; L- n5 T
"<td>Description</td>" +
" @' J A5 M# y0 a, c "<td>Cost</td>" +
h; f' _! F5 t& h6 @* }* _( P8 m: n5 h "<td>Quantity</td>" + # b# }3 t$ g2 j Q5 `
"</tr>"; 7 x$ Y* m! ?6 G; k; C& C
6 _8 N1 k1 T' `+ S8 B, }- L
// Iterate over the BOM Items.
& p! N [- s4 r1 K& Ofor (i=0; i<count; ++i) - ?) F# g2 `- j$ k% Y: ~
{ $ [0 y/ P0 N+ I+ w
// Get a handle to the relationship Item by index. . Y7 H/ N/ b' }8 H: z2 \
Item bom = bomItems.getItemByIndex(i);
4 h1 o8 T3 H' m+ B// Get a handle to the related Item for this relationship Item. & v. }- _5 L/ j
Item bomPart = bom.getRelatedItem();
" ` q, | x. u0 j" G( y, s( ]5 R: {
( v _" |, r4 l/ K! | content += "" +
# h- a# O7 A" a/ Z "<tr>" + : J2 i2 J# w, u
"<td>" + bomPart.getProperty("item_number") + "</td>" + C$ F+ ^. ^5 z4 ]3 w
"<td>" + bomPart.getProperty("description") + "</td>" +
/ k# L3 {( n8 q% z% q3 A- f2 Z9 O "<td>" + bomPart.getProperty("cost") + "</td>" +
! _0 ~/ a" ?5 \6 W "<td>" + bom.getProperty("quantity") + "</td>" + ( J' w' T6 j) m
"</tr>"; 3 v. f0 y( t t/ d
}
+ i) l& l& `' ~1 [content += "</table>";
3 G( N+ ~4 _0 {+ b* ~ " G' L/ x! P2 b8 J' Y
return innovator.newResult(content); / | f& e3 O/ Y( Z/ n+ }
! Y" }. p* }; C6 P7 R5 K
9 b p5 H+ u3 f4 I
+ k3 J3 u( ]; e" ^* P( F y' ^: h# |$ `6 `' Y8 S. @( u; ~
4 {% f5 e$ U* a$ j
# D% G# P5 E" t Z- l! E' G" Z; w
% |& X+ g# l" ^* A% u" T: i Page 46
& b; z+ O0 ?: U , B' c: D/ } s0 r0 k$ \; h
Copyright 2007 8 V: Z3 ~ R) F+ g a8 N$ w
Aras Corporation.
* `6 w" e! p0 f$ L. h' rAll Rights Reserved.
6 l3 f7 H; }2 f: Q; x. s- ^4 rVB.Net 8 t7 ` k6 q8 G/ K# v" M( @4 Y
Dim innovator As Innovator = Me.newInnovator()
* P/ `3 s6 N9 ]0 b) i/ D 4 H0 [7 ^; ?5 V! Q$ k" q3 A
' Set up the query Item.
+ ^* y' P% w6 L+ @2 j) l3 u5 M4 DDim qryItem As Item = Me.newItem("Part","get") 5 @& F* z+ F* [5 G' ^
qryItem.setAttribute("select","item_number,description,cost") 5 F* a: b& Z( \# f- x
qryItem.setID(myId) & G1 L4 L4 y6 S4 }3 \$ O
& s& ?- O- A3 V3 v' Add the BOM structure.
9 ^7 {- Y. h/ l& H5 ]1 t# xDim bomItem As Item = Me.newItem("Part BOM","get") 3 G5 I0 r, v% i6 a( x
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 9 @* ]9 I; s* s2 J
qryItem.addRelationship(bomItem) 6 p* H4 u- W) J- g5 ~; O
) ]4 r- s0 z. C" H1 C) g7 Y
' Perform the query. 4 C, C }; z$ ?5 E; E7 ]
Dim results As Item = qryItem.apply() . L {9 V/ r8 [, Z k. Y9 s
' {& D8 t W: @ Q c' Test for an error. % J% v+ {9 n$ X/ i" M; W8 e+ z& {
If results.isError() Then
# S* e7 w( Y$ y5 y Return innovator.newError(results.getErrorDetail())
8 C7 g4 ]$ w/ ~ R! ~8 Q3 {# _End If 1 S9 }3 S2 I g i) q1 s x( {3 r
3 `7 L! m# Y- ^* L/ g7 c/ s
' Get a handle to the BOM Items.
# N: m- u2 j; e' E: uDim bomItems As Item = results.getRelationships()
) {! C) Q) \" M6 hDim count As Integer = bomItems.getItemCount() 9 X( B' R0 x& F; L7 ]9 M
Dim i As Integer ! r1 z/ u' h" K) _
h; h, \! J/ L: A' Create the results content. 6 I. v l0 Z8 w% s& ~: a
Dim content As String = "<table border='1'>" + _
$ K, M3 E- y' _ ] s$ \ "<tr>" + _
9 ]$ V9 G( o$ y( b& ^1 o' q* U "<td>Part Number</td>" + _
6 ]( }& c9 J( Y- M H* Y3 E, }- V "<td>Description</td>" + _
! W& h" x3 @8 f1 y "<td>Cost</td>" + _
' C2 g: l7 |4 p8 f9 s, q "<td>Quantity</td>" + _
# A& c% ]+ W- J2 g6 x "</tr>"
% q5 d2 O4 G) g6 i2 ~; ]
+ h2 ?2 z4 H! k; H' Iterate over the BOM Items
+ f% o F( d4 c6 FFor i = 0 To count - 1 , w# A/ } w% v4 M+ X4 d
' Get a handle to the relationship Item by index. 0 G% e5 Q0 l0 M! f3 C. W) |: h
Dim bom As Item = bomItems.getItemByIndex(i) 1 u5 C9 H: h. J' c
' i4 I% Z+ K2 ]4 n( n. \# j) `4 m' Get a handle to the related Item for this relationship Item. 8 Q5 I3 P) D# z3 M3 q( N
Dim bomPart As Item = bom.getRelatedItem()
# Z+ G% A" ^0 R1 P) I- N
% \# ]! d) i. ^$ A% `7 U3 X content += _
/ R+ q$ \! {) r* _# K5 b "<tr>" + _
+ c% ?- M6 e* q7 R! ` "<td>" + bomPart.getProperty("item_number") + "</td>" + _ & W5 s0 L# c9 y0 @
"<td>" + bomPart.getProperty("description") + "</td>" + _
& @4 V4 i/ m2 M* w "<td>" + bomPart.getProperty("cost") + "</td>" + _
3 {2 J5 O3 r# y, V# ~8 k# U0 w "<td>" + bom.getProperty("quantity") + "</td>" + _
, X, O: H1 r9 o* j' Q "</tr>" # c% `$ I5 N9 U4 c
Next
! O9 |* b9 ?4 Scontent += "</table>"
6 o5 L' b, U3 Z- q; u3 N* n
& U7 w2 a- F: c0 cReturn innovator.newResult(content) + o) x C$ d+ \* y' T) M3 l. ]
$ ^. ]! b# a$ h9 U |
|