|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 4 U8 O+ V3 z$ K& y8 o- u# d
To query for an Item and retrieve its structure you build the query as the structure * A( g1 y/ h( I3 d; Q) b0 S* K [
you want returned. Use the IOM methods to add the relationships you want and % Q7 u# _# p! c0 A+ d P& H
build the structure in the Item. The server will return the structure that follows the $ `& @! a* U1 H- q% f w' h$ ]
request structure. + T# x$ b( e. ]! _/ B, U: ?7 a
This recipe illustrates several related concepts together, which are how to get a set ) N1 Q( D, z. I
of Items from an Item and how to iterate over the set, plus how to get the related
. k; l! ?# k+ v$ ^Item from the relationship Item. 7 B7 X" O. Y' O: Y+ Q/ C
JavaScript
' j9 F% p1 Y2 Vvar innovator = this.newInnovator(); : A! f5 }* W9 I8 b, @5 G+ R% F9 o
9 g; y6 n: n1 F; \+ Q; i
// Set up the query Item. 1 w4 ]/ {' ]' z H8 F1 ?
var qryItem = this.newItem("Part","get");
6 i' z+ j0 D% C2 b- o2 `qryItem.setAttribute("select","item_number,description,cost"); 7 a, ^$ u5 F! U2 y3 f
qryItem.setID(myId); * x6 N* @! g. A" \- I$ x
) a, `0 h1 y" U// Add the BOM structure.
1 O2 @- g% R/ e+ ^var bomItem = this.newItem("Part BOM","get"); ( x! @! m, r+ }, d6 s) q8 g
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
; L% F( i3 G' C1 o. l8 y2 IqryItem.addRelationship(bomItem);
* x# A* ]* Y, W8 [- e6 c$ ]
1 d2 {& a- A0 w M// Perform the query.
& c: ]% o3 U% s: O9 Gvar results = qryItem.apply(); $ r3 [" _ g1 ^/ o( a( _
4 V& W. [8 k$ _0 ]" U* r- ^- B
// Test for an error.
/ R7 d$ A& y1 u5 z2 B/ kif (results.isError()) { - I% ?# x7 k2 E
top.aras.AlertError("Item not found: " + results.getErrorDetail()); 5 ^5 o! T) x+ r9 r# I! H+ r
return; - ^9 H: |2 Q. \9 t# a
}
$ }- s) v, N; D: t' d
" `/ _" k% H& s6 Q$ F! F// Get a handle to the BOM Items.
! n8 o3 y# r" U! vvar bomItems = results.getRelationships(); 4 g# J: O' O( b
var count = bomItems.getItemCount(); 2 l9 v7 Q+ v) A$ K9 M" C$ `) w
2 L$ N# M9 p& n0 D) z0 Y// Create the results content. + v# E* a) [' V" b1 e3 ]
var content = "<table border='1'>" +
3 `2 g4 i3 i- ~5 Y& w "<tr>" + $ ?, T ~5 F; r$ Y5 N! z+ ?
"<td>Part Number</td>" +
- ~( n9 r" R/ Y "<td>Description</td>" +
/ j4 M3 w1 A* _3 |. `/ m "<td>Cost</td>" +
* B" C+ s, @. X "<td>Quantity</td>" +
. G" Z9 }* F8 C" k/ I "</tr>";
3 t0 |0 j, S5 ?
3 |* G) U5 ^' p0 q7 y// Iterate over the BOM Items.
5 K5 J7 ?+ ?6 h, U8 ^% L% rfor (var i=0; i<count; ++i) $ V% [( ]; \' T7 u" u
{
, T" D8 g* e/ Z% o/ |; B& I// Get a handle to the relationship Item by index. 4 T' U' m$ V3 n9 w/ R' o' c' w9 L" c
var bom = bomItems.getItemByIndex(i); ; l+ X, U3 e. \' N) x0 [+ l
// Get a handle to the related Item for this relationship Item.
( g3 ^7 ^$ |( G2 S5 G& ~3 q var bomPart = bom.getRelatedItem(); % \! r! _* g9 D0 k8 y
' z+ x/ Y1 k: P
content += "<tr>" + $ J2 |9 D- S5 f1 t) H
"<td>" + bomPart.getProperty("item_number") + "</td>" + K y- b& R( e' _, D8 @- v
"<td>" + bomPart.getProperty("description") + "</td>" + ) R ?' S& u* z: E. s! B1 A7 `
"<td>" + bomPart.getProperty("cost") + "</td>" +
0 r' [2 e( k$ J2 x E& q: m) \ "<td>" + bom.getProperty("quantity") + "</td>" +
0 R% L) Z7 U/ Z1 t: s% q7 _/ q) }* H( _ "</tr>"; & V% Q6 A6 y5 ^: @5 d
} $ V6 I y; \# j' N7 G7 z L' j1 |/ b
return content + "</table>";
! u( M; k6 l2 B( q; }3 p% R, k. s: ]& A- x- X' p# Y. j
6 y9 e+ F/ X# n+ d- t5 x
5 F% \! _) `2 d9 O' ]9 `* F+ o2 m
1 \. l4 M5 E* @" g3 [! jC#
# f9 d8 P3 n3 b9 z: F0 ]Innovator innovator = this.newInnovator(); 7 e" N8 f- Z' O! p' h! ~& `
! L6 s! ^1 J. V$ W e. e+ ~
// Set up the query Item. 3 F; V' S G' b; l& F* F
Item qryItem = this.newItem("Part","get");
9 d+ H l4 ~, VqryItem.setAttribute("select","item_number,description,cost");
1 f0 `, _, O4 T: i+ n6 H$ FqryItem.setID(myId); ! ^6 S6 l2 T0 m/ C
5 Z6 E- I3 Q; k. }// Add the BOM structure.
B, k9 j. X; MItem bomItem = this.newItem("Part BOM","get");
" a3 T5 K T, x8 H$ gbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
1 N; b' h9 I8 \- A& U+ O9 E# _qryItem.addRelationship(bomItem); / m4 O+ O! W+ t1 b7 \/ k, f
. B; A! }5 @0 g" F4 U. Y// Perform the query.
7 c& ^% O' L- t2 F9 m8 p% {Item results = qryItem.apply(); - H3 c7 w/ B% x/ g. D1 j0 J
+ w P* r$ ~# a! s& ^( R: r }// Test for an error. 0 o% C! T+ h+ l! ^, X$ {
if (results.isError()) { * `0 M# o' \0 z! Q, F
return innovator.newError("Item not found: " + results.getErrorDetail());
$ T) h% @, B$ S" C} 7 x: y" o6 _4 S$ ~3 @
- h' ?% }! n% K" [& |$ I// Get a handle to the BOM Items.
0 D+ X* ?7 j1 YItem bomItems = results.getRelationships(); : M% Z2 B/ t9 }8 j ^
int count = bomItems.getItemCount();
0 U* h# }, G) y7 Sint i;
& F! e% z) b" ^5 L& i5 H
. }! ~# b* _5 x# n// Create the results content.
+ J/ |) W2 l; h) v. x, w `string content = "<table border='1'>" +
; ?3 g7 u' {0 i( y s "<tr>" +
* A. K6 ^/ ?8 M; ~: m6 L' K "<td>Part Number</td>" +
\5 ~5 a: U: }% [' u$ q3 b "<td>Description</td>" +
- \: ^# \ a4 ?) @- R "<td>Cost</td>" + 9 O% G2 c! [8 ?
"<td>Quantity</td>" +
9 Q6 p2 ?, C8 F "</tr>";
4 [4 v( o ]8 Q. d$ e; S
( k5 ~1 c1 A9 p/ `// Iterate over the BOM Items.
8 M9 C, h+ d8 G. N; hfor (i=0; i<count; ++i)
+ f( o4 H. j. x) |/ Z{ ! O% o6 K1 B/ A- n% b, \
// Get a handle to the relationship Item by index. * g: e6 p6 c- ^8 Y. s2 q9 a+ h
Item bom = bomItems.getItemByIndex(i);
. S9 k' q% x8 M& \% }) H- |// Get a handle to the related Item for this relationship Item. 9 {* ?3 I' c7 o1 B+ v
Item bomPart = bom.getRelatedItem();
: B8 p- P4 L% I! r: p) B) `; z
4 u# f' x% e# p' r* J content += "" + 4 m( \+ J1 |* N4 W, r/ B6 M& e2 N1 z
"<tr>" +
! F$ D8 v7 E4 n, R6 T "<td>" + bomPart.getProperty("item_number") + "</td>" + : l+ y) B6 C, x
"<td>" + bomPart.getProperty("description") + "</td>" +
- Q" ^7 ^: r0 X' F( G "<td>" + bomPart.getProperty("cost") + "</td>" + 8 m* C4 O* O% b: ]
"<td>" + bom.getProperty("quantity") + "</td>" +
) z! ~1 s* {9 k& \ "</tr>";
0 P8 R8 s& L9 N! H: J0 E# `}
1 N' ~( ]: a v' e5 d: @! o4 a/ Mcontent += "</table>"; 1 M/ C' p9 o- d
1 s# e* f2 d' ?4 V# e( ^& Lreturn innovator.newResult(content); & L0 g( }6 E* r$ U5 }2 L, |
& u+ J/ s$ O8 ]# ?' d$ i
* f: B K/ o$ v8 W5 y9 P
" r* U+ W- F& c; P
; ^2 u9 }8 l5 m: e7 c3 R) {6 ~( |* K4 F5 n B
% L3 r, ~ ^* R5 K$ \/ M
2 `) C' h) C5 p3 p8 p" i Page 46
g; J4 m, q, s- c 2 c# ^# I; D, V% L0 R
Copyright 2007 6 a; Z0 ^! F* A: f# k" d+ H4 C3 B3 F
Aras Corporation. # b/ l3 k y& _2 f
All Rights Reserved.
9 i& a: A2 U! M S4 Y4 W. iVB.Net
" o8 L9 \+ c) A3 b/ ?. XDim innovator As Innovator = Me.newInnovator()
! w5 d" H9 @5 q/ x+ u8 O, I 7 z) W2 b b7 s, ~( I1 x
' Set up the query Item.
7 B& K9 v2 O8 B6 C w: kDim qryItem As Item = Me.newItem("Part","get")
! @0 ?% i( n' ]7 B$ BqryItem.setAttribute("select","item_number,description,cost") : D3 P+ ~$ S, b! m
qryItem.setID(myId)
* f6 k8 j" L5 i
0 o# X6 y. A) _' Add the BOM structure.
) @! f3 h. C$ C( A! C: uDim bomItem As Item = Me.newItem("Part BOM","get")
- m O) I0 B# J: @bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
9 D" G0 d$ v$ u- N7 y. ?qryItem.addRelationship(bomItem)
% Y m c3 P7 b7 i
5 x3 \) z! L3 J- T' Perform the query. 2 K& g& X# @* n$ R1 X; r3 g
Dim results As Item = qryItem.apply() 1 B; o/ |$ x! d ? H
' s+ x1 ?( ?9 j' Test for an error.
$ q2 H1 n% H! |5 J) FIf results.isError() Then Q) y0 z" ^9 d& c: y
Return innovator.newError(results.getErrorDetail())
2 N( G4 G l# `0 A2 n$ VEnd If + J& o9 T' y4 b( W @2 W6 C
1 B5 A" Q- W3 E/ A2 K X# j
' Get a handle to the BOM Items. 0 z* h- L; C( F7 X+ ^* @& ?
Dim bomItems As Item = results.getRelationships()
s$ Y, H p$ P c3 K" P: f0 C. IDim count As Integer = bomItems.getItemCount()
0 T1 |$ t! ~" CDim i As Integer * j3 `4 E" y+ \% E a1 x& @2 u$ _
2 o( _# a1 n% b' Create the results content.
0 l6 d8 c9 J$ wDim content As String = "<table border='1'>" + _
. F4 C7 y) L6 |+ y5 @( g "<tr>" + _
( N6 E3 q3 X$ v- h6 z# { "<td>Part Number</td>" + _
" |3 A: W9 }- \ "<td>Description</td>" + _
- N+ l( E0 K; R- P "<td>Cost</td>" + _ 6 v: A, X8 P$ a4 N% g% k' V
"<td>Quantity</td>" + _ 1 V) s: O! |2 | g
"</tr>" 2 N0 ?" U E% B% P" t) H
" V) h# f7 P8 L6 K" z
' Iterate over the BOM Items , Y$ S' X: m+ K
For i = 0 To count - 1
; }% p* y3 H+ s) c! F* l' q% d' Get a handle to the relationship Item by index.
9 C# {1 |$ H9 m. t Dim bom As Item = bomItems.getItemByIndex(i) / _2 @4 a! k9 a, |9 h
' O# v: k2 R4 F, h( O6 J3 _
' Get a handle to the related Item for this relationship Item. # |9 H3 r& m) j( c7 ?
Dim bomPart As Item = bom.getRelatedItem() 5 ]9 d/ J5 n7 s" P, \% o
; ~/ Y. G+ M9 l- l content += _
0 }6 p, O, K+ t4 s9 W0 v4 Y "<tr>" + _
2 S7 V3 k1 q4 Q "<td>" + bomPart.getProperty("item_number") + "</td>" + _ / p5 m5 ^4 R' V, Y, t% i z5 n! S( E
"<td>" + bomPart.getProperty("description") + "</td>" + _ ' T0 e" Z2 {) V+ o$ W3 ?* s% g
"<td>" + bomPart.getProperty("cost") + "</td>" + _
0 l4 F% b$ ~' l; o/ m. [ "<td>" + bom.getProperty("quantity") + "</td>" + _
* [9 R( N' S: [ z "</tr>" # z! v' w# B _- E
Next
7 C& Z+ M- r: x8 W( dcontent += "</table>" $ ^" z6 v9 j0 X) m3 b
- f0 j$ @) B) zReturn innovator.newResult(content)
8 i- X% G' f- ~' Z
7 s/ d) b* _" ]7 O$ W( m |
|