|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
- m. {! B( j: h! x( j4 W5 u7 @) fTo query for an Item and retrieve its structure you build the query as the structure
$ E, B( a) e7 b( C$ _ Tyou want returned. Use the IOM methods to add the relationships you want and
; M9 L- Z$ L! x& u! A- sbuild the structure in the Item. The server will return the structure that follows the Z9 C( V7 g5 ^- m+ T
request structure.
) Z, V7 L+ n( _5 u- A- u5 s+ SThis recipe illustrates several related concepts together, which are how to get a set
; n: u i" K7 i4 L7 ?; r( Wof Items from an Item and how to iterate over the set, plus how to get the related 4 O9 G2 q# a0 y/ S F0 d5 s& b
Item from the relationship Item. ( y Q" I& W+ f, J' |' M% R- j$ y
JavaScript 8 {, I ]) O$ o; L; {, I
var innovator = this.newInnovator();
9 {8 I( n' U( h& [
6 q, j" D' d7 E0 q// Set up the query Item.
5 f$ F& {& a( P' a' D8 _5 Fvar qryItem = this.newItem("Part","get");
% _; Z- D! a5 _+ i8 z& X0 aqryItem.setAttribute("select","item_number,description,cost"); , {7 A0 `! Q! y" U
qryItem.setID(myId); + g) v( c$ v: x. w
- D" ]6 a+ ]7 [% l. R& _+ w// Add the BOM structure. / s6 J. e0 e1 Y& l8 [
var bomItem = this.newItem("Part BOM","get"); 5 ?; U* j& B; G" [
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); , }/ d4 e/ n. S( c" q1 j- w
qryItem.addRelationship(bomItem);
$ Y/ c. E: F' C* H
0 R% ?# X, O& V- @' D// Perform the query.
/ ?8 p( e: H; P( U; bvar results = qryItem.apply(); 7 d, _. m/ R$ q, \/ M8 ~7 |# u7 Y
9 C5 D! w% D4 ~* o/ f, }# a
// Test for an error.
* ^9 d: c" o* o, P! N2 lif (results.isError()) { ! \$ L, f, t2 _6 J
top.aras.AlertError("Item not found: " + results.getErrorDetail());
" L2 I5 Q* R& T return;
$ n% I3 Q" l/ y5 {} ( ` M, R6 o1 _' r* T1 H) W
* o" q, g# a6 n- f3 }5 f// Get a handle to the BOM Items.
' h; j+ {5 h$ Yvar bomItems = results.getRelationships();
0 w/ J" u# ]# A8 [: Rvar count = bomItems.getItemCount();
; o$ b& e4 g3 w2 M+ D# Y9 q `- J
* Y2 u6 g2 G9 ~+ {8 F, ?// Create the results content.
# _; U9 R& Z# @, Zvar content = "<table border='1'>" +
2 Q: ]- K C# f4 i9 K# S "<tr>" +
3 }+ X3 r! M8 e% r "<td>Part Number</td>" + + R1 I9 B- S) q0 j1 w, F
"<td>Description</td>" + 3 s! Z* @- d+ e+ C( ?
"<td>Cost</td>" +
* V. u v) G4 b# g+ F9 |/ M# r3 c "<td>Quantity</td>" +
0 Q! m9 @3 C" s! n "</tr>"; 3 D' q% [6 w. f3 y$ b4 }1 a/ }( O2 l
# @ ]; H6 ]. p' f/ \) w// Iterate over the BOM Items. 8 q1 O# X% @8 U% ]- ]+ D
for (var i=0; i<count; ++i)
( }0 s; H4 n; [# K! Y8 q{
0 U# e5 |4 L& m// Get a handle to the relationship Item by index. ' `( K4 r* U( t/ U
var bom = bomItems.getItemByIndex(i); ! j; W' x2 ?, `. F
// Get a handle to the related Item for this relationship Item.
* B; C* y& z3 r/ t O) T var bomPart = bom.getRelatedItem();
) U0 B- n* {: a( ^( I4 t6 V 7 S% G' t" ^: z" Z* a' z
content += "<tr>" + ! t6 _" N" @7 K: y0 X
"<td>" + bomPart.getProperty("item_number") + "</td>" + . y2 c+ k* E" R
"<td>" + bomPart.getProperty("description") + "</td>" + / n0 u# f( `/ X
"<td>" + bomPart.getProperty("cost") + "</td>" + ) r. _: u, j; y( P- ]6 Z$ L
"<td>" + bom.getProperty("quantity") + "</td>" +
% U: `: U% V% O# L, R "</tr>";
7 s N8 ?: g6 t} 0 v, Y4 \# c3 F4 k
return content + "</table>";
0 k, `, j0 W3 v
+ ^6 y6 p4 z% i
8 k9 h" T/ ^ D1 P; F8 j c4 ^
; }) H3 d& b0 o) M: {6 @9 y1 l; @& @. _5 O) A
C#
0 D4 U% v) ~ y8 Z% _/ bInnovator innovator = this.newInnovator();
, K' w! v% b" s! W 2 ]2 q* h& K" E0 f8 _
// Set up the query Item.
& x3 I4 S1 \. ^- p& ?Item qryItem = this.newItem("Part","get");
7 q7 Y/ B; J( z+ R, c: xqryItem.setAttribute("select","item_number,description,cost");
) k9 r; f! H5 M9 c3 T# b( sqryItem.setID(myId);
5 l: O5 j! W' L3 j G- f4 @, Q$ ]8 G5 @( t
// Add the BOM structure.
/ w. R2 Z: D2 f2 P5 o- i6 V6 YItem bomItem = this.newItem("Part BOM","get");
2 B: L4 H5 A) V N* jbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
! }0 u* I+ }, `" S# HqryItem.addRelationship(bomItem);
7 v4 g& z' v/ u! a9 X
& g' b" W7 q- q2 |# ~0 }6 M// Perform the query.
7 ]* C% V0 ?& I& y' K/ i7 CItem results = qryItem.apply(); 1 N5 g# p( R3 Z! W
) W# M9 i: Y4 c// Test for an error. % h$ Q) E/ O2 R! a# Y4 N n0 w
if (results.isError()) {
3 ?3 m% S: F: c. R# J4 Y4 |0 Z { return innovator.newError("Item not found: " + results.getErrorDetail()); # @" \3 U% h- }/ P' W; G
}
9 ^9 s! q! X" D! W( K 0 H( P9 n3 c h6 Z* W- P
// Get a handle to the BOM Items. 8 X7 T# K1 o1 m" j1 z
Item bomItems = results.getRelationships(); " o# `& |7 q+ b' Z, D) B
int count = bomItems.getItemCount(); , j4 n# d% A0 P j( B
int i;
0 D9 |* t* N! V% Q: e4 \
% f" J6 c( Z# E# Q1 j7 q// Create the results content.
& ?6 _* l) Q$ `1 f% s$ Y' [string content = "<table border='1'>" +
F3 E$ {, s: b3 Z/ L8 i8 b8 p8 G "<tr>" +
# @4 s# z* |3 }& l9 d; ` "<td>Part Number</td>" +
; w& S& a$ H P" a3 a "<td>Description</td>" + ) J8 j$ K& ?/ @
"<td>Cost</td>" + + t- ^2 @+ l" W. r: `
"<td>Quantity</td>" +
5 i: x) v: F6 ] "</tr>";
' j" l Q5 K9 _" K I 5 S! N# x/ V, C7 x q
// Iterate over the BOM Items. / A1 K2 m+ x6 {, X
for (i=0; i<count; ++i)
, G% y4 V6 j8 H$ N6 [{
0 `" v1 n0 |. u v1 r4 ?$ N* x// Get a handle to the relationship Item by index.
! w- Q. x6 }, k2 T Item bom = bomItems.getItemByIndex(i); + ~/ D l$ D5 f/ H0 n, j B/ G
// Get a handle to the related Item for this relationship Item. 5 U- u* I0 w, W$ _: S0 _& }
Item bomPart = bom.getRelatedItem(); 1 s+ {' |. e. i# k& `' q
/ Q+ @/ d" ?0 q+ z% [. X content += "" + 3 v7 V* q$ N5 @ y9 J
"<tr>" + + b2 o, e# ?, z( W% H
"<td>" + bomPart.getProperty("item_number") + "</td>" +
+ J5 w" T' f8 f; h "<td>" + bomPart.getProperty("description") + "</td>" + & C) B3 x3 C5 m. P
"<td>" + bomPart.getProperty("cost") + "</td>" +
4 G9 H# @) O8 ^! h7 l "<td>" + bom.getProperty("quantity") + "</td>" +
/ X' U2 _& k2 X- a, w "</tr>";
5 b6 v& O! o* J m} 2 Y3 K+ O# W- ^# E0 l
content += "</table>"; $ G$ } C& H. _$ |, }& V
9 O2 }. U# j7 y G+ u4 ireturn innovator.newResult(content); - ^- Q; p" u; A5 `# ~( y
. {+ E0 @( v% `; C G9 I- |! b. B3 e" ?8 T( c% E# A
4 u" y7 l2 ]+ ^2 Z
! q1 d$ ]+ h# b, \5 o
' Z- |2 {( e k2 `4 }$ _
, y: }& N: u& _1 z ^% i3 M
6 E: `8 g" d- F+ m! X Page 46
# U% N9 x( H8 p; `7 t+ _
' ?9 {0 y' }! ~$ P9 o F* W8 XCopyright 2007 2 ~+ F. Y$ Q: L0 A3 ]! ~6 E/ b
Aras Corporation.
, Q: `9 ^4 l- AAll Rights Reserved. $ k4 h% G% R* t8 n. r+ h$ h/ i
VB.Net
6 R1 N+ E' U" q( P" N7 x( @Dim innovator As Innovator = Me.newInnovator() 2 [# ^; ]5 N4 c" |
8 V! V$ o; ~; M9 R2 b6 u! R' Set up the query Item. 5 ? k: q( u. `! U B
Dim qryItem As Item = Me.newItem("Part","get")
% K1 Z0 V/ O% ^. `qryItem.setAttribute("select","item_number,description,cost")
) C! d) F7 s- f kqryItem.setID(myId)
, O; f. e6 _ @( Z8 w1 u
- U4 |+ P8 i! Q* o/ n' Add the BOM structure. " r3 R+ _1 ~1 |: I
Dim bomItem As Item = Me.newItem("Part BOM","get")
/ l: R1 U0 a% ? ^3 ^bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") / O3 `! `" }, s( p( n a
qryItem.addRelationship(bomItem) : [+ y1 e/ } q9 n; G
1 L5 n E1 Y* r$ X9 F' b7 x$ m O' Perform the query. 8 y" Y y1 w) T! _" p' X( b- q% U- n9 |
Dim results As Item = qryItem.apply() , S" w6 _5 T; e/ X) O) R
8 a) |# Z; V5 u' Test for an error. 9 t$ t6 Z0 v0 j& z: A
If results.isError() Then
* Q1 N! E8 ^% N; [0 L/ o) @0 Z Return innovator.newError(results.getErrorDetail()) 3 z/ V. D; v7 b) r. o: O( @
End If
( H* L! `, Q% H0 J$ y
" c' ]8 e3 P% |& L& z' Get a handle to the BOM Items.
# x. f* L0 W; L7 @5 gDim bomItems As Item = results.getRelationships() 8 M/ |' D( b2 ?6 N
Dim count As Integer = bomItems.getItemCount()
; [ J! d! v, \7 j/ cDim i As Integer
" s5 }/ H4 w( c' U* K1 H" n l 1 l+ A9 y) }" _3 }- j
' Create the results content. - u& h! N& h" a1 u; F
Dim content As String = "<table border='1'>" + _ : u. J; Q, k/ u
"<tr>" + _ 7 R! ~# z, E5 O' H8 }& p U( P' W
"<td>Part Number</td>" + _
. U t) _ m; |! M! r- ], U/ W "<td>Description</td>" + _ ( w" M( T2 t2 m! J5 V
"<td>Cost</td>" + _
" E! V+ _! ~, n$ x& k1 N, t "<td>Quantity</td>" + _ . x! ?/ [, g, U' W1 L
"</tr>" 9 ?. Z5 E: W% K: Z# x
- f8 x0 g; o/ _; s u* [; ^' p' Iterate over the BOM Items 6 m1 x6 W( V! U! l) R2 J+ G0 B: u
For i = 0 To count - 1
6 Q5 N$ D3 n* J, s6 U' Get a handle to the relationship Item by index.
+ M& d; g" y, v, k* G Dim bom As Item = bomItems.getItemByIndex(i)
! l+ p) ]& Y$ L" o4 W
& j, J$ E; G4 [4 L& a7 N' Get a handle to the related Item for this relationship Item.
; d% n& c2 S3 {1 v5 } j Dim bomPart As Item = bom.getRelatedItem() / J3 \7 I: v& F2 I# a' p. \
; b! ?: z( ]" f; q' A- `: j% v content += _
8 P b8 L" N1 k "<tr>" + _ * W5 w! k* ]/ }+ i
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ : Y6 q. C. t$ d6 {* P3 N
"<td>" + bomPart.getProperty("description") + "</td>" + _
2 u" _2 O$ G. u: _: p "<td>" + bomPart.getProperty("cost") + "</td>" + _
! y3 \: S6 i `; S/ i F& x "<td>" + bom.getProperty("quantity") + "</td>" + _
9 V6 |) {1 s" B5 h, y, ~. E' V "</tr>"
4 f0 w% P2 B' W! {! mNext ; }8 O/ x2 ^+ @" V
content += "</table>" / \9 c3 o* f3 k- u
( g$ u' D" n6 M: y: D" T) z4 N
Return innovator.newResult(content)
) z* K( D3 K& W
, h3 w2 J7 a7 h% f |
|