|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
0 W7 ^0 I* O+ V. ATo query for an Item and retrieve its structure you build the query as the structure + W& \. d2 D* F, C( i
you want returned. Use the IOM methods to add the relationships you want and
, A, Q& V2 l( ?build the structure in the Item. The server will return the structure that follows the 0 @3 L. M+ X1 K
request structure.
* P6 Z+ N; {7 j' e9 nThis recipe illustrates several related concepts together, which are how to get a set - h4 \6 P# H4 o% R0 \
of Items from an Item and how to iterate over the set, plus how to get the related
- u9 ?) M3 c8 h1 hItem from the relationship Item.
4 b+ u {% S: m% G7 _JavaScript
( Q1 Z, Q- C) B( `var innovator = this.newInnovator(); 8 i# h5 f- h3 p5 k
1 S1 v- V2 T! T; A8 t1 W// Set up the query Item.
$ t4 B# d0 e B) }+ p' V2 yvar qryItem = this.newItem("Part","get");
% e, n) }+ z" z0 D3 S( Q# C, GqryItem.setAttribute("select","item_number,description,cost");
% p& ?! x; C- |7 IqryItem.setID(myId);
x; ~- X: R1 W. D$ X1 B3 Z( W & E+ }, K( I9 A" @. k" W
// Add the BOM structure. 9 Z6 A5 w( _. @% Z
var bomItem = this.newItem("Part BOM","get");
& y* r, A2 T1 t' M& H! U% l9 w5 pbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
1 g) s% z# B7 V; L# lqryItem.addRelationship(bomItem); $ v4 \1 A( t) [2 Y: U
# K+ y- P. y' V, E6 a// Perform the query.
# _9 f" h" @) S3 L9 {9 z1 P& ^7 \var results = qryItem.apply();
3 B4 R6 `6 K0 F$ X3 P! L 2 }* ?6 [, L# M: d }8 @3 p
// Test for an error.
Y0 }: W4 {' h' k4 R, Fif (results.isError()) { - D; C$ h4 s" R
top.aras.AlertError("Item not found: " + results.getErrorDetail());
# N" _! `' Z* k+ U return;
* ?. t! @4 Q7 F8 h& R7 X3 ?} * D J- l2 x: ~3 I3 G7 ^5 r& V( R
' [. K" i/ e+ b1 v: j// Get a handle to the BOM Items. b N+ H" N1 \4 E" t6 P% B1 w
var bomItems = results.getRelationships(); . M2 p) F: \. l. H! K6 V. P5 `
var count = bomItems.getItemCount(); 8 C) _# N' k5 X1 s9 v* f: T
! T% y8 V* W$ |8 I- R; B) y% l// Create the results content. 3 K3 Q# I, z6 ~: @' S/ B- M
var content = "<table border='1'>" +
3 Y( q+ H: }3 A: M. a% o "<tr>" +
! p6 s6 v! `( {1 [8 M# b) v3 n8 M "<td>Part Number</td>" +
+ M3 Y" G2 h0 J; y: L "<td>Description</td>" + - x7 E% i2 n$ I2 D/ w
"<td>Cost</td>" + ' R( @4 m# M5 s/ N9 t' o
"<td>Quantity</td>" + + [' C4 ^# ?' J) v. Z2 w) f
"</tr>";
! b2 ]- m- ^7 p f/ Y; K ! S1 ?. |; q y
// Iterate over the BOM Items. 9 ]7 h3 o4 _ F1 P8 V3 ~" E
for (var i=0; i<count; ++i)
/ e+ L" s/ v# l% Q( \2 b{ 8 a# ]+ D% n4 I9 y
// Get a handle to the relationship Item by index. 1 i6 g! ?7 m- s) v' v. d Z
var bom = bomItems.getItemByIndex(i); 1 h* M9 I) S/ ~& {
// Get a handle to the related Item for this relationship Item. 4 G! a4 ], b* _* b4 R7 V2 N* I
var bomPart = bom.getRelatedItem(); 2 ~+ ~# F! E* r X
, G% O, S4 J- W3 e5 q7 x& e; f; M content += "<tr>" +
+ D& Z" D$ ^$ Z' a! R) \( w# |% K "<td>" + bomPart.getProperty("item_number") + "</td>" +
, Y- Y& l" U* c2 k "<td>" + bomPart.getProperty("description") + "</td>" +
* g. t7 n: t& x# `: _/ X. ` "<td>" + bomPart.getProperty("cost") + "</td>" +
& u) ~' S5 W, j7 q "<td>" + bom.getProperty("quantity") + "</td>" +
- _/ i6 k1 }" z) J* k% K2 u "</tr>"; - e2 |$ o' R( \" Y _9 O$ y
} ! D" ~8 s1 W8 i# i
return content + "</table>"; e9 z# F9 b4 |- l
$ j- E& Q( O0 F7 p* U( m5 Y% U
5 f/ r( _: l7 c! t# m2 y& @. k! m1 D
# p7 ^9 r2 i" [4 a* \/ x
C#
/ F# E: k, J" C- D8 V9 RInnovator innovator = this.newInnovator();
' W) J7 x5 E/ n2 n- F6 R* \ 4 K* t& F" L5 q) ?
// Set up the query Item. . w g- e H: j+ q4 ^7 S# G- b" O
Item qryItem = this.newItem("Part","get"); 4 w4 y: k0 }/ F7 u& Q* e! L K8 o8 Y
qryItem.setAttribute("select","item_number,description,cost");
4 I: f) I# E; }qryItem.setID(myId); 6 l% u8 V7 a+ B. x
p0 J) k# Q4 U" U# \& x4 e// Add the BOM structure.
& Y) w" H6 n2 J; f, c+ yItem bomItem = this.newItem("Part BOM","get");
) S4 b, P( M5 ]* Q: z" a0 ?+ cbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
2 s5 h) [- F/ p2 j! ZqryItem.addRelationship(bomItem); - h4 w1 h+ \) `( X
- v' C" d" L# C) E1 R/ Y// Perform the query. % H1 j, k2 g2 J' F6 m+ U
Item results = qryItem.apply();
: i" T& K5 R! y2 w 5 N4 `5 G: b' a/ i
// Test for an error. ; _* J+ e" f8 I$ s7 a/ T4 [1 Z
if (results.isError()) {
6 X; D, `! h7 q return innovator.newError("Item not found: " + results.getErrorDetail()); : s; e2 T9 h6 @' J; ?- Q& p
} : J# d' {9 u8 W' b, ~, e
: d. v) R p7 b) t1 s! U* h$ K! b- ]// Get a handle to the BOM Items. 8 k/ k* T+ g3 X. F1 \6 ~2 m9 t
Item bomItems = results.getRelationships(); * G5 _7 E; q1 Q
int count = bomItems.getItemCount();
% W3 q) ?2 |1 Z" e9 Kint i;
* E3 |+ c7 W# V/ n, n: Y
) ?/ {( O( m8 O" U; b/ n// Create the results content.
2 ^- i" x5 T5 N4 P; z4 l9 g4 Istring content = "<table border='1'>" + * R$ u/ x* `% ?/ B
"<tr>" + $ L. e$ P* g2 g' m a9 k
"<td>Part Number</td>" + ; T% [2 y, s# B6 L8 ?$ h; N/ v1 X
"<td>Description</td>" + * \ m& y; z* g: M% A0 A+ X H
"<td>Cost</td>" + - L, n& |0 r* @7 M" W9 Q5 C- @
"<td>Quantity</td>" +
% ^: _, ]& O* d5 x7 E8 U2 B "</tr>";
/ E, n% m+ F3 j* L9 B
" e: S _9 b$ L' B// Iterate over the BOM Items.
/ ?3 ^8 R% D3 f: Ifor (i=0; i<count; ++i)
- P& @- G* b( _$ o+ M{ 3 u" |( l8 z5 H/ R3 l, M
// Get a handle to the relationship Item by index.
9 L ^- S+ y' `& X3 p$ ^ Item bom = bomItems.getItemByIndex(i); # n, j' y1 a2 R* Q- `
// Get a handle to the related Item for this relationship Item.
* g( ~4 ^0 ~8 v# w4 T) U/ P Item bomPart = bom.getRelatedItem();
. f K+ |" \# A$ p . Q/ @/ v4 I) {$ r: T
content += "" + ' X' z8 B0 V5 ], G& M3 g& T
"<tr>" + * }; w; m+ u p) U( s4 z7 e) c2 S* r
"<td>" + bomPart.getProperty("item_number") + "</td>" +
# V8 `7 k- g) I+ ` "<td>" + bomPart.getProperty("description") + "</td>" +
- | H- t C. r+ [0 z7 b "<td>" + bomPart.getProperty("cost") + "</td>" +
0 u1 l' g! _/ N7 O4 c# A4 l8 D0 x+ E2 J "<td>" + bom.getProperty("quantity") + "</td>" + E% o, _! a8 R! S: y2 D. [! C
"</tr>"; 3 z* T/ s4 r! c0 ]3 V* d/ ^
} ' r; D- }: M/ C2 H5 K, R
content += "</table>";
' X" r) m. g# N+ X' y' D8 S 6 O J: e6 x- N5 r
return innovator.newResult(content);
, B' F7 B, z0 R+ g- p! ~# | u+ v5 t( Y; [% o' `# R+ \; J
, e$ j0 R$ i) F7 k$ U
6 |0 t& G3 F2 e. }1 N. H% D3 b: T6 ?" V, y! u* Q# M6 h7 e
0 Z7 R4 P9 z' F' T& v: x/ d) {- i- x) `
5 @3 R, G k- Y. a8 s Page 46 Z- w( p. v$ t1 f2 \9 b
, {5 i- [; @. `1 d7 S* WCopyright 2007 . K! _( f: X! B% J
Aras Corporation.
9 s* x* R1 W6 z, K3 g5 H2 J1 X; zAll Rights Reserved.
; t4 {. _6 g0 W0 @1 l; WVB.Net 8 W- L! u5 }/ o( L( |
Dim innovator As Innovator = Me.newInnovator() 4 S9 f$ v! I+ H7 M1 z+ s
! Z* h& I- E) Q! K `' Set up the query Item. & A6 i0 e* ]/ y# x% }
Dim qryItem As Item = Me.newItem("Part","get") * ^! K" ^; o% q) A0 C
qryItem.setAttribute("select","item_number,description,cost") 1 r" x6 b0 L4 i' f
qryItem.setID(myId)
: Z; v' i' t: C$ s c' B + P$ k" W# p( P; ]( O' Z+ g7 q9 v& v
' Add the BOM structure.
+ m5 t' ~6 n) D! ?& a4 {Dim bomItem As Item = Me.newItem("Part BOM","get")
* ]- r& `) I; N+ _4 z* XbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
$ Q4 b" U6 z% Y/ SqryItem.addRelationship(bomItem)
9 e! Y7 U* i& C/ P5 K( i
2 [. {0 t2 Y+ R J' Perform the query. " u$ X% @7 r$ p, |) Y5 z7 p$ K
Dim results As Item = qryItem.apply()
3 s; A4 L. \. g' o1 p3 E4 b % K# L" s' B0 ^
' Test for an error. - ?, k9 M# s- K, E
If results.isError() Then 9 v3 N! M$ z7 j- O5 k% S
Return innovator.newError(results.getErrorDetail())
" \+ k2 `) R9 }. y; M: ~End If
6 Z7 `) d- U8 q$ c4 @1 Q 2 @; A: r+ C! z' v
' Get a handle to the BOM Items.
" m( c9 D) c# |2 |Dim bomItems As Item = results.getRelationships() 8 ?: B; I+ a; q2 x2 a" i3 B
Dim count As Integer = bomItems.getItemCount() # x% U( |% i7 r9 K; G
Dim i As Integer
- z3 L; L' d$ g2 ?3 O
) m& p% D6 B& U4 o' Create the results content.
0 P% Q/ i8 ~4 \Dim content As String = "<table border='1'>" + _
; P* J" o9 f* c8 g, j, N "<tr>" + _
|7 ~% [- y+ H9 o1 {% C "<td>Part Number</td>" + _
: A3 o$ Z$ c9 l "<td>Description</td>" + _ - N+ }% K1 v. f* k0 k
"<td>Cost</td>" + _ 9 ^0 L, L. {$ N& T K
"<td>Quantity</td>" + _ 3 a! L% q, A3 N% M
"</tr>" & I: ^! n1 [% W+ b5 U/ @3 R
* @6 b' }% T3 S6 Z, E
' Iterate over the BOM Items
2 M4 h' V& d, q6 DFor i = 0 To count - 1
$ V# L0 c! c- N: N* j' Get a handle to the relationship Item by index. , ~, R% h) d7 K3 T7 m% U' P0 i
Dim bom As Item = bomItems.getItemByIndex(i)
0 H/ i' ^6 B6 ]. \+ L c- q5 o' Z 6 e# P: s6 z: X5 X9 O: j, P
' Get a handle to the related Item for this relationship Item. 1 z2 r5 l: w7 N" G- F* v
Dim bomPart As Item = bom.getRelatedItem() & s; v( w/ n( w6 H& g8 y, O' Y
p. N/ ]2 F* g) y/ I0 w* \
content += _ 8 m* y. [9 V* j) U% c
"<tr>" + _ # [0 n" {. f. s' E# C5 y
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 0 a$ B6 [% N9 Z+ K: x% ~5 L
"<td>" + bomPart.getProperty("description") + "</td>" + _
, J y7 p6 _' n/ o& ^0 r! Z9 @ "<td>" + bomPart.getProperty("cost") + "</td>" + _
: c% O+ n$ s$ X$ ]! |- ]0 H& e "<td>" + bom.getProperty("quantity") + "</td>" + _ 5 b! @& z* z+ h; m3 H; k
"</tr>"
* l, R+ s$ H; S8 g7 D0 mNext 9 l7 a1 I4 |8 Q& @$ V8 q
content += "</table>" ' |: F E3 L. G# K) K8 ~* U5 k, f
! P/ a! [' d" ]% j) ?, _
Return innovator.newResult(content)
/ M O# G- s, z# A" z- M5 _
6 D: t" v* v% f( S4 j |
|