|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 2 s8 h3 m/ u8 s6 P6 d
To query for an Item and retrieve its structure you build the query as the structure 5 A" P. V; a. w& r+ U, u$ ~$ `; E: D
you want returned. Use the IOM methods to add the relationships you want and E( a* L! g; F
build the structure in the Item. The server will return the structure that follows the " N* p: P% `6 O" w/ g( s
request structure.
/ D3 Y2 C. Y# b1 I* HThis recipe illustrates several related concepts together, which are how to get a set
# j, j2 I( x. Oof Items from an Item and how to iterate over the set, plus how to get the related 8 y: R% W5 r# x
Item from the relationship Item.
. @% K0 t3 W, D$ TJavaScript + ]2 |6 m2 a7 {' Y3 \% F2 n* x; I
var innovator = this.newInnovator(); ) Y* O a7 ~" o5 } c
) T$ e: x4 D# m// Set up the query Item. 5 f: Y$ q3 {+ l- {
var qryItem = this.newItem("Part","get"); 3 E. S+ x9 W7 `: K
qryItem.setAttribute("select","item_number,description,cost");
1 ~0 v6 A5 f, K Z" G0 FqryItem.setID(myId); * M/ O) O4 K V3 k
& ~: N# Z. l1 j% F" ?6 P
// Add the BOM structure.
8 d+ I! M3 \. @& Z" j, y! jvar bomItem = this.newItem("Part BOM","get"); . i) _) Y6 c( W& L. E
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); # s z3 t9 k. |0 O9 D, v
qryItem.addRelationship(bomItem);
# T+ n0 i" r) |6 Q5 V" |4 i
3 \' `6 K) q' v8 O: B0 @// Perform the query.
3 P1 C) h5 [% N# b( qvar results = qryItem.apply(); ( W' H3 L: Y" q! J( \+ J. ?
/ H4 L: q2 P+ \3 s3 i7 m% ?
// Test for an error.
: \" N/ Y& n$ Y* ~if (results.isError()) {
/ _* X$ i" [$ ` top.aras.AlertError("Item not found: " + results.getErrorDetail()); 4 }- u: i! W& u5 c! @1 n( d1 F. [
return; " [' q% i4 U! q8 C
}
* N) x* q0 Y' q6 F( E8 g+ X* i
0 ^% B8 H3 `; ^5 ~// Get a handle to the BOM Items.
6 q/ N# l( T( b1 m' ~& L S Hvar bomItems = results.getRelationships(); ! D' z: K$ ?# ~% |6 P' E
var count = bomItems.getItemCount();
6 ? D4 s0 _+ K% j # P$ j; G# G8 j4 y
// Create the results content. 7 m f& A( l! b& D; k0 x9 [
var content = "<table border='1'>" +
- T7 M; k! C' x, Z. ]% C+ T "<tr>" +
9 I. A$ n1 O: M$ I "<td>Part Number</td>" + $ A9 ~1 I( r) }- b2 k
"<td>Description</td>" + + l6 T$ h! r8 [7 n" H
"<td>Cost</td>" + * y! A$ M9 M2 F0 ~% I
"<td>Quantity</td>" +
/ Y, U1 V$ H: w4 w "</tr>"; ; W- Q% H9 o% I) b$ ~
& }- x9 n! x3 m2 {; `// Iterate over the BOM Items. + h; t* V$ b* t! A2 u' Q: [6 K
for (var i=0; i<count; ++i)
$ g( S8 p% B5 h{ ! M# F# ~ H" ?. h2 v/ i
// Get a handle to the relationship Item by index. - u6 a3 e, d# d. |5 A3 l
var bom = bomItems.getItemByIndex(i); / w5 e t, u' w4 }/ e7 s
// Get a handle to the related Item for this relationship Item. - `4 t, R* X) E6 X
var bomPart = bom.getRelatedItem();
, V3 t0 T3 a. l" w+ [9 h' f( k
. I. x1 k+ l6 X) H content += "<tr>" +
/ T+ {: O" S- q4 y "<td>" + bomPart.getProperty("item_number") + "</td>" + 0 x+ n7 e" G; U+ U: e
"<td>" + bomPart.getProperty("description") + "</td>" + 0 ~+ C( G* n. |! H. j# z% O3 R
"<td>" + bomPart.getProperty("cost") + "</td>" + 4 G" M& E; F/ s# I3 B
"<td>" + bom.getProperty("quantity") + "</td>" + 8 y1 ]. n) y8 T! _% Y( l
"</tr>"; - s1 I" W7 X1 d0 L- I
} 7 P5 P5 g$ {$ r1 r6 r4 x
return content + "</table>";
* Z; ` v7 a% B# u! o; K7 z& b: e
0 K2 i, ]4 f8 U/ {! p& c( r+ r3 S" T" z
5 _9 @# {4 ^9 @# a8 n8 ]7 ^5 W# d3 S* r8 r1 Q
C# ' i0 r$ _; A6 O0 b) n2 H( B
Innovator innovator = this.newInnovator(); 9 a) D+ s% |) r8 \8 [. M3 g8 H
1 w' K* m$ {, z: g, c# E3 {& p* ~8 z& D
// Set up the query Item.
. z( M. z, A) S7 M, `$ Q/ }Item qryItem = this.newItem("Part","get");
, w' l/ H6 i; h' \ XqryItem.setAttribute("select","item_number,description,cost");
: {: n! d% }/ q7 X. I5 fqryItem.setID(myId);
1 F, }# V. p# ~) _5 i 4 @" b7 B$ ^7 i! t/ [: \8 M# w
// Add the BOM structure. " V3 c) _6 u: f& j, n
Item bomItem = this.newItem("Part BOM","get");
3 ^, Y% H3 }; w; q. L* q9 r1 p# W% abomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ! E4 }# \: H8 N% a% }0 b% y
qryItem.addRelationship(bomItem);
; J8 P2 ^3 a. @
- P8 m$ z8 j& S* M// Perform the query. 6 ^0 s6 A& M1 t9 v! b. `
Item results = qryItem.apply(); 0 K1 C1 S3 L$ y( o
- L2 f3 G, S0 m2 u' l// Test for an error.
, ]6 ~( w+ J! p3 C' y9 Vif (results.isError()) { + m8 S) i. S1 t* C
return innovator.newError("Item not found: " + results.getErrorDetail());
0 b/ ? ]9 Q9 U" e) U9 u/ J: v M} " {6 J* s3 E! C6 i; l, M: K
2 k2 D2 A5 a5 I! x) T
// Get a handle to the BOM Items. , K \8 r1 k. e9 x
Item bomItems = results.getRelationships();
/ E* D% m; T8 [int count = bomItems.getItemCount(); - e4 U+ \7 P3 }/ ]+ }0 H4 F9 z
int i; 1 v, D8 D8 X9 z
8 p" n$ Y! Y- h. s// Create the results content. ' w5 j# Q: ?* t8 A
string content = "<table border='1'>" + S; z$ u0 L1 { ?
"<tr>" + 5 _( E5 h% ]4 ]0 D% ?
"<td>Part Number</td>" + ! p* Q ?% _ E ?% J7 }+ \. S7 l% T
"<td>Description</td>" +
, \! x) H! h0 C8 }4 w "<td>Cost</td>" +
, N- x; v- D7 D. {% u/ R "<td>Quantity</td>" + * |9 |+ {& J; G. Z
"</tr>";
; N1 |2 ~8 a2 A3 J
9 h1 X+ H. j9 ~+ |8 K+ t( D// Iterate over the BOM Items.
4 O9 S% x8 m4 P% cfor (i=0; i<count; ++i) # U* N {8 P( S9 n
{ / x& F e) p4 D g. h) a
// Get a handle to the relationship Item by index. ; e) T% E0 X _; n2 [
Item bom = bomItems.getItemByIndex(i);
# |' M1 y: T6 J: K7 h// Get a handle to the related Item for this relationship Item.
/ d) x* o7 V9 s U8 J l; Y Item bomPart = bom.getRelatedItem(); 9 n/ g/ o, ]) r- b2 v. c2 J
" w( V! |/ E0 r" z& f
content += "" + ) t, _3 U$ n* E* N9 u' O
"<tr>" + # j0 @1 s; a% A
"<td>" + bomPart.getProperty("item_number") + "</td>" + 5 X; j( g/ A+ C# h
"<td>" + bomPart.getProperty("description") + "</td>" +
3 f: Q0 P! J+ l5 ~7 ~- c( E "<td>" + bomPart.getProperty("cost") + "</td>" +
1 _5 ^1 v% ? D "<td>" + bom.getProperty("quantity") + "</td>" + 8 S, u4 H: C( U! t: E) A
"</tr>"; ' B* y" b% f R1 Q
}
% C$ j6 k8 P& j+ B" f6 Vcontent += "</table>";
( H o: z7 G" }; h9 s3 t
|/ `0 _7 N1 m' d3 S- V, {return innovator.newResult(content);
4 W4 u5 t% q, c, L# E0 t! e9 u0 n. V5 _4 K& q" I0 Q h' j
! _0 s+ }+ t9 q* ?; g
: q* A" m! b9 w+ G
( ?3 C6 Q! Y" Y. w3 r
! n( G8 a( q6 g0 H0 a* y' V
+ \* @+ o: |1 D# `9 A4 c4 P
. _ ]" R3 e* ] V Page 46
0 {, _0 L; ^0 J% c 2 w0 \+ v: s% y# O# G; Z. ]3 E
Copyright 2007
; O1 c5 @3 U% b+ w5 |: zAras Corporation.
1 O7 E; E( q% e6 K$ }: L4 \All Rights Reserved.
" U' p- ?% W) D" n" B9 \1 \VB.Net ! d9 e+ q5 v6 A3 m; q
Dim innovator As Innovator = Me.newInnovator() / f) y! o* c3 P+ E P* j
# P/ P: [. x0 l# X' Set up the query Item. 1 U+ g5 A, O, K1 P
Dim qryItem As Item = Me.newItem("Part","get")
7 i9 }' g4 D' n- b2 e* [* [qryItem.setAttribute("select","item_number,description,cost")
; I2 N' p2 e, @0 HqryItem.setID(myId) S1 V4 D# @/ k$ B
% W5 U# R u, t
' Add the BOM structure.
. j/ K3 X4 A }Dim bomItem As Item = Me.newItem("Part BOM","get") : L/ P* k" H6 l0 c2 Q# w. q
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") # o& V q9 d" j, F2 V4 e
qryItem.addRelationship(bomItem) - e3 y9 z" U! o; H4 z
6 `, H7 n( e9 f, N: X: B' Perform the query.
A: E/ ?7 I7 ZDim results As Item = qryItem.apply() ! P+ L& l. A- y
, Q. J$ c" f+ ~% @+ n
' Test for an error.
" x$ t" n) J$ B& }: C6 _$ MIf results.isError() Then
7 T! D/ v4 A4 [* Q2 z$ O. g$ A Return innovator.newError(results.getErrorDetail()) - m" v. n8 y& c3 p
End If 8 b" ~& J( x% ~" r
% m( U) W3 H) Q) J' u6 e8 F4 p% l
' Get a handle to the BOM Items. 9 Z9 u5 y6 B2 `; a6 k# u7 a
Dim bomItems As Item = results.getRelationships()
- O, L1 r$ L$ F7 Y. b0 M# b/ QDim count As Integer = bomItems.getItemCount()
6 N5 Z+ M8 W ]5 G, GDim i As Integer ( H% ~ z7 f. D/ `& |' l7 `( @
0 \9 p. P6 d! k# F0 ]' Create the results content. 0 a' M- t- M& {. P0 r8 d
Dim content As String = "<table border='1'>" + _
6 `& h! Q7 m+ u( T "<tr>" + _ , ~0 R$ ]1 K' x; Z) r/ ?% {0 S
"<td>Part Number</td>" + _ $ J( _' t3 l/ T$ B
"<td>Description</td>" + _
! J1 \5 h% K7 v9 _" } "<td>Cost</td>" + _
5 N+ }& P0 g$ g/ U: B "<td>Quantity</td>" + _ / v+ @0 C4 z3 g! f3 s
"</tr>"
% M# G" Q/ l) A9 o 4 S: a6 B" E( a' S. J/ a, m% {
' Iterate over the BOM Items 5 n. W, D" V1 |
For i = 0 To count - 1 ; E3 D. V' s1 T$ i7 u
' Get a handle to the relationship Item by index. : q' D' W8 R/ M* O' F2 }0 p+ P
Dim bom As Item = bomItems.getItemByIndex(i) 6 i4 j9 c$ ~* j |5 l
( N" Y' A# \: L3 F' Get a handle to the related Item for this relationship Item.
1 k8 K( B! }/ {3 d0 f Dim bomPart As Item = bom.getRelatedItem()
& ` y6 D+ d1 q2 x; y9 V
* C2 g4 y; S' O0 J P content += _
) X1 D" S3 J. R& W "<tr>" + _
- S e* ?1 u' D- b5 h3 m9 ^; y, P4 l "<td>" + bomPart.getProperty("item_number") + "</td>" + _
5 T, \/ g& q* d0 B! r "<td>" + bomPart.getProperty("description") + "</td>" + _ 5 N) r1 N* K( I- w5 `# u- {$ S
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ' t* f, F, F7 n3 S# O8 w
"<td>" + bom.getProperty("quantity") + "</td>" + _ 9 J' @) @: U4 ]% w& n
"</tr>" 1 G* y- c0 i3 {) G
Next 3 |6 ^0 [8 ]: S9 `/ E* z
content += "</table>"
9 w( u9 H4 c( |1 X
+ }! F2 b) ^8 o7 eReturn innovator.newResult(content) ; [/ @; s% z' `8 {/ u
. ^# J8 Y7 V, X* z8 j1 {2 k% B
|
|