|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 4 H" s. n' C& |3 l% v% N7 z
To query for an Item and retrieve its structure you build the query as the structure 3 z5 s1 j& S. W& _& A
you want returned. Use the IOM methods to add the relationships you want and " S7 {6 L, ]4 ]+ g& \
build the structure in the Item. The server will return the structure that follows the
' @- G; @! |3 g, x5 Y8 [' R- \request structure. - b" V+ Z8 S! S+ B
This recipe illustrates several related concepts together, which are how to get a set
6 G6 d" s* C* q1 E+ R' k+ ]of Items from an Item and how to iterate over the set, plus how to get the related / z) a5 S, {' A/ v Q8 r; Z1 p! a
Item from the relationship Item. + W" r& q: V* C
JavaScript * d' B7 ] @4 G, [( W
var innovator = this.newInnovator();
' k; Q4 _0 d3 G- V* @ ; N6 m/ j+ j2 F& Q- ~, ~. I5 x; K
// Set up the query Item.
9 s1 e* V5 P" z( g) T, bvar qryItem = this.newItem("Part","get");
, g0 N" E/ _, k! DqryItem.setAttribute("select","item_number,description,cost"); - l% l6 i9 L- Z" G3 [8 g, @. ]
qryItem.setID(myId); 0 M9 U3 I( \/ V% V
/ y W" e% t# \+ V# E- x c// Add the BOM structure.
: U; c- J: l* Ovar bomItem = this.newItem("Part BOM","get");
, a+ \. }) t. ?6 NbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 4 h+ l$ t5 A% n) z7 [
qryItem.addRelationship(bomItem); % q5 r' T' V) y) D! T. Z' I4 ?
, h' T2 D- o2 L2 e' B+ k// Perform the query.
3 D4 a7 ^7 t5 W7 N7 Xvar results = qryItem.apply();
1 ]* I) Z9 ]5 N6 }; r- O' n
3 x) [. ]' {8 o/ e& K' u4 y# X// Test for an error. % [! f. @: o$ v( G0 n
if (results.isError()) { z( i: c0 L U2 S: Y, e7 ~3 s
top.aras.AlertError("Item not found: " + results.getErrorDetail());
8 B, ~0 @0 ^$ Q( H) s) R% Q i return;
* a" h1 }+ O9 i+ J9 t0 _} " {+ H# p) M6 m! x) {# P5 D
& `5 p" r0 ?* p' {// Get a handle to the BOM Items.
: S# c$ W+ t# n, ~# m' Uvar bomItems = results.getRelationships();
1 o) d1 v8 _0 L* A" Mvar count = bomItems.getItemCount();
" \9 A+ ]* a5 I4 ^1 m& ^! _/ Q " l3 w( Z- ~' I1 y0 Y& Z% `
// Create the results content. / ]& _. C: {- n0 i
var content = "<table border='1'>" + & W; b" ]/ Q. p6 m$ _
"<tr>" +
4 |8 M h. j" N2 q "<td>Part Number</td>" +
0 P, y, K8 n0 \- g5 f "<td>Description</td>" +
5 q+ S- T4 E. i' k/ F "<td>Cost</td>" +
4 Q7 Q, @9 n& x7 T$ O z7 w h/ Z "<td>Quantity</td>" + 8 ~% L. }$ d& b& Z/ |
"</tr>"; % h0 R- }, q( X) g
) l4 U+ H: p% e8 d; E# ?, h// Iterate over the BOM Items.
7 p5 ]' j! k/ J2 Bfor (var i=0; i<count; ++i)
, \0 b5 X L; n1 M( ~; n{
5 H+ q' }; v4 }0 q// Get a handle to the relationship Item by index.
$ ^4 g. ?0 m7 S% E& T var bom = bomItems.getItemByIndex(i);
* ^$ m* k% s4 c5 _" ?. K// Get a handle to the related Item for this relationship Item.
: I9 _) ? U2 [+ T% V; b" F var bomPart = bom.getRelatedItem();
3 n- z% H$ g& Y3 W7 f . @ x8 A9 T3 _2 F8 G
content += "<tr>" + 8 K$ N0 C" z5 i M+ v: p
"<td>" + bomPart.getProperty("item_number") + "</td>" +
# T/ d) x H+ w* ~2 s( n6 F "<td>" + bomPart.getProperty("description") + "</td>" +
4 @8 H$ k9 S! F! Y "<td>" + bomPart.getProperty("cost") + "</td>" +
. k: e8 X1 d8 k: ?& u, H "<td>" + bom.getProperty("quantity") + "</td>" +
6 |1 o9 J. v! p2 W6 _1 }9 w "</tr>";
6 I8 {# ?6 |1 H- K} 6 a, U& e$ ~( J! ] ^2 i2 y
return content + "</table>"; O2 R# X( r8 B3 o3 B" u
- i" _7 p: a( k( J
]' M6 w, @' n0 p
$ _* o3 b2 m: c+ P3 R
- ]! e) ]+ l; \C# $ ^7 E" _( x6 l2 o! S- G4 i
Innovator innovator = this.newInnovator();
6 @: e2 j* D- ?& @" ~ - F1 I. e- f4 H
// Set up the query Item.
3 E: g* R% E0 T* z2 I9 _7 @+ {Item qryItem = this.newItem("Part","get");
v+ Y! G# K) t; I7 }qryItem.setAttribute("select","item_number,description,cost");
6 L( Z. V7 R' o$ I" n V4 y1 FqryItem.setID(myId); & h3 v* [" p- F3 | U$ O
8 O! ~. n3 Y$ `2 U) Q) H' L; }
// Add the BOM structure. ) r9 }" P# _" s6 n
Item bomItem = this.newItem("Part BOM","get");
: C& C9 N3 F& W0 w/ Z2 PbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
# `% S0 q) t5 kqryItem.addRelationship(bomItem); ) z. l6 M$ _) Y1 M. Q/ y
) i) e* D, ~7 x2 z: R# h4 A+ r, W6 `// Perform the query. * h7 y' i, M$ M) d1 e$ g( y
Item results = qryItem.apply(); $ P/ P/ L. r0 R/ X, N% h H5 W) U
2 U0 z+ K! N; }; @5 w
// Test for an error. 7 D$ A5 k$ P5 l
if (results.isError()) {
+ c" a- o+ {1 h2 N! b& ^ return innovator.newError("Item not found: " + results.getErrorDetail()); " ?" O, s3 v- g# K4 N. b9 x
} 9 ? t; H1 G$ Z; j& I: m, J
! g. k t ]8 D" M1 `// Get a handle to the BOM Items. - Q, h# f# D; B& ]' c0 r
Item bomItems = results.getRelationships();
" S2 z# I$ z- E4 o4 s) G lint count = bomItems.getItemCount();
& |0 L4 D4 A1 q5 b6 g- g( Xint i; . x/ R' L4 N3 t1 s& w4 }
' P* e6 N- ~( x A+ r3 q
// Create the results content.
9 H$ R4 Q" I8 `6 d6 |string content = "<table border='1'>" +
. F% g& {4 r( {# [ "<tr>" +
, h& }" T& [2 F# G& o! N "<td>Part Number</td>" +
# Z' |; e9 P% z; i "<td>Description</td>" + " j8 j0 \" w& R5 P
"<td>Cost</td>" + ( ^, {: j: v) D0 ^/ \( ]5 R: Q
"<td>Quantity</td>" + . E U N2 l9 }& ^9 O
"</tr>"; ' p: v- `# G3 }0 R& F
* d$ O( N4 ^# i) ^// Iterate over the BOM Items.
- S& B1 O6 ?5 m! r& O& ufor (i=0; i<count; ++i)
9 `5 a8 {. s& B{
' e" b8 h+ C" @3 n+ a0 U% h/ d8 v// Get a handle to the relationship Item by index.
9 L2 T4 ?! y( Y) _3 V4 D Item bom = bomItems.getItemByIndex(i); ( N4 U: Z) w" {" }; @5 y
// Get a handle to the related Item for this relationship Item.
) N4 R' a' J; s) I' f1 Y Item bomPart = bom.getRelatedItem(); " I1 T7 Q4 i8 G6 b% @1 \
0 q9 v* e* j6 X' q/ W8 |6 J2 F
content += "" +
5 \ [# n8 {$ L "<tr>" +
; t3 s( U( c- y& { "<td>" + bomPart.getProperty("item_number") + "</td>" + 4 h7 K6 T j7 _0 _" X0 ?, i* M4 [, I
"<td>" + bomPart.getProperty("description") + "</td>" + / X5 l) O0 o9 s0 p& c
"<td>" + bomPart.getProperty("cost") + "</td>" +
/ s. [2 R' g8 N) X( A) d "<td>" + bom.getProperty("quantity") + "</td>" + 8 v' ^* }! A3 H) a- j$ h
"</tr>"; " V5 ^2 S6 P* H- ~, J8 e
} 8 L; }" c& L2 N# b
content += "</table>";
+ _+ {9 R! c' E0 x. G9 X
' {5 Q; o6 }# L+ B# H$ creturn innovator.newResult(content); ; l: S3 f' Y1 c5 v
1 }9 z2 z* M& j c1 i
5 q6 O2 M' ^- O5 @( |
- H! s$ B/ B5 j8 M1 d# `3 c# B% O# {5 _2 H+ R
. o { s( m+ P4 |" g3 t4 P1 V5 M: z0 q3 z( [2 G I
' w$ v, _, _% c/ c& K
Page 46
2 X: R5 i& ]$ q3 q6 v% X 9 Y/ m0 F0 ~3 D2 W( A; N( ?8 ^
Copyright 2007
8 J( x5 {1 a( s X; P2 uAras Corporation. 5 E4 B" |' g$ p$ r0 S
All Rights Reserved. " g. ~; F- {' m" V' K! c
VB.Net
! z4 N$ G( W, q/ _; |Dim innovator As Innovator = Me.newInnovator()
: ?4 P: x9 \6 V& U6 n8 Z
- Q+ ^5 y+ W# e! m. W' Set up the query Item. 5 n! p% }$ |. C* p/ K0 J
Dim qryItem As Item = Me.newItem("Part","get") $ z; B. V& Q! m. _- T( u$ ~
qryItem.setAttribute("select","item_number,description,cost")
/ @6 D+ q8 E4 m8 Q( Q9 A" j6 rqryItem.setID(myId) 8 E: d2 \" w0 T; E) S/ \9 t
! C# r- F, x! R1 g8 d' Add the BOM structure.
, Q4 H' n. \: Z0 I s9 {Dim bomItem As Item = Me.newItem("Part BOM","get") " Z% h' m6 j/ _7 W
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") - f) k: P3 H4 u- \2 q# e3 z- z; }9 ^
qryItem.addRelationship(bomItem) 1 @9 [, y/ p2 t
* P$ N- g2 t2 {
' Perform the query. 6 H' d' B4 i: d y3 M) ?. u
Dim results As Item = qryItem.apply() 3 b. h0 Z; d" o+ ^* x# \
6 o- N( t8 i! U- O5 \4 ?' Test for an error.
8 }: S3 V% Q: f$ q7 b/ w/ |If results.isError() Then
: A* B; ^6 A [& b! c* X Return innovator.newError(results.getErrorDetail()) 3 z( S! ~$ J( _4 a' u& e% ?" {
End If 2 Q f. Y/ _* J: D N8 q
3 W w& h7 e5 g
' Get a handle to the BOM Items. : n1 ?8 N& O- ]- K
Dim bomItems As Item = results.getRelationships() ( `$ {& K. u/ ?
Dim count As Integer = bomItems.getItemCount()
% d5 O7 H; w8 I z: S$ u. Y# GDim i As Integer 8 G' [! u" w! g7 E, U( j
* L1 s. g, c1 a7 ?6 s6 p' Create the results content.
6 @ D1 a. |$ K! T( Q/ |Dim content As String = "<table border='1'>" + _ 5 I1 P! _% y8 Q: k j4 i
"<tr>" + _
4 l' I) _+ b9 K4 f4 G& W% P "<td>Part Number</td>" + _
2 V8 [- Q# K+ q$ m "<td>Description</td>" + _ 5 I4 W+ z7 c" S3 d! K4 o
"<td>Cost</td>" + _ % D% P% R, b& H+ }
"<td>Quantity</td>" + _ 0 b8 W0 `3 B% |! @4 _# O+ J1 P
"</tr>" , G4 W/ [8 [6 f: }6 P* U
4 w1 p+ O! M) K# R' @2 ?) q5 d' Iterate over the BOM Items ( S: u. ^1 U- h% U. f
For i = 0 To count - 1
% P1 v2 B; i. N; _6 _' Get a handle to the relationship Item by index. / o2 G4 R W* D( O+ {" M, }
Dim bom As Item = bomItems.getItemByIndex(i) - c& s1 E( D- B( i) ~) ~, \
) S d8 d0 V) V3 v/ \
' Get a handle to the related Item for this relationship Item. + e6 q" h3 C; f5 u$ c8 x
Dim bomPart As Item = bom.getRelatedItem() 3 d+ n' R8 c: W; S. A7 T
. I1 ~: {' F. d, z6 g9 h! t; ]+ X) m
content += _
& ~/ y5 @, Q9 N, l# U "<tr>" + _
4 q- D3 ~! _" h0 I; ]5 R% V "<td>" + bomPart.getProperty("item_number") + "</td>" + _
& F$ B& F4 X# C- o. { "<td>" + bomPart.getProperty("description") + "</td>" + _ 1 L& E, J/ W# J" q! P
"<td>" + bomPart.getProperty("cost") + "</td>" + _
' `0 g+ U" E6 I/ L "<td>" + bom.getProperty("quantity") + "</td>" + _ 0 H# W) i0 |& i0 j0 P
"</tr>" ! u2 c/ b( U: x- M$ e0 Y# }1 J
Next ( v, j6 i1 b4 z3 K8 z! ^
content += "</table>" ; p/ B7 L+ \( R0 w# R7 J4 X
/ t0 k' J4 s7 ^9 S# D( v
Return innovator.newResult(content)
! g, C" u4 A/ Q* U, a3 {: F
4 i8 Z" v# V) R+ Z |
|