|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 9 E1 z K+ p2 i( ^: R, n7 O( n% L
To query for an Item and retrieve its structure you build the query as the structure ( V `& _6 u" m7 H: `, y
you want returned. Use the IOM methods to add the relationships you want and
& `) {0 ?' U- b4 k Lbuild the structure in the Item. The server will return the structure that follows the
( H0 j6 [) f Y. j7 h+ }request structure. ) c( w- X9 X2 X8 j: p" \0 V
This recipe illustrates several related concepts together, which are how to get a set 8 y+ u7 x1 A: T+ H( t+ ?) P
of Items from an Item and how to iterate over the set, plus how to get the related 4 U; r3 ^1 B, H% S
Item from the relationship Item.
. X9 G! U3 Y. g* o# NJavaScript # b# ~+ J$ u5 V$ w: Y9 p* V* {
var innovator = this.newInnovator(); ' ?. `1 u0 G' z% {% Y) }
% {* t- m1 @/ z
// Set up the query Item.
; _2 ?. n3 `+ b+ w9 s" t* Fvar qryItem = this.newItem("Part","get");
& d9 x# X6 u$ O- k; E' n5 y8 DqryItem.setAttribute("select","item_number,description,cost");
# _1 }3 b" O, o {, Q1 EqryItem.setID(myId); ! K) y6 u5 M4 W
! Y( |2 b, ~3 p* o// Add the BOM structure. 8 u; E/ `+ T" i* z6 X- `" h
var bomItem = this.newItem("Part BOM","get");
4 `/ E1 G |6 A3 c- ]4 e4 NbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); $ S/ ]$ W7 x$ {* b% w7 y0 c
qryItem.addRelationship(bomItem);
7 W+ r( F H0 _! f" w . x5 F% `- l' P; y: ]3 t
// Perform the query.
4 D+ b4 X$ e @5 Evar results = qryItem.apply(); 1 k( |6 n# c4 w( J+ l
0 F; C9 P( C$ V) }& Q8 X
// Test for an error. 1 F6 x# Z, X* n/ Z$ j7 A+ ?8 H% r+ O
if (results.isError()) {
4 u$ c/ V S$ w2 y top.aras.AlertError("Item not found: " + results.getErrorDetail()); ( f9 g* O+ ] J
return;
( h( Z& g! H1 ~# {}
- l$ x+ K- T- I( N. D " F/ ~$ Z( H/ s! H$ F& o. d2 c
// Get a handle to the BOM Items.
' K z( {3 s9 u# C; Bvar bomItems = results.getRelationships();
! C7 P8 _0 Y9 w) V+ d$ o- G- bvar count = bomItems.getItemCount(); 4 y/ x0 O! d8 W1 `, R% H
* b: {% M( s) f4 T0 y$ P6 A) H! D
// Create the results content. . U7 t8 b5 m; v8 k8 _) W, n
var content = "<table border='1'>" +
! H, g( g) H" X/ v' R1 n# g9 [9 t$ I( _ "<tr>" + ; P" C( R$ o B: T) K1 `
"<td>Part Number</td>" +
# \# P" ]+ m# W8 c "<td>Description</td>" +
$ d( S$ O& s. I "<td>Cost</td>" + - E. m* `5 Q. Z$ Q" m4 r, @
"<td>Quantity</td>" +
$ M4 c, B; Q% O" e: l N, I5 g! R "</tr>";
4 f: a( E n+ o) A! E: D1 s+ R
# v1 Q' f- W3 O J1 R* F8 M! `// Iterate over the BOM Items.
$ _, a, _2 R1 P2 q1 }5 }for (var i=0; i<count; ++i)
' J! J3 n( i4 p" Q1 {{
6 L6 x& h- G( m5 `$ i7 y// Get a handle to the relationship Item by index. ' d4 C( g9 s# K2 k- Y% b; l/ [6 z
var bom = bomItems.getItemByIndex(i); 6 _7 [ q4 {2 E# @, G2 F" [
// Get a handle to the related Item for this relationship Item. + t6 k$ V3 k) L, Z% o
var bomPart = bom.getRelatedItem(); 9 N/ @' W0 f9 z- u/ @; t
% r5 i2 [% V/ a* u& c
content += "<tr>" +
' [; W* g6 I& l* i+ N "<td>" + bomPart.getProperty("item_number") + "</td>" + ) }8 L" ^' @9 O
"<td>" + bomPart.getProperty("description") + "</td>" + 1 B4 v7 r* V- \- K
"<td>" + bomPart.getProperty("cost") + "</td>" + 9 Q% j0 F& G7 r4 K( I1 S
"<td>" + bom.getProperty("quantity") + "</td>" +
# `, G) ?$ N+ V/ G2 ~: ?7 k* q "</tr>";
& U- }; [- A) v+ X}
/ O5 E1 z. o! w- g/ T$ o/ o) B* \return content + "</table>";% b. s, |' t2 X2 @, b6 t
; \" R# f* _/ |1 c4 n6 f# J8 c! d2 A
3 M7 [# F5 ?9 l4 v2 D: ]4 ^4 w9 t7 J& K7 J0 J
C#
/ m/ |4 K3 q" x1 O6 K- I9 AInnovator innovator = this.newInnovator(); 2 y% ?8 L: ^2 g! ^
. R6 Z% `3 z/ r1 U
// Set up the query Item.
, _1 N: s, u4 D/ @; U, Y7 `4 n2 s) X# FItem qryItem = this.newItem("Part","get"); 7 O4 e1 o8 S1 K& ^- }- `2 b* z
qryItem.setAttribute("select","item_number,description,cost");
# E$ A; g0 E* M" a; L5 ] oqryItem.setID(myId);
& ~ I# T, X: X6 S' v 8 R; b }5 X( o, X. [
// Add the BOM structure.
! v* |% r/ {6 nItem bomItem = this.newItem("Part BOM","get"); 3 b& ]1 {, H. v: k [0 R
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
: Y L- I6 f* P5 {7 y. OqryItem.addRelationship(bomItem);
' r# q! m- O! d1 J8 }4 i8 m 3 ~" c; i% v$ n3 h5 Y; d
// Perform the query. 2 c0 c: h* ]0 c" r H
Item results = qryItem.apply();
" g! F6 @0 g$ m% {3 x5 k" h2 B
% N# [! C* a& m: W8 c" Z// Test for an error.
- U, B' ?/ _. Y% w5 l1 ~if (results.isError()) { 8 e7 e3 c% c% v! f1 F
return innovator.newError("Item not found: " + results.getErrorDetail()); ' k5 }* [) J. D) N, s- Y l E4 J
}
7 q: q% P" s- a+ P; ~
1 [: S# ~% ` M5 x5 y: r// Get a handle to the BOM Items. $ W! v: G6 p) `
Item bomItems = results.getRelationships();
, p- F, q1 z* ~% Iint count = bomItems.getItemCount();
0 T( n# P4 u+ x2 m' \$ ^, S2 Sint i; , U9 f, y& |, i3 X# @
' G% }$ p e4 C! B, M2 E5 ^9 u
// Create the results content.
" [3 S! c' @6 o2 Ystring content = "<table border='1'>" + * ^! J0 S, r# H1 L$ \% z" }
"<tr>" +
" S! p( ^& E4 c" U "<td>Part Number</td>" + ' Q* G4 H1 T, Z
"<td>Description</td>" + " i0 |- o, C; F8 ]* n X( h8 z
"<td>Cost</td>" +
1 F8 j1 a7 x3 e! z& @( l! o "<td>Quantity</td>" + + c% V4 j4 |: L* c( q) @
"</tr>";
6 L v" R9 N, L+ z4 V; ~0 p5 q" e W
, C+ r# i$ A: `// Iterate over the BOM Items. 3 h. H# M5 X W: {
for (i=0; i<count; ++i)
4 f( Y' A0 Q+ X" {3 A{
1 {- K5 a" h( {& C& i. ?- p// Get a handle to the relationship Item by index.
$ s* ~0 m* b& ?5 ?5 v- g Item bom = bomItems.getItemByIndex(i); 7 p) n- t1 x: j6 u+ n+ y
// Get a handle to the related Item for this relationship Item. . u1 u) l, N' F; G
Item bomPart = bom.getRelatedItem(); , p5 m9 g: C& i
% q; N2 ?+ {3 [2 G7 {
content += "" + " M5 _9 u, v' ^
"<tr>" +
/ y3 J& V9 ^4 y D. z8 @: a "<td>" + bomPart.getProperty("item_number") + "</td>" +
; q/ r4 S. Y& P, {" N/ R, h "<td>" + bomPart.getProperty("description") + "</td>" + 1 N, P# ^" ~' D
"<td>" + bomPart.getProperty("cost") + "</td>" + 4 F4 w7 C7 Q4 ~( [8 k, K
"<td>" + bom.getProperty("quantity") + "</td>" +
. K* J8 f4 t( }9 ? G+ h4 v "</tr>"; - {" e: K6 c+ F2 n# E* L3 ^
} ! S. ]0 O4 n% t+ M
content += "</table>";
; Y% V4 F" i5 _% R# s 7 K) [- T3 e7 P( W. r
return innovator.newResult(content); 3 q+ g- q9 `5 F+ v* ` @
* y5 d+ ^! ~* B! [, a
. \* N6 g% O4 ^. K
' `' m1 Q8 m' _3 @7 ~- m& S) T! k9 M! S4 |
" `+ e7 z$ z6 y
3 q; G2 @' | h( Q! a+ F
. M% y; n6 F6 r! U$ D! a Page 46 ) y2 l% V' O+ a+ N& o3 |' b& G
# e" k, y0 b8 e2 F6 r' ?# i- iCopyright 2007 8 ?6 ?7 i; T. O1 E9 d! h6 U
Aras Corporation.
) D) `( A" B: W& AAll Rights Reserved. / j4 a2 x, G F: n: W* j
VB.Net
3 C: f, N$ D; \$ xDim innovator As Innovator = Me.newInnovator()
. R* N7 u, X& C, B4 S9 g " K+ `/ w. ~1 F4 z$ O
' Set up the query Item.
& H9 J4 @- M' F& m) N! LDim qryItem As Item = Me.newItem("Part","get")
, e, r5 f0 ^3 P1 e, }# CqryItem.setAttribute("select","item_number,description,cost")
[$ C) l7 @# S' u, rqryItem.setID(myId) + N R' H& ] T" z5 w
7 f: q: K1 l1 N3 U/ V
' Add the BOM structure. % v$ b9 \7 j; r, Q. H" [' ?! i1 V( J
Dim bomItem As Item = Me.newItem("Part BOM","get") . ]" ^" ]+ c4 _4 o7 z, T
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
+ t6 a1 [/ m4 T: T4 w+ [1 j7 MqryItem.addRelationship(bomItem)
" T9 p; k2 C- h0 h2 f! q0 ]
- o2 u+ z0 b9 j! @' Perform the query. 2 d' w! U2 b4 C& B" h N+ ?6 R
Dim results As Item = qryItem.apply()
7 q5 J; K2 x2 ]2 n
% S, Q3 r. t; j+ p( f' Test for an error.
1 t; o, X5 H) _ E2 L: ~If results.isError() Then
0 O/ k, P0 s$ F9 l/ {- [1 ~; `% i Return innovator.newError(results.getErrorDetail()) 3 L7 Q" a, c: l/ I8 N
End If
. \; v3 ?$ u) {) d. z' Q
- Y: T9 Q1 I) Q# l' Get a handle to the BOM Items.
# \( P6 K- c) Z- \- R+ kDim bomItems As Item = results.getRelationships() . W4 k" l, {7 l+ ~
Dim count As Integer = bomItems.getItemCount()
0 [; K0 b; r6 B/ [, j# J( f! YDim i As Integer
7 A+ V C9 z$ @( h( ^4 [' f
9 G4 d* H. ~$ v; x3 j' Create the results content. 9 M u9 e6 l4 @5 _4 ~ }9 R
Dim content As String = "<table border='1'>" + _ 5 L! H' F& Y# H: r, Z
"<tr>" + _ , G! J( u3 z: s2 p2 c
"<td>Part Number</td>" + _
! f1 v" _6 v) X6 r, J "<td>Description</td>" + _
2 _5 x" \1 k( `$ `1 i* y2 I" H "<td>Cost</td>" + _
& _( R0 e" L4 B5 X2 ~ "<td>Quantity</td>" + _
! F+ t Y5 k7 Y, N7 o "</tr>" * g" c& w: |! s* q0 d6 d; \/ x0 R& Y
* {3 m$ e( y' ~5 M: U; U4 O' Iterate over the BOM Items 6 a7 U: [& y w% i
For i = 0 To count - 1
y' Z' }) F5 P1 j' Get a handle to the relationship Item by index.
8 m0 o5 M, _) P* P$ @! V( R Dim bom As Item = bomItems.getItemByIndex(i)
) S4 K# m5 L1 y2 m- j; n/ U0 _$ x
* _: x9 e5 `; S- N# E* q' Get a handle to the related Item for this relationship Item. i+ w/ y4 x8 ?: k' f1 W/ I* E
Dim bomPart As Item = bom.getRelatedItem()
7 {' k e3 q1 Z2 H" G + u0 ^! E& z8 n& C! `
content += _
3 H* r" w2 m; P1 {( K "<tr>" + _
" ? t" R# r2 I! ]5 J( I "<td>" + bomPart.getProperty("item_number") + "</td>" + _
. t3 r0 N) N4 V) e ] "<td>" + bomPart.getProperty("description") + "</td>" + _ 6 U7 H7 V# Z8 R, d4 [; K
"<td>" + bomPart.getProperty("cost") + "</td>" + _
1 l9 C( b2 _7 l/ L "<td>" + bom.getProperty("quantity") + "</td>" + _
: ~" h% |' |3 Z' F( R# L "</tr>"
4 v" e- I; c4 LNext
9 u' q& v$ d }+ E- Vcontent += "</table>"
0 y5 R, j9 t6 \( b. F. w% j' D 4 ^# U1 U8 K: ?# p9 c
Return innovator.newResult(content) 2 ^- M/ `" f7 z7 d6 p
+ |# ]' h* V5 I9 f |
|