|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique & L6 R; F1 _) c
To query for an Item and retrieve its structure you build the query as the structure
; m/ w; K+ W0 A h( T' B3 D( wyou want returned. Use the IOM methods to add the relationships you want and 0 e2 H. W* e% k( o6 A
build the structure in the Item. The server will return the structure that follows the % _/ T f& X7 S8 ~, _
request structure. " x; w) Q; E+ ^( c) j
This recipe illustrates several related concepts together, which are how to get a set ! k2 O- I. h: v9 r* b
of Items from an Item and how to iterate over the set, plus how to get the related
) |& Z& d% `0 D; QItem from the relationship Item.
9 U! R5 u4 w8 sJavaScript % A- ], F0 m2 r
var innovator = this.newInnovator();
; h* p9 J, p& c6 ?: n- B- w
4 ^' T; l- \( P9 m// Set up the query Item. 0 }) M$ {6 \ Y6 S! i H- C
var qryItem = this.newItem("Part","get"); 9 |$ ^, A t8 l, r9 O2 @0 _, h
qryItem.setAttribute("select","item_number,description,cost");
( e# K3 i5 i- s5 }+ O2 B. RqryItem.setID(myId); 4 v+ X( K4 @4 G# M H- s
4 C( C k( d$ `! i! ~* k' Q
// Add the BOM structure. 4 U0 n* y+ v$ x( z
var bomItem = this.newItem("Part BOM","get"); G+ C% Q( J+ D6 s( g. I' q1 G; b9 H
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 4 M- M; K# x3 @& F( N& n% h
qryItem.addRelationship(bomItem);
8 H1 W8 M( Q2 z0 ~0 P , I8 d- z: ]9 j- s4 a5 U/ R
// Perform the query. ) a6 K8 ^! W% p; x# P
var results = qryItem.apply(); ( v. T" ]0 E( i+ O9 R
) v8 |$ p* g x2 I" b( h- ]: K
// Test for an error. : t8 `1 T% J2 k& J1 F X3 W) n4 x
if (results.isError()) { % I4 b0 Q1 E4 l1 s. ^3 F8 ?" U! n
top.aras.AlertError("Item not found: " + results.getErrorDetail());
: {( m# e+ \ ~7 B' f. Y4 L" r, H return; * O: @( ?- o, p$ ` B$ b6 |
}
! i+ b! c, ^( k- b$ D5 L ( v m4 i5 @% r% K! x# k7 V
// Get a handle to the BOM Items.
2 X( f* y$ W Q- O7 {& f9 Vvar bomItems = results.getRelationships(); 2 m* b1 @& D# ?+ {6 ?
var count = bomItems.getItemCount();
6 N2 K6 ]4 D* t3 d+ N; ~ $ I9 o) {& ?: P6 S" g
// Create the results content. ) B8 X0 ^: j U5 s
var content = "<table border='1'>" + % }7 b2 T# m1 n: K% U
"<tr>" + ; |; |8 A9 u: d2 q3 Q
"<td>Part Number</td>" + ( f/ I) B6 |. b8 E
"<td>Description</td>" + 4 L, G3 B J% L, o9 p) l
"<td>Cost</td>" +
( ]1 @; T4 T z$ L: ?) l( x "<td>Quantity</td>" +
! w2 `3 z( I; s9 ^/ v3 | "</tr>"; ! j) L) C3 p+ b! v
8 H7 m6 z; g% p1 z* l// Iterate over the BOM Items.
# x/ B# y0 W# L2 cfor (var i=0; i<count; ++i) / k5 z" W3 R3 s7 |$ r
{
. B7 F1 T8 f( j7 N& u3 p/ Q// Get a handle to the relationship Item by index.
; @1 n" A. {+ Q) I7 q ?% S8 {3 ?: O var bom = bomItems.getItemByIndex(i);
& L1 F1 e `% w// Get a handle to the related Item for this relationship Item.
1 z' `; c) M& W9 e, | var bomPart = bom.getRelatedItem();
- v$ M4 u4 O! d! \/ ? % M+ K1 w) O8 T& _4 d/ I
content += "<tr>" + # }6 x1 T& U# z: w. G+ G+ @; I
"<td>" + bomPart.getProperty("item_number") + "</td>" + ' O- l: p7 a# c- f0 d- P
"<td>" + bomPart.getProperty("description") + "</td>" +
$ ~# u6 j- N3 I. f6 c% Z "<td>" + bomPart.getProperty("cost") + "</td>" +
_% k! \ S: h) c& u( d "<td>" + bom.getProperty("quantity") + "</td>" + " b! [, Z- h* Z& F+ w& M
"</tr>";
' V- ]1 J7 I( Y0 ^. g! g8 ^, {0 L}
2 V9 W/ m3 V& q" H$ V4 Mreturn content + "</table>";. B% K1 ~' h4 h7 B( b6 x
! Q' z' b, H0 {8 }% v: c4 N0 C
" v0 g" c* K, |+ Z" M% D' c, w7 X
% k5 {) }! K+ X" GC#
, i6 M1 H" e5 m& |, D1 UInnovator innovator = this.newInnovator();
8 u" u2 c4 |# b% b; y
3 \' `, g5 O" L) s// Set up the query Item.
; Z1 {" G; I7 r; zItem qryItem = this.newItem("Part","get"); : G$ P: B4 l) a. b# G
qryItem.setAttribute("select","item_number,description,cost");
. p- N+ V0 x1 J' O- aqryItem.setID(myId); 0 t9 `% W. \ j% G
0 x( t% ]3 R( y, {# B- D7 J
// Add the BOM structure. , Z0 J! o2 h- z! J" V
Item bomItem = this.newItem("Part BOM","get"); & `" J+ x, Q3 @& u
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 9 W. J G. j4 Q9 o; t
qryItem.addRelationship(bomItem);
( l6 X% F9 D$ b- G: {% F6 s
w! Y, V3 }3 ^. U* g( a// Perform the query. % O E, u" L1 H2 P0 x6 u; _3 A
Item results = qryItem.apply(); ; q0 w. ~) Q# ~$ L' s5 Y
4 \ L! _5 l7 \' P Y
// Test for an error.
9 S7 j& V7 l% M. F- xif (results.isError()) {
4 B; u- Z1 {3 @, a! | return innovator.newError("Item not found: " + results.getErrorDetail());
- s: @ W$ U D. X! D# A2 s1 M}
( a; m0 F' m% l$ b/ Z+ s- m * p$ c& U! }/ W, I
// Get a handle to the BOM Items. 6 f% @( d8 b7 t9 q5 j% _; u
Item bomItems = results.getRelationships(); , L1 V( ~7 B( D, ~; Y7 P3 f4 Z
int count = bomItems.getItemCount();
6 ?: W" d/ h' k6 uint i;
* U# ?) r# e% l+ i % T% ]* Q+ E+ l/ K7 B$ t# V7 \
// Create the results content. ! U9 x) M# `3 ^
string content = "<table border='1'>" +
$ ^; ^% x+ k; S6 B "<tr>" + 6 ?# u8 O: S' ~4 @3 R j/ ~
"<td>Part Number</td>" + 5 j+ V5 E3 m& `9 E; P8 x( A
"<td>Description</td>" +
4 L2 ]) V+ t, G$ G) c$ f "<td>Cost</td>" + ) [# h1 H4 Y2 M9 u5 a" X! ]
"<td>Quantity</td>" +
: D5 z+ l1 m+ Z" R f1 o "</tr>"; $ }4 R+ V/ N4 n
) F7 r5 H2 a& \' J+ y6 L+ w// Iterate over the BOM Items. ' v$ j; z( R' [- U6 S& I
for (i=0; i<count; ++i) , s5 A. S# g% `: X4 X
{
; n `" k. }9 u! w. @: c# u5 y" {, U a2 V// Get a handle to the relationship Item by index. . S x& E1 G* d0 n+ H( h
Item bom = bomItems.getItemByIndex(i);
0 X4 v3 Z/ K: J$ ?7 S// Get a handle to the related Item for this relationship Item. - w/ I# k1 \+ j! d% L
Item bomPart = bom.getRelatedItem(); # T! Q o+ D: B; z; U
2 e5 y- i& V2 Y- m/ v8 x
content += "" + ! A9 L) R- u+ o9 [: D* e# d/ \
"<tr>" + + L9 V1 o) L1 d4 m8 I9 i: O3 i+ @7 ]
"<td>" + bomPart.getProperty("item_number") + "</td>" + 3 S3 b! U" T$ ~
"<td>" + bomPart.getProperty("description") + "</td>" +
- b" j/ q& V z "<td>" + bomPart.getProperty("cost") + "</td>" + 3 C1 [( k* X" Z/ D/ |2 u
"<td>" + bom.getProperty("quantity") + "</td>" + + A' M, \; p8 r3 y- f/ L1 E$ w _
"</tr>";
! u2 B! b# {1 _- r* x/ i8 A I: n} * r; X7 [3 `7 P* ^) w& v& W
content += "</table>"; : `0 G! l7 X+ U. [
2 ]# U5 {( z! u. Ereturn innovator.newResult(content);
0 Z0 a: |1 q, Z6 I$ b) E
) p2 l! Z3 x2 k- E! J# M' ]6 `: m! ]3 y; N
* \' y8 O; r- r, o2 `# m
( }; ]+ U/ [. B$ X3 w
2 F; N6 n# V2 t
( k1 \* V/ T7 }2 }, G1 y2 C" P: }% w
+ U3 s9 ]. L7 c/ d4 x: Y J Page 46 , @5 I/ G K7 ]- }! S1 |
8 R! {4 l( J2 E# z2 H, \Copyright 2007
! }3 A( y# f) f- W9 c! F* OAras Corporation. 2 T: a, q5 P4 Z2 w$ m# b
All Rights Reserved. 6 v X, ] O0 L' }$ r m
VB.Net
* W( s% K$ l( ~) rDim innovator As Innovator = Me.newInnovator()
* O e- l/ @ }5 `0 R; j: a 0 d% I/ `* u) W/ I
' Set up the query Item. 5 W- {0 _6 h7 P
Dim qryItem As Item = Me.newItem("Part","get")
% M( O4 Z+ s( m1 ^% V1 eqryItem.setAttribute("select","item_number,description,cost") & m9 [$ |1 W/ k8 t
qryItem.setID(myId) % z' o3 b7 C) w9 E$ G$ s( _
X6 A+ E$ y. l# }* K9 I8 r
' Add the BOM structure.
: Q+ k8 w# F( A3 x; Q7 @Dim bomItem As Item = Me.newItem("Part BOM","get")
+ S t: w( f o# _+ y! j! LbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") + T% ?) {! E2 p5 [2 @) N
qryItem.addRelationship(bomItem)
* ?3 \" O- D( v0 e* v8 `5 U 0 _$ i- C4 _1 w9 P) y% H
' Perform the query. 2 X8 X6 f f( p. g* ?
Dim results As Item = qryItem.apply()
4 g# l6 ^8 G4 n/ N' z/ o7 q5 T1 F 1 s$ ]! @6 m0 \2 _8 f* {
' Test for an error. ; a. ]# v( o* K' k5 S
If results.isError() Then
+ ]: x/ x: q# S( Z1 | Return innovator.newError(results.getErrorDetail()) & t6 k* Y7 K8 r5 a' L
End If
, n* ?0 h/ ~+ G v8 t$ f e* u 1 _$ {* G1 B9 O+ a
' Get a handle to the BOM Items.
M+ l! v* D8 Z3 |- tDim bomItems As Item = results.getRelationships() , q$ O& b% e; d. d% h
Dim count As Integer = bomItems.getItemCount()
, r9 N* v7 _- U0 V2 ~2 eDim i As Integer
U1 B$ ?* e1 ?$ }1 f+ m % r. ~% W" ]& l+ C% ?1 ^3 D2 T+ u
' Create the results content.
% V5 g& ~$ F! A$ D e4 fDim content As String = "<table border='1'>" + _ ; T* D/ n5 u D
"<tr>" + _ ( z' ?1 F/ h7 ]; I
"<td>Part Number</td>" + _ 4 q! I _; B' B% p- {! z7 E" w8 A
"<td>Description</td>" + _
7 r% {+ G+ ~$ t "<td>Cost</td>" + _ 1 i U# l# W# S. Z
"<td>Quantity</td>" + _
{5 y3 E% F# s) e. R x "</tr>" 7 _. B# [3 q9 F' i* \- n
9 R/ o0 |* w$ M0 W' Iterate over the BOM Items ' o" t) B7 e$ [; p8 J6 W P
For i = 0 To count - 1
, q! t) c% o" L, k: J( T' Get a handle to the relationship Item by index. 0 U6 h+ Z7 j8 H8 c+ d8 f
Dim bom As Item = bomItems.getItemByIndex(i) ) i1 J2 U* e* `3 D0 _# P
0 f. A; n7 f% |9 A0 }, [
' Get a handle to the related Item for this relationship Item. , c' _# J4 A) y! Y- Y) p0 ?2 O, y
Dim bomPart As Item = bom.getRelatedItem()
; w* Y' b# ^8 U" k " d$ o% T/ z6 n- y8 p
content += _
$ \6 \1 T$ B3 D6 T$ o# Z "<tr>" + _
2 m5 k1 g: I4 X, P& T "<td>" + bomPart.getProperty("item_number") + "</td>" + _
2 X& @) Y' A, i2 p p4 b. d3 N "<td>" + bomPart.getProperty("description") + "</td>" + _ ) S& e4 o% f' \0 G% ]
"<td>" + bomPart.getProperty("cost") + "</td>" + _ 3 F! U6 \1 Q! Y+ w% H1 u3 r' J- x
"<td>" + bom.getProperty("quantity") + "</td>" + _ # w, I! X$ O% [8 Q9 Q
"</tr>" ! ?$ o) ^* Z5 C& f6 ?2 z
Next
' L2 i0 d O8 e) Wcontent += "</table>" 1 ^& M! {- }8 D( |2 j2 O6 w
2 j, t( d6 t, A- z7 t* Q) z
Return innovator.newResult(content)
' Z& r3 e# e7 ]% }6 B7 R& X+ D7 K7 V
|
|