|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 6 {$ ^4 [$ z9 ~) S2 Y
To query for an Item and retrieve its structure you build the query as the structure ; C% j: H9 G" e: i# a7 B
you want returned. Use the IOM methods to add the relationships you want and
6 i* a1 d. Y" S3 [8 Rbuild the structure in the Item. The server will return the structure that follows the 8 {. e/ j/ f8 x. G* s3 C g
request structure.
5 _0 m6 b' k$ U8 JThis recipe illustrates several related concepts together, which are how to get a set
# }( q+ w/ }9 Q, v' Uof Items from an Item and how to iterate over the set, plus how to get the related ; Y/ R7 f$ S2 s7 p# `
Item from the relationship Item.
p, y- Q; j' F4 oJavaScript : w* b4 Q. ^" F, W
var innovator = this.newInnovator(); & M; e/ @& J) v" U8 {9 I
- ~: H+ H$ _. G1 {: j: N9 p5 B
// Set up the query Item.
" K7 l! B2 z7 o D9 u: e' G! Vvar qryItem = this.newItem("Part","get"); * ~ w2 ^" A5 Q9 L' V* r1 c
qryItem.setAttribute("select","item_number,description,cost"); 8 b2 R2 b& G0 I4 {" ?" K T$ c+ \
qryItem.setID(myId); : Q1 `9 }7 @& T. O. Z, d
5 b' n7 b& n q2 ]6 E$ Y
// Add the BOM structure. 4 w6 P( m/ w2 t2 V, Z3 j9 _. s& [, r
var bomItem = this.newItem("Part BOM","get"); 5 B& m9 D, E% ?7 S
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ; i$ ]2 q5 U4 T7 h" p
qryItem.addRelationship(bomItem); [% Q& M5 o5 l8 B2 _, F7 Z M
$ V9 f9 O- i R9 R// Perform the query. 5 i9 w# m( K; E4 n- O6 r
var results = qryItem.apply(); ' p& }7 j( S2 K6 @, D/ R: _
" V; E3 i( `: c% \: @// Test for an error.
: P9 k4 T8 B8 L: E) Z; x) `6 Rif (results.isError()) {
3 ~9 q7 n/ }" a' z' i top.aras.AlertError("Item not found: " + results.getErrorDetail()); " q% C. t( |7 \; a, G: G# [
return; 9 b6 w% S8 q' s
} 4 a. |5 l7 u G7 h* |
2 Q+ |2 v8 L7 }7 C( |2 L
// Get a handle to the BOM Items. , k# C% h% F% p$ p
var bomItems = results.getRelationships(); : E$ z& A+ M3 l
var count = bomItems.getItemCount();
) z( m0 d" F& p: n' P
) R. q" t* n4 b6 I& H' ?9 v& Y// Create the results content.
, H% ~' ^3 [0 F4 g- Tvar content = "<table border='1'>" + " C* J7 j( d, Z+ T6 o/ c. b
"<tr>" + 2 V$ i1 f! k* [5 U' G) F. ?
"<td>Part Number</td>" +
" T$ C; n. t8 s. c8 _, g "<td>Description</td>" + 3 F9 [2 Q- ]1 l. u. X
"<td>Cost</td>" +
$ ]# ^# D0 e. H0 Q3 A6 x6 s "<td>Quantity</td>" +
* J" d/ m0 H- g- T9 P/ H% @9 m "</tr>";
1 O8 C6 [3 N7 `& P% o& b ) B3 C8 @) z3 C4 w( {( b% D
// Iterate over the BOM Items.
! u( A$ u F5 G5 ]5 Wfor (var i=0; i<count; ++i)
1 r: M5 b7 n) q8 N) N/ y{ 3 b! g2 k; V* {' p" H6 r
// Get a handle to the relationship Item by index. - I0 ?$ h- K1 g& V
var bom = bomItems.getItemByIndex(i); , q% V3 Q% a4 q
// Get a handle to the related Item for this relationship Item.
) V5 o( D/ L+ ^ w( g" ^% z1 T var bomPart = bom.getRelatedItem();
6 h+ R: I% F b8 ?
9 D8 j* E! w& U3 T U! H content += "<tr>" + 2 U. |9 \: I# e7 `/ k/ L9 N- [
"<td>" + bomPart.getProperty("item_number") + "</td>" + 4 f+ Q9 B9 Z7 g2 X# y$ R# a0 [
"<td>" + bomPart.getProperty("description") + "</td>" +
' K, B; N" R! r# N8 A0 o: D' b/ G4 u "<td>" + bomPart.getProperty("cost") + "</td>" + 6 C, z- q. P) W. ]: ^
"<td>" + bom.getProperty("quantity") + "</td>" + ! k$ s6 O, I) G0 T L9 v$ |
"</tr>"; - c3 q2 V3 z: [0 d4 |
} , `8 T4 Z+ z* j z. C6 M$ Z
return content + "</table>";
: Z% W& k0 V# o! L5 u6 Z0 a
. C. w" X3 M/ c3 r. k; g
8 U$ ]( _* `( t$ V! ?& v) o$ K) |& ]" W2 ]% U( k; ~
8 v4 {& [ s, ZC# 2 y5 h( ~; T! s- t% q* t* W
Innovator innovator = this.newInnovator(); 5 Q0 u8 T. t: l
$ o @4 }/ _8 s& T// Set up the query Item. * N2 j6 m' \% U* ^) d8 F. N
Item qryItem = this.newItem("Part","get");
0 y6 B( b; Q" t- rqryItem.setAttribute("select","item_number,description,cost");
- |% T6 @- t. ?6 A d/ P5 j/ R2 [qryItem.setID(myId);
! ]; C: ?0 n9 r3 q3 t% i! s 1 y X6 f5 n- m- q4 f: E
// Add the BOM structure. ; X! q6 g' ^4 n! u- n$ b! @- z' k' Q
Item bomItem = this.newItem("Part BOM","get");
( l# x% M/ A& c$ M& a) ~8 S( FbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); , F, \" e( d2 `
qryItem.addRelationship(bomItem);
9 \6 q, s) b @% k# G . ^( W% N% L, {
// Perform the query.
: k2 u( x- `. r; B& iItem results = qryItem.apply(); 6 j0 L5 D, I1 ^/ G; Z2 C
, Z) U( I3 o) @( ~// Test for an error. & ?0 h; I, j/ [; p
if (results.isError()) {
- N$ f2 T# a# h- W9 ?, a6 k1 ]0 { return innovator.newError("Item not found: " + results.getErrorDetail()); 0 X' \4 o( J5 V0 \* O
}
1 I# \! Y4 n, t% D & q) f& I( |; z
// Get a handle to the BOM Items.
' k/ _* T7 [7 U3 b& G; {0 y( d4 v0 G; cItem bomItems = results.getRelationships(); 2 W8 I+ X. S+ s2 Q" h& N4 S0 i
int count = bomItems.getItemCount(); " q; {, Y+ j5 E. c. h% Z/ {
int i; 2 } ?$ L$ e" W J
) t+ D3 K+ u5 t# @0 g& |// Create the results content. 5 t) `. y1 n* Z; W
string content = "<table border='1'>" +
) Z/ M% w0 @ ?" I" B "<tr>" +
& {0 ~$ Q9 z7 p5 G7 D: u; Q! w+ K4 C "<td>Part Number</td>" + 3 J: x4 |! c2 t0 W) H& `
"<td>Description</td>" + & \, H$ e2 B- S9 c2 `
"<td>Cost</td>" +
u2 m D" j' x/ x8 O' } "<td>Quantity</td>" + / S3 C7 [8 ^; j5 m- Q7 u
"</tr>";
. w9 a* s" t# Q1 v/ s
' Y. L% i2 F# |6 i1 W3 f// Iterate over the BOM Items. 7 r& X9 f* a. U3 C# ?# i
for (i=0; i<count; ++i)
$ _$ f* E% w' z8 a P& q{ * K, O; _& h; |; J1 z% \6 J( k
// Get a handle to the relationship Item by index. 5 a) R: |3 E- @& m$ Y' g, u
Item bom = bomItems.getItemByIndex(i);
) l- }. h; p/ Y! y+ T// Get a handle to the related Item for this relationship Item.
t7 F! T- B( S8 P- [: n9 [ Item bomPart = bom.getRelatedItem(); 3 m/ H+ f. i/ F/ e; n" A: m
5 n" T1 N( ^7 o. s5 X4 \
content += "" +
3 s* f E ~( x P3 ~4 z D "<tr>" + ) U- l4 r- t r5 R
"<td>" + bomPart.getProperty("item_number") + "</td>" + 4 m/ h% W9 l5 w; c# O6 w" V
"<td>" + bomPart.getProperty("description") + "</td>" + ' r9 w. ?' X+ d J. w9 s G0 Q5 d- h6 q
"<td>" + bomPart.getProperty("cost") + "</td>" +
J7 {4 H& M7 Z "<td>" + bom.getProperty("quantity") + "</td>" + * ~9 W/ B$ H! X& @) ?+ Y3 o' W% o
"</tr>"; & _- T: _ ]) B) [ ?! d
} ' j9 _- w# O- Z! Y2 z' A% r
content += "</table>"; * ^* I; D# U" A
7 y. [" f: b. g8 C" Wreturn innovator.newResult(content);
" s# C: c! m8 q( h. g# s/ u' v* c3 N: `7 R# B5 l
0 |$ o2 L2 G( _( X @
7 @+ Z. z$ k3 t- V/ h0 t1 a; Q
h$ A$ v, {9 X5 a1 U! w3 M
! }, B! V. I( U7 S
& U! Z+ d0 P( \; @2 Y3 u" `6 b 9 W W) n2 A5 z& p" U
Page 46
5 A0 Q" t% c/ c) ~2 y( S) k , ~$ c/ n! Q9 T2 N$ |% e
Copyright 2007 1 O2 j( \; ?9 Q% Y3 w( ]
Aras Corporation.
$ I1 x2 `+ g6 g$ z0 z: e% B7 uAll Rights Reserved. ) ^( T8 y4 w0 I7 [% A) X# E
VB.Net
& j' L* q0 a4 a! K1 J& S: ~' A/ vDim innovator As Innovator = Me.newInnovator()
+ X, J# F( S: f1 ~
( m2 e2 y" z/ `& k' Set up the query Item. ' z; |) @; Q: U) ?* U
Dim qryItem As Item = Me.newItem("Part","get") 4 K* y5 `1 B4 U0 ]
qryItem.setAttribute("select","item_number,description,cost")
* v$ C4 G% Z8 T1 @qryItem.setID(myId)
4 n w9 z; Y% K. n
" I- A T. {, b) J* j' Add the BOM structure.
) X1 d- y3 M$ f8 g V0 S+ HDim bomItem As Item = Me.newItem("Part BOM","get")
2 u3 e) V7 j# bbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
* K2 r2 q2 M1 I! p! A7 n. eqryItem.addRelationship(bomItem) 1 e( I, G0 K" \( Y( M+ o( n( e0 r" X
: ], E) D" v+ C" I2 @
' Perform the query. % p! N q2 r7 p* R
Dim results As Item = qryItem.apply()
0 b; ^( I2 i. A2 r 7 E v# u6 x9 q2 o3 ^% g
' Test for an error.
7 C1 z% j5 c( K4 g& AIf results.isError() Then 1 N, ~' M% v# ^2 T! D. P2 |) H5 m
Return innovator.newError(results.getErrorDetail())
" e3 u1 g5 ^8 b* W& n) AEnd If $ {, y R8 w9 W% D
0 m- [- q1 g9 \- A) }7 m# t5 b3 o
' Get a handle to the BOM Items. 5 R6 x1 y/ D# p- o9 x
Dim bomItems As Item = results.getRelationships()
* l: i3 L/ _2 q* B7 pDim count As Integer = bomItems.getItemCount()
4 c: c7 l) ~) j7 K. N3 R' O2 }. @Dim i As Integer ( s `' H M6 ?$ C6 l( v. o" M# U
; _7 T. h/ L$ {: m' v8 p5 ^' Create the results content. % `' B7 O' T9 V# r
Dim content As String = "<table border='1'>" + _ / ?4 K! O, H8 I/ l0 l+ c
"<tr>" + _
$ {$ {2 F i% b1 x "<td>Part Number</td>" + _ 5 n0 {" A5 z0 E; A. ]% S, |/ @, m& Z
"<td>Description</td>" + _
4 E+ b6 v& v8 j6 D6 G( k "<td>Cost</td>" + _
% s- z$ i) U( ~& S% ?$ h- r "<td>Quantity</td>" + _
/ }5 B' N, m4 e2 V "</tr>" 6 d# B. [1 c! T1 B- w7 c% [- G
, }5 W) P9 Y2 c$ c# b" |% D6 v. @' Iterate over the BOM Items 2 z; ]$ }- A y# l8 F: K
For i = 0 To count - 1 2 N4 N# C" A5 @) C
' Get a handle to the relationship Item by index.
! r6 S* U( f+ ?0 p/ S Dim bom As Item = bomItems.getItemByIndex(i) ! Q: H6 k. e& ]; t6 v$ E
$ {' V( `$ |6 n" r4 `' Get a handle to the related Item for this relationship Item.
! P8 ~% i( E( @ Dim bomPart As Item = bom.getRelatedItem() + J2 j- |, l0 @7 [( F- U
1 `9 E& p% A! h6 i content += _ 2 `* L1 [4 h; |8 Z4 V
"<tr>" + _
! N( U+ V g) Z' i! I S3 N5 B( ] "<td>" + bomPart.getProperty("item_number") + "</td>" + _
+ u; ~( U0 I* k9 Y' U "<td>" + bomPart.getProperty("description") + "</td>" + _ ( F% \4 U% ]5 d$ M. P6 m: |: k
"<td>" + bomPart.getProperty("cost") + "</td>" + _ 4 J8 e' `9 p7 x# [( s8 W
"<td>" + bom.getProperty("quantity") + "</td>" + _
" |% x4 `3 L0 n1 ]# k- Z8 P "</tr>"
/ K& Z' Y* b/ D% B' NNext & f! v( b9 w# F8 [, r/ \
content += "</table>"
' @/ v: S6 N& | c! c 4 a# P, j' n @/ s# P7 A# X5 k
Return innovator.newResult(content)
1 y& \# { [ }7 W
6 h% T7 Q5 V5 H1 N+ b# V4 e |
|