|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ; r( V! W; Y- X \2 j8 D
To query for an Item and retrieve its structure you build the query as the structure 9 M2 Z) [( s! ^! O" s8 k' u" a
you want returned. Use the IOM methods to add the relationships you want and 0 g4 G i [7 h) b( q+ F
build the structure in the Item. The server will return the structure that follows the
H1 \5 W5 H( W$ G1 Q! H" xrequest structure.
4 k) ]) n: j9 r' y) w5 Y4 OThis recipe illustrates several related concepts together, which are how to get a set
! T$ [0 ^' S& cof Items from an Item and how to iterate over the set, plus how to get the related " @ U/ y( l% C/ k
Item from the relationship Item. : e8 K, p+ w- y7 I( t6 Z$ F/ s( g
JavaScript * c; j4 K9 x0 N) U, {( k
var innovator = this.newInnovator(); . u) h, c! U4 y$ [7 _1 r
4 H- j" b% Q9 U. V) y' L W
// Set up the query Item. - S" Z1 G2 t5 Z. Q; K
var qryItem = this.newItem("Part","get");
5 v2 Z8 e$ w# d' g. eqryItem.setAttribute("select","item_number,description,cost"); 2 j0 z6 K% m+ |% W% K+ x! k
qryItem.setID(myId); u1 s& [' f- j2 p/ }1 {
. V; o# |# |8 |6 ~4 h" W* C* W& X4 b// Add the BOM structure. 8 q# U; ~1 z% T3 E
var bomItem = this.newItem("Part BOM","get");
& u- [) C( f# ^: |bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
5 z4 o2 P @ C. Y8 IqryItem.addRelationship(bomItem);
$ p2 u+ s& n+ n1 f9 ?0 b1 c / D. F& ~* r3 Z0 w) K
// Perform the query.
- k- X1 B5 x. d+ v1 k# E1 ?+ c$ zvar results = qryItem.apply(); 2 G) Q8 f+ R( y6 W
( U: S0 U4 k, \/ v- J5 M7 g8 g% ?+ E1 J// Test for an error.
& L5 [0 p8 Q6 w1 Qif (results.isError()) { & E/ \) k j7 B4 [. q3 T2 x5 @ |
top.aras.AlertError("Item not found: " + results.getErrorDetail()); ( I: Z7 `- |4 a2 p
return; 9 k$ Y0 d/ |# s) i4 A9 M
} ) A$ _8 V8 }4 I. s- j( Z& A6 v
2 j0 t6 G, S. Z9 q; |
// Get a handle to the BOM Items.
! T- Z. G$ w' a1 tvar bomItems = results.getRelationships();
7 _0 f4 `/ W" ` ]var count = bomItems.getItemCount(); % d, F' w7 _+ c+ M$ v
d% _2 S5 }/ C, W// Create the results content. # h. o, [, [& d( E$ j% H' w
var content = "<table border='1'>" +
$ B- h% f- q2 N% ?5 p% C "<tr>" + ; L3 p5 K6 x8 ^# [# {6 o
"<td>Part Number</td>" +
9 y8 I/ U# q, |. J( [, _; M$ A "<td>Description</td>" + 2 B+ G7 I( c- B0 L t U! U7 K3 ^
"<td>Cost</td>" +
& h" R) K3 x3 b+ U$ l6 s# w "<td>Quantity</td>" +
( z9 c& F3 Z) \" D" A9 B "</tr>";
) y/ G/ c/ ?$ M7 ]1 M7 \
* V, ^: h( E# A0 O! I; t7 `) l! Y// Iterate over the BOM Items. n, D" W7 a0 n8 ]
for (var i=0; i<count; ++i) 3 W7 R2 v' n( E5 @
{ 6 x# |8 h: s! t, ?
// Get a handle to the relationship Item by index. 1 c7 x, h l! n5 h
var bom = bomItems.getItemByIndex(i);
1 q7 A7 A/ w" U/ X9 V* r& J' |1 M6 U2 v// Get a handle to the related Item for this relationship Item.
8 G8 O; @8 r; L$ D: [3 c5 C+ Q var bomPart = bom.getRelatedItem(); : t- V1 D5 s7 X3 A$ d; t' q4 I
: Y# _! R! Y& l: ^
content += "<tr>" +
7 P, h) t0 F+ z9 D9 L "<td>" + bomPart.getProperty("item_number") + "</td>" +
0 g. Z; P$ W8 _8 @ "<td>" + bomPart.getProperty("description") + "</td>" +
# j* s6 w* h- W& I* X* z7 q: u "<td>" + bomPart.getProperty("cost") + "</td>" +
+ u/ T2 S3 S# m9 \ "<td>" + bom.getProperty("quantity") + "</td>" +
4 r9 {( h) s# O. j( Z. K- q: ^ "</tr>"; 3 G" k9 c- v! [% {% T+ N& H' _2 m
}
7 f# c0 U! c% ?$ greturn content + "</table>";
/ F9 R4 Y2 |& E4 U0 X* e! y% t Z+ K; [
* g: C& V( I4 s& K, Q
/ B2 Q& |: B2 n2 b# h- A. _/ G! Y
9 Z# w- U" F7 S A/ lC#
/ b+ U" c" n' [3 A. _- `Innovator innovator = this.newInnovator();
! C; S# A( P8 x( C
; Y8 m$ w7 d4 j: h% j4 A9 E// Set up the query Item. + K# z- T& u! \8 p# F) I" m4 u( ?
Item qryItem = this.newItem("Part","get");
% C( _% L: P% D( D: r/ l/ EqryItem.setAttribute("select","item_number,description,cost"); ; a, ^ G- N5 U5 x/ l7 j: O
qryItem.setID(myId);
* v% d! p, V& P: i
4 w: R8 [5 R, T, L, d// Add the BOM structure. ; O! m# ^& _* ^+ {
Item bomItem = this.newItem("Part BOM","get");
( v3 i# ^/ C. _# @bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
* [2 F& D+ |' G0 oqryItem.addRelationship(bomItem);
J, ?6 W( D. m7 @4 g) p. U( s 2 r7 |2 h2 `3 J- U- ]
// Perform the query.
. O. H0 G9 {* k$ \1 R5 y& eItem results = qryItem.apply();
& Q9 E2 J7 p" Y- ]
6 g& `4 J% D! d/ I; r/ \1 a: E// Test for an error. v0 V# f- `5 c4 N
if (results.isError()) {
; P$ r0 c X ~2 @: A return innovator.newError("Item not found: " + results.getErrorDetail());
. \* [1 {( @; N' N& G6 h2 f} ! s; _6 \6 ~. w9 `
- G2 K0 H" U- ^3 e5 Y
// Get a handle to the BOM Items.
+ f/ D; u7 t* z+ K2 ]Item bomItems = results.getRelationships(); ' u+ h! f7 m! G/ k: A
int count = bomItems.getItemCount(); ) e- q8 i Y- x9 C+ ^9 Z& k
int i; " ?2 W% e! V) ^- l q& L z
3 u. H# n/ P# i1 k2 f$ n s
// Create the results content. , ]) v1 r/ W" h2 e$ t
string content = "<table border='1'>" + : W# u1 A, r. i9 I. y5 v/ d
"<tr>" + . P. w9 U2 {0 h; {- j' I6 X# X) N! }
"<td>Part Number</td>" + " L* X% n6 P' I" X! }) b$ b
"<td>Description</td>" +
5 m7 w# o% b4 q- d( S- s1 @& ] "<td>Cost</td>" + ' P5 a$ `, H. ?0 T
"<td>Quantity</td>" +
/ L0 x1 B# m3 L& t5 T3 ? "</tr>";
( d' [: y& L9 o) w0 l" F + ^( N6 k7 g6 M; V& y: j0 E4 E
// Iterate over the BOM Items. $ z% f3 @9 ] p' o L7 {2 b$ ^4 y% T
for (i=0; i<count; ++i)
9 y/ r* R$ |% p: V* x) } u{
% x# z) b- `9 W6 K. K' g// Get a handle to the relationship Item by index.
0 E" Q1 m( ^5 Y! Z. R) X) y3 _ Item bom = bomItems.getItemByIndex(i); ; o; L; r9 ? A1 l) d
// Get a handle to the related Item for this relationship Item. 8 \! S5 \* G+ p' d+ c& v
Item bomPart = bom.getRelatedItem(); 4 @: d+ D' a& V c
9 b+ H# u; l/ f
content += "" +
& q3 L# E& E4 Y) o" L2 F; E% p "<tr>" + + w) c/ @& c7 l
"<td>" + bomPart.getProperty("item_number") + "</td>" + $ i1 h) v K' ?1 V3 C/ S
"<td>" + bomPart.getProperty("description") + "</td>" + 6 D) y/ G3 ]0 U
"<td>" + bomPart.getProperty("cost") + "</td>" + 1 v3 C7 h7 q ^9 k
"<td>" + bom.getProperty("quantity") + "</td>" +
! t, c) J' S. ^ "</tr>";
! e9 S7 l& S( D0 Q! u b}
+ K* f; M! g3 C) gcontent += "</table>"; u1 P8 @- b4 ~4 N. X7 i9 w
8 m- A, a& d( b' q- R1 Jreturn innovator.newResult(content);
1 D3 j% D5 D" q+ r6 Y
/ H" P3 [; z+ P2 m9 e. t
7 N3 _' x. T! ?, L- `$ Y5 p: r' e1 R4 E: c3 L1 K+ o- k
6 Y1 }6 i1 {/ [, D3 ^$ H w: _+ F: Z: X( l/ \' l6 ?
: n* [! }& P3 u* g* ~
" A- T( a- E; o- B Page 46 / a: F+ }: R; N9 |4 u
! n5 P5 i/ t: V% J l3 LCopyright 2007
6 f0 U8 V2 i& lAras Corporation.
* W5 t5 m* H0 V5 }6 t) wAll Rights Reserved.
8 c$ @+ h+ N/ ~ g% QVB.Net
& E+ ?/ w, @& {& C/ xDim innovator As Innovator = Me.newInnovator() ' m. j/ A7 H. w5 r q- [
H1 o( ^, ^; z8 M8 D
' Set up the query Item. 1 X: I3 V$ V; Y3 ] _5 h: {9 r/ j
Dim qryItem As Item = Me.newItem("Part","get") " O5 W& \2 k; g4 P- d, m' S
qryItem.setAttribute("select","item_number,description,cost")
* _/ p5 o6 Y4 k) P. KqryItem.setID(myId)
{& ` v/ [' q' c) N
4 h; C6 i2 W, {+ O9 Y- M. F' Add the BOM structure. 3 W+ S9 c6 \- Q) {
Dim bomItem As Item = Me.newItem("Part BOM","get")
4 a7 T" ]! D% z( Q% }( gbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
9 j7 f V) w7 s: wqryItem.addRelationship(bomItem) ( z2 F3 u4 _& t- F, O
6 S0 j' p$ d6 o* d% q Q8 ~
' Perform the query. 0 }" m2 o4 h% Z! w( @
Dim results As Item = qryItem.apply()
5 k5 y. h* q- d 9 x8 M. x7 h6 d; j
' Test for an error. 7 H$ _- Y- @# y9 h0 F1 v \
If results.isError() Then
$ w, @! T( U. D Return innovator.newError(results.getErrorDetail())
, }( f3 n- Z- }1 y5 rEnd If
7 l4 v2 t7 W: m & Q P& F' f* W. \! `; J, S
' Get a handle to the BOM Items. 8 E; i, t6 q. I
Dim bomItems As Item = results.getRelationships()
g" m/ N& h& qDim count As Integer = bomItems.getItemCount() 5 e- n. A/ C- w4 m6 c: t. @4 V
Dim i As Integer
* J1 q) B- E2 |; n, Z5 W
/ b& I u+ J0 L" O' h0 S' Create the results content.
( Y. E9 N; ~# C. G9 x/ `- PDim content As String = "<table border='1'>" + _ 5 S6 y$ h/ u5 f
"<tr>" + _
2 @$ R2 F. q' `' }/ L0 ?2 b) X% j "<td>Part Number</td>" + _
: w. {( k) l; y( R "<td>Description</td>" + _ 9 k+ v b, d8 G# y6 M$ ^% k% N r
"<td>Cost</td>" + _
! N6 f# N% p; Z: ?% l "<td>Quantity</td>" + _
) S E" c4 x9 } "</tr>"
0 c9 h8 Y& [7 C8 W3 s( A! o
, j. E$ g7 ~ ]; X: d' Iterate over the BOM Items 0 A1 L: o1 V, ^; c) c' V
For i = 0 To count - 1 $ s% J/ C# |3 F! A ^0 r
' Get a handle to the relationship Item by index.
) \8 F* T4 ` J) _) A6 H4 c Dim bom As Item = bomItems.getItemByIndex(i)
m: M( d9 ]9 k" ~' e ! w8 {6 a5 c( c& n1 b3 H
' Get a handle to the related Item for this relationship Item.
8 G* D& |$ Y# `0 D4 Y+ w: c# Y Dim bomPart As Item = bom.getRelatedItem() 0 a! P0 i3 r' i% w
" l+ Z0 x6 e" U, k* P9 a
content += _
# e/ A& s }/ b* |4 A: f6 o7 M2 h "<tr>" + _
; K" [* u6 p" x# X/ S% t C4 b "<td>" + bomPart.getProperty("item_number") + "</td>" + _
8 ?" q( s5 Y. j8 V) t "<td>" + bomPart.getProperty("description") + "</td>" + _
* S$ t0 S n9 ]5 q* C( A1 d8 B "<td>" + bomPart.getProperty("cost") + "</td>" + _ 9 t1 E: G+ ~. H) t; x9 A
"<td>" + bom.getProperty("quantity") + "</td>" + _
( _6 L) D6 v# x/ J2 [ "</tr>" 9 q5 n d& L' g8 m: d+ G- u( o+ e
Next + |# O! M6 ]* \( ]# w
content += "</table>" ; y2 B1 r0 H2 z3 X+ d6 f
5 A& A0 W; k+ c/ k7 {$ U# Q" ]
Return innovator.newResult(content)
* U# Q9 ^+ N6 B+ f$ b5 u E: k& N5 p/ B2 M% F2 h
|
|