|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
\1 }8 R& t8 h! u3 T F& yTo query for an Item and retrieve its structure you build the query as the structure
# I" `& v s) {- T9 {2 `you want returned. Use the IOM methods to add the relationships you want and . S6 f4 ^. G6 o5 V9 u% y- c
build the structure in the Item. The server will return the structure that follows the j# V$ }- @2 k# H/ h" j
request structure. 2 e4 C4 j* o; p0 c5 i
This recipe illustrates several related concepts together, which are how to get a set
7 Y! E4 F% {& cof Items from an Item and how to iterate over the set, plus how to get the related & _0 w4 b* i' \8 z4 S& v
Item from the relationship Item.
7 H! H6 P1 V [8 hJavaScript ; v; P0 @: J5 O
var innovator = this.newInnovator();
* i9 h4 Z) E+ @& v9 y
5 P7 _# z5 a+ f- A; D) X& D' B// Set up the query Item. 5 R: M7 C7 V/ x( O# e9 m! B
var qryItem = this.newItem("Part","get"); / K& ^& D+ S- m9 i. x6 L/ T
qryItem.setAttribute("select","item_number,description,cost");
3 l( i# k" y0 g! U0 D! n" mqryItem.setID(myId); . i- n4 V6 |7 l! F' d) ^
/ b0 d' D# N9 }1 L5 U
// Add the BOM structure. 6 }6 c, ?# Y8 g. Y6 H0 J0 M# E
var bomItem = this.newItem("Part BOM","get"); 2 u$ d2 D' n! e3 w- m$ t4 n
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
( f X7 m" m3 |( J8 [qryItem.addRelationship(bomItem); 2 u* o! B2 a: w
; K5 d8 m! A `: g# y3 z// Perform the query. : o3 X% N2 k: q
var results = qryItem.apply();
: _# c/ }( W* `3 q* M
* f3 `/ F! T# B; b( e7 j; T) i// Test for an error. % e! y+ I; ~1 ]5 N
if (results.isError()) { % B! c9 o; V& n' G: I/ Z: }
top.aras.AlertError("Item not found: " + results.getErrorDetail());
7 b8 t2 I: }; E/ F# s return;
# J3 x. V) \$ C Q3 ] T}
/ a: W. E. M8 l L- Q; b - [. ~4 f! L [; h
// Get a handle to the BOM Items. 6 v% e, V# c: M
var bomItems = results.getRelationships();
" t( u$ g( R% C2 {var count = bomItems.getItemCount();
# D0 _+ e& I/ p) q. G' |( q0 \
! c2 }: u$ m$ \1 q6 [& z// Create the results content.
6 |% e! F+ A& A3 ], Hvar content = "<table border='1'>" + 6 l+ Y& I2 j5 g& l5 }6 O
"<tr>" + 4 O- J! l1 J0 K: `3 P% ?* q
"<td>Part Number</td>" + : f0 t' T3 L, I# |2 |' |
"<td>Description</td>" + 7 O( O5 g. W3 I' i& @( G, K( s5 a
"<td>Cost</td>" +
2 ?( M# }* K2 M- H& O "<td>Quantity</td>" + 2 y+ J$ O8 A: w$ ~
"</tr>";
6 V8 n- |! q+ s5 ?6 u0 b ; v0 {' L! e5 o0 Z+ \; n
// Iterate over the BOM Items.
' M6 ?, ~2 G! o! h5 tfor (var i=0; i<count; ++i)
0 N( N) _. C+ o4 c! c5 ?6 c{ 4 C/ }/ I8 W* o: P
// Get a handle to the relationship Item by index. 1 a: u' b; j; \% h2 S' ?( G) w: A
var bom = bomItems.getItemByIndex(i);
' s7 n: p0 [3 V2 s1 I z// Get a handle to the related Item for this relationship Item.
# x: c/ a5 e i& Y var bomPart = bom.getRelatedItem(); % I+ F* x- J( w7 ?
% R5 ^; d/ r* O1 h, r: H* k7 V content += "<tr>" + 1 L- R2 P3 z) ?0 `( q; L1 X
"<td>" + bomPart.getProperty("item_number") + "</td>" +
/ |8 \4 j3 Q" f/ }! s2 { "<td>" + bomPart.getProperty("description") + "</td>" +
" b! B4 L! ]" T3 Q6 z" q4 m "<td>" + bomPart.getProperty("cost") + "</td>" + 7 n6 ^+ K4 D8 `, f) }" {. b
"<td>" + bom.getProperty("quantity") + "</td>" + " t5 r7 D1 a( O" P
"</tr>"; , E- n# q) N, F& I: ]+ ^' j8 Y, P
}
N' @; Q$ x% c% U) sreturn content + "</table>";: P% `8 s" I* D
4 v, i( T- F3 z1 k$ E" z9 L
5 A5 j" d h1 W& e
! _: _' O: g/ |: k1 D
2 [+ k8 [4 n% y5 f1 PC# ' q7 Q0 d8 n# g0 Y6 h* r1 S
Innovator innovator = this.newInnovator(); ) K! d' g8 `; O- ?* a, `5 d
' B3 n8 U* n& u: ^$ M- q// Set up the query Item.
0 R8 j/ t3 a$ k: _: }: s8 |8 KItem qryItem = this.newItem("Part","get"); * X3 ~4 ?0 j# t& n# K8 ?4 C1 J. X
qryItem.setAttribute("select","item_number,description,cost"); 5 [. M. z7 y" Q3 ~" D( D& L
qryItem.setID(myId); ( d' d" Q* E: ?0 B5 g
- K% w/ |6 d9 y// Add the BOM structure. 4 c. B2 X6 |% r H" c
Item bomItem = this.newItem("Part BOM","get"); 3 T9 A! u% _' O- p) d
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 3 b0 o' e$ @2 j# ~: ~
qryItem.addRelationship(bomItem); U1 G4 l/ H& A2 K+ Q
- w3 N$ R2 B! x! g$ [" H; u! L
// Perform the query. - V* c Q ]& Y$ @( p
Item results = qryItem.apply();
6 c4 x0 r6 \) c |. t! x4 F 0 e6 h) S2 L# w! G- ]2 }
// Test for an error. ( A, E' {) V$ s( [
if (results.isError()) { 3 d5 l1 ?7 O& j% E2 K
return innovator.newError("Item not found: " + results.getErrorDetail());
. L' E# |& j' L2 n( ?} % c! n$ I+ k! `% w7 B( w
5 W9 }4 f2 ^5 F7 w) R* B& Y: \// Get a handle to the BOM Items. 7 f% l) s. D# J$ ]
Item bomItems = results.getRelationships();
* |* j, l4 r; d2 l9 qint count = bomItems.getItemCount(); " W: k/ ~! b+ t0 j, \
int i;
5 `% n. Y1 O& }) y& |& G0 d# m
4 r6 _5 ~' _9 P$ u' q) x% J// Create the results content. / m/ T- Z& @, J) [! }
string content = "<table border='1'>" +
) j& h0 V+ G. F' \ "<tr>" + . S3 M1 e) D0 j6 R; ?5 _3 j8 t
"<td>Part Number</td>" + ! c) l; E6 E9 A8 Y& M7 }- q
"<td>Description</td>" + % ^2 e G$ r( M) [2 F
"<td>Cost</td>" +
! x; D' S3 Q' n$ J% s "<td>Quantity</td>" +
- U# t4 Q/ Z7 [! k6 L: x "</tr>";
# J( W( U. r' d: [; u6 `/ c9 ~
1 y$ G! D5 K& g$ `// Iterate over the BOM Items. / Z/ M5 w; P) }* h
for (i=0; i<count; ++i) 0 n& P$ p9 ]. H% x0 h6 Z. w
{
. M2 Z" E1 N, O// Get a handle to the relationship Item by index. * ^" W* P0 n- c$ |0 g
Item bom = bomItems.getItemByIndex(i); % p$ c Y# `' r$ m, d
// Get a handle to the related Item for this relationship Item.
}: D; }4 |: U, u Item bomPart = bom.getRelatedItem();
# k' g3 a8 J# C: Y% C
6 }% g9 n9 W* `" ~( {! ~4 [ content += "" +
: B B) V# S' Z "<tr>" +
$ C* G( [7 P9 O/ W9 _ q2 ]! j "<td>" + bomPart.getProperty("item_number") + "</td>" + ! H" P h# }8 Y4 |* ` `
"<td>" + bomPart.getProperty("description") + "</td>" + : G1 e6 j0 C$ O" ~% m( x3 ^
"<td>" + bomPart.getProperty("cost") + "</td>" + $ Z! @! n" N( r7 j
"<td>" + bom.getProperty("quantity") + "</td>" +
1 _" S3 Z- b: Z2 A1 P. m. _% i5 o "</tr>"; 2 x6 ]6 }# d' Q$ F# i) Z8 o* k
} # L' ?! n3 V* J9 @
content += "</table>"; 3 \# Y4 q* ?! C
2 | ?0 q# `* R T0 M
return innovator.newResult(content); 2 [8 y& w" o3 \7 A6 S9 \: }
' Y) t. t( J6 V& U/ r; K( D# q+ O" E1 {! t7 ?% }5 C
9 n7 n* \- x# Z6 D t* `
5 z7 W- e' ^, j1 l$ x& {
( Y2 N8 Z1 \1 D W% q
) b" B2 L" K/ ~7 ~% [ ( o" O8 T. G: i4 Q5 e* L
Page 46 , A9 K2 ~6 C) y1 v* A) U C8 U
# ]# f$ U: C6 E* V" o, _- ~1 \! @- W
Copyright 2007 7 R) Q5 Q0 v! X ?: X" B
Aras Corporation. B: n1 O4 M4 q1 V
All Rights Reserved.
7 N ^! W. K* n5 L% ^VB.Net
. g0 P8 f7 E4 x6 w, T4 kDim innovator As Innovator = Me.newInnovator() 1 B3 f7 L1 r! B) x7 o% T- |
h8 v) p2 I" S7 H2 M: x
' Set up the query Item. 6 K7 `" N; ~* T3 Y
Dim qryItem As Item = Me.newItem("Part","get") 3 V' ]4 J( s- P) l* M( s8 F
qryItem.setAttribute("select","item_number,description,cost")
; ?. [/ A, j5 I- d- f" r5 nqryItem.setID(myId) 6 A0 v6 B: x1 q; s3 c" D
; \1 B" o- `* ~9 z( h' Add the BOM structure. / e7 J, B# `5 W$ E
Dim bomItem As Item = Me.newItem("Part BOM","get")
, m) Y' K4 m2 W H' A) \9 WbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
0 Y, x( _3 s3 Y# dqryItem.addRelationship(bomItem) # ~- P- p) f# E* w6 l: D0 E
) K8 r0 f# Z7 t7 z R' Perform the query. $ L; S, u9 ~9 V$ x, O$ \- T# d
Dim results As Item = qryItem.apply()
( J: o7 ]* }* ~6 Y( r
7 ?- O! R% O; v* L( K2 m& _$ z' Test for an error.
2 E- o- c% z( n+ a* \If results.isError() Then 2 F# Y* {" V" Q5 f6 @
Return innovator.newError(results.getErrorDetail())
3 V: w! N8 |2 M# K6 y# aEnd If
( ]0 g+ i4 l g6 {3 U- F# U/ U8 M 1 ~2 U- ^) n! N
' Get a handle to the BOM Items.
0 N$ t# `, s& I7 W- N/ P( w/ nDim bomItems As Item = results.getRelationships() . r8 R. h& I! d( i
Dim count As Integer = bomItems.getItemCount()
( v7 ]3 y" t c/ A* E4 F( P8 DDim i As Integer
" B( |0 L0 }+ B. W E$ W% B 8 ?0 i' c. C: I4 u; _8 A( y$ }/ W
' Create the results content.
T; l2 t7 P* Y9 zDim content As String = "<table border='1'>" + _
+ k5 W" ], Q/ Y% ] "<tr>" + _
! B. M$ F. B0 @ "<td>Part Number</td>" + _ % d3 U# @5 a/ `% ~
"<td>Description</td>" + _
" N0 ]6 M& T, w, z "<td>Cost</td>" + _
* L: f5 c% m: J+ K4 _/ W "<td>Quantity</td>" + _ 4 h3 g, D1 H! K4 j& c+ ~
"</tr>" 5 A2 _; _' j& N A+ v+ r+ _, r1 o
& w. \. O0 f5 T5 i& U' Iterate over the BOM Items 9 D5 n. L% R' N2 G6 G7 h& W
For i = 0 To count - 1 7 o" e2 W! `7 P& p: H1 |
' Get a handle to the relationship Item by index. 1 P$ D7 }) S/ P$ l- R* s
Dim bom As Item = bomItems.getItemByIndex(i) $ t5 w1 C, L2 N, [. G( c
( r4 Q& N/ t0 S, D! B
' Get a handle to the related Item for this relationship Item.
# ~2 U" u) {/ _6 I3 _' M1 u& ~ Dim bomPart As Item = bom.getRelatedItem() 0 a9 V& ~2 z; A& U
" |1 U( [$ E6 n content += _
* o0 I5 E9 v# C* y+ p% s "<tr>" + _ + {) a9 a2 b) {9 Z. r0 O
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ : g0 L; u2 V0 K3 h0 n
"<td>" + bomPart.getProperty("description") + "</td>" + _ 3 H* _3 w4 A% e/ z( X
"<td>" + bomPart.getProperty("cost") + "</td>" + _ 7 ~! _4 X) V; D: X) s
"<td>" + bom.getProperty("quantity") + "</td>" + _
9 S8 m7 J! _% f: o6 ]2 c "</tr>"
' c r4 F; p3 X, `/ G1 L! {: [! Y4 SNext " F. M" F* w/ T6 o& v! u
content += "</table>"
! _0 H( L# `2 Z
! o- ?- p6 }6 J, C. j$ yReturn innovator.newResult(content) - K. o( A0 i% c. H& B& s; U/ X
) W: u9 p$ s, w2 F. |: g& i
|
|