|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
. o. G: \7 L& H6 m6 ]' r# K, _To query for an Item and retrieve its structure you build the query as the structure
& N; A& [4 B4 n* q' _you want returned. Use the IOM methods to add the relationships you want and
" G0 G! R: q3 E. x2 |8 q- Y8 Bbuild the structure in the Item. The server will return the structure that follows the
! s2 j; R( e2 y( O/ \4 Z) [9 zrequest structure.
* R# y; J3 s- G7 \& ]1 X/ m: N) R* W4 p$ rThis recipe illustrates several related concepts together, which are how to get a set
1 t% N- K. s4 |& T' F8 C% oof Items from an Item and how to iterate over the set, plus how to get the related + G: f! ^; K# Q, e
Item from the relationship Item. 6 Q9 b- i4 I4 |) T/ y7 @. {
JavaScript 5 }7 P/ b. _1 W
var innovator = this.newInnovator(); ) s2 h! D+ B n! N0 k+ I7 y
4 X- ^' B" N0 T' D
// Set up the query Item.
$ m) O4 C7 O: e* U( x3 Z+ w* _var qryItem = this.newItem("Part","get");
/ @0 ~6 d/ i) n$ ZqryItem.setAttribute("select","item_number,description,cost");
2 m* n( g/ Q$ C9 C( oqryItem.setID(myId);
! B; J2 g; D1 |; t2 {
/ j D$ n+ S4 D6 x// Add the BOM structure. - x+ }. u7 i! p& c/ c' S3 R' |! o
var bomItem = this.newItem("Part BOM","get"); . l' e! }/ y( ^$ q" T
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
0 G' Q/ B# ], ]$ cqryItem.addRelationship(bomItem);
& n# q4 T! }( w& X6 X2 o0 o3 V8 _ ' U* i% s1 b8 W# [
// Perform the query. 6 f2 U1 }" Q& p4 X8 X; Z/ }/ Z
var results = qryItem.apply(); 1 f: ~3 m/ W# f/ [0 P' B
3 N3 s( Q5 o% ~9 A2 g% L* V
// Test for an error.
4 o0 i ?- P6 m- K; |0 Qif (results.isError()) { # q# ?0 D9 x1 R5 k3 V, N7 Z- _5 c0 l- i
top.aras.AlertError("Item not found: " + results.getErrorDetail()); . A. i0 Y! ?- Z" ^. \
return;
8 A6 O! s3 f+ \- f} ' ]* s3 S# ~( Z0 T" a* X
, m4 l7 b" ^* X
// Get a handle to the BOM Items.
6 e+ w* f# {4 [: _: C4 b/ Fvar bomItems = results.getRelationships(); ; B% G$ o( ]3 X2 U
var count = bomItems.getItemCount();
# B1 f6 I z+ l' ~% |+ L; C' x - k' b, w) S" A$ @. d
// Create the results content. 8 o- T+ T" i! x( g6 Y4 V4 @4 A0 W! e
var content = "<table border='1'>" + 9 R0 d% i8 J4 m$ y& w/ n
"<tr>" + ; B9 L h. Q: K0 [- G
"<td>Part Number</td>" + 6 \" E6 P( _7 A* a( L
"<td>Description</td>" +
( H ^4 x2 ?2 a1 |' I "<td>Cost</td>" + 3 ?1 C2 y4 W( S* H* c
"<td>Quantity</td>" +
2 c4 c9 W% ?& Y: ^( b, f# ] "</tr>"; . I! X% R: o% o _, o: l- D
# z7 t% u, Q+ o7 i3 ?3 b// Iterate over the BOM Items. 5 R% L& Z8 U- f' j" B5 }) f4 J, E' S( w
for (var i=0; i<count; ++i)
3 Z, i7 P$ \1 x( ^- w, X+ R5 h9 }{ 7 Q" }( ?5 M2 }8 c. g
// Get a handle to the relationship Item by index. $ O/ v$ m" E+ Q* s9 x$ \. j
var bom = bomItems.getItemByIndex(i); & C* j x, T- P
// Get a handle to the related Item for this relationship Item. / F, N/ q% C& Q, ?- g& S5 F: i
var bomPart = bom.getRelatedItem(); $ O4 i, T' u0 W F* c+ P3 T
# Q; w( x: h7 M5 a/ ?
content += "<tr>" + 6 _8 l# v0 U: J z
"<td>" + bomPart.getProperty("item_number") + "</td>" + / M8 ]7 s0 e* c
"<td>" + bomPart.getProperty("description") + "</td>" +
& a8 r0 t5 q4 b "<td>" + bomPart.getProperty("cost") + "</td>" +
& o) H: d2 Y) M, }% ` "<td>" + bom.getProperty("quantity") + "</td>" +
) K. }- k* a4 |* r "</tr>"; ) c+ h0 U, Y4 O/ Q' A2 g
}
' T) F# n* o9 F+ d# s% Breturn content + "</table>";
0 r! p, y/ i$ J" w7 _+ W- l7 m
+ Y8 ^$ Q' H' |( T1 G
/ s$ \' W8 G6 X) n$ }' k6 m8 T" x
5 o% A% D2 C( a2 n# E Y; S1 l
C#
+ U1 \3 | f& e8 m+ E% TInnovator innovator = this.newInnovator();
! X3 R& T1 k* h1 H/ x# M. |* y - V& \# }9 U& ~5 X! c) d* k) l; k; h
// Set up the query Item. 8 a' u |) e3 ^4 ]4 ~/ S
Item qryItem = this.newItem("Part","get");
; G% [4 |0 P) M% r" CqryItem.setAttribute("select","item_number,description,cost"); ) B: e6 Y+ p }9 D( v
qryItem.setID(myId);
/ z& R1 v9 T/ O: x+ h # j; s7 n4 W6 F( F0 a6 X
// Add the BOM structure. 4 Q8 n1 ?- h! U1 j" p4 Y4 x
Item bomItem = this.newItem("Part BOM","get");
3 B+ a$ { ?, G# z" p4 IbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 7 T8 I+ B6 ]% z' v' `* Q
qryItem.addRelationship(bomItem);
# ~9 s2 \0 {" U% n
6 i( N; \ V( a- o' c" R3 S// Perform the query. : ~; B6 j& D6 {# n2 O( _6 Z
Item results = qryItem.apply(); + D& x1 f( j, E% u& c. g( M* M
2 w. K2 G8 r" R
// Test for an error. * d9 e% P4 J- ~! Z* N7 N$ m
if (results.isError()) {
1 C" [2 b" I; J1 l return innovator.newError("Item not found: " + results.getErrorDetail());
3 p1 y, T- A, i3 t. _* `} 2 M9 g3 u! l8 z, `' a% O
& ]* I6 k% D1 m- z+ N3 P7 F2 e7 O+ E
// Get a handle to the BOM Items.
8 M" I7 x, v, C6 x4 l3 EItem bomItems = results.getRelationships();
) M' b& X+ X1 T' m O1 N# P+ D: }int count = bomItems.getItemCount(); 7 s! E* `& S: V, c8 J' |7 U
int i; . T3 K8 b& B C9 y% N
% U6 X* N% v& C# H& n
// Create the results content.
. L" z% ^5 t9 \- X0 ~string content = "<table border='1'>" +
A- g) A1 [) H' G "<tr>" + % C& w% b3 i, z/ ^/ \4 Y
"<td>Part Number</td>" +
3 P2 o6 P$ l7 ^+ P( V" C ^% f$ | "<td>Description</td>" + + A& H o' w3 V* n
"<td>Cost</td>" +
. L: P0 w% A/ O' e "<td>Quantity</td>" + 8 K" H5 R% S2 {: _
"</tr>";
1 i, K) H8 W* ~3 l3 Z' w; T* R' @8 h, Z
l1 p8 G7 x7 m. b- ~// Iterate over the BOM Items. % M3 K! W9 r' k! Q$ h0 }
for (i=0; i<count; ++i) % L3 @* j% ?. X; M' l8 m9 H6 J
{ 1 u6 x" A( D! T
// Get a handle to the relationship Item by index.
+ y$ x |9 ?7 P. S2 f8 C5 _ Item bom = bomItems.getItemByIndex(i);
: e' i: s H# o. H( p' ?" Y- H// Get a handle to the related Item for this relationship Item.
) |3 {! d/ j1 c8 y" q" a, d4 c) ? Item bomPart = bom.getRelatedItem(); 6 y- W. N2 m3 o4 ]: [0 g* ?
9 V; K# {8 r# x* O% W3 N3 ~
content += "" +
9 s3 Q* o0 c4 ?* Z "<tr>" + ) R2 \$ H! X9 x! [! ^/ n
"<td>" + bomPart.getProperty("item_number") + "</td>" +
5 v8 V. X% \8 P& i "<td>" + bomPart.getProperty("description") + "</td>" +
/ Q* R% y; c! \4 M% z0 ] R. T "<td>" + bomPart.getProperty("cost") + "</td>" +
( o: J) a8 h& s) b8 [! t m9 X3 ~ "<td>" + bom.getProperty("quantity") + "</td>" + + P/ M% y0 Y9 R( {: s$ w( h2 n
"</tr>"; ; y9 Y W# B2 {- E( F
}
0 v3 e. d- H5 |4 T2 \0 Gcontent += "</table>"; _7 ~2 ? D. L h p! ?
9 {4 I, q* I5 B2 B* u3 Z
return innovator.newResult(content);
! _% Q+ |: Z8 s- o+ t
! C% ]. |; y4 |; q" _0 S4 V0 z
2 w. ]+ `+ j- y2 {- \% i3 F
?! w+ @. k! H
, U! T4 [/ D3 `& V: `
; g9 e- Q/ K! ^3 `) e: D+ }( O
6 |2 U/ Z$ v" N; P) C" n. Y- @ 3 `0 k" `6 S3 o0 G
Page 46 ! _. F" e0 {6 l, s# U& n7 b
0 E, P- z& g! N1 d( L1 D
Copyright 2007 5 c; @2 M: i3 J8 a( C6 y! u" c
Aras Corporation. 1 {9 s4 z, d& d5 P Y! ]# d2 G
All Rights Reserved. # `/ ?; y, j7 Q E
VB.Net " \/ R2 R! r7 A
Dim innovator As Innovator = Me.newInnovator()
; T& W8 @" U' [% k% V* | 5 C2 h/ \3 P' q @0 z: |/ [
' Set up the query Item. 4 {) i' L5 V( Y. e& L
Dim qryItem As Item = Me.newItem("Part","get")
9 H4 i' O# @" q. E/ Q! sqryItem.setAttribute("select","item_number,description,cost") 1 e- o* [3 t3 g& A+ s, e! q
qryItem.setID(myId)
7 f7 V* U& r R u k* G
3 T' S% ^% w( N* b4 r6 b' Add the BOM structure.
9 X& m# p# [5 M* w7 b8 ^Dim bomItem As Item = Me.newItem("Part BOM","get") , \, g* A: l( \- h% J
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
% p* |; d0 _9 H9 M- S4 g6 XqryItem.addRelationship(bomItem) + Q! r( v. g6 k6 |& ~% @
0 {( l( t/ |/ `" j: t4 @
' Perform the query.
: X/ J& I: H* z, ]Dim results As Item = qryItem.apply()
1 Y& _2 F% N$ Z) t S
" g/ F4 k" u: F% U- e' Test for an error. 2 [, Y- S2 u( |9 B- D
If results.isError() Then 6 j4 I* C6 t' `: p' e
Return innovator.newError(results.getErrorDetail()) 7 n% T" M: {& q" `1 `1 W
End If
2 {3 K! I0 h! ]3 w
: W: S; @! e8 t f2 u2 Y0 o' Get a handle to the BOM Items. 5 _' @9 P6 A: W$ s" s
Dim bomItems As Item = results.getRelationships()
3 Y" @% i0 { N4 O$ M! _Dim count As Integer = bomItems.getItemCount() ; o0 K& Y) L! z
Dim i As Integer
7 d! E& ?- j0 W- ]$ }- F0 H
! E0 I1 Q" v7 ^, c0 U) H L5 h' Create the results content. - A0 S4 v R1 b$ R3 f
Dim content As String = "<table border='1'>" + _
1 P: S1 q c% s5 C( V "<tr>" + _ 9 l: e, A: p/ X2 Y( A; p- b% |
"<td>Part Number</td>" + _
- b: R* v+ e8 s0 r "<td>Description</td>" + _
! L" x; l/ I1 Q "<td>Cost</td>" + _ ! g5 {; ?8 H% i4 j
"<td>Quantity</td>" + _ 0 |2 T; i; j) C2 Z( t" y
"</tr>"
, x6 D/ H( E" s+ m; P8 g3 K. i% n H* C1 Y( X! G5 C7 ~
' Iterate over the BOM Items 2 t9 B4 |8 J8 h
For i = 0 To count - 1 . x2 `+ j% _8 X
' Get a handle to the relationship Item by index. . a& v4 j; z% ^# O2 ~
Dim bom As Item = bomItems.getItemByIndex(i)
! Z& c4 b% y1 [# Y# i
, H/ s, ~5 s, R+ B' l+ ?3 C' K5 y' Get a handle to the related Item for this relationship Item. * r9 V% Z% Z! A5 N3 x* Q
Dim bomPart As Item = bom.getRelatedItem()
5 G7 O! Z; \+ M8 m ; q& ?* B* a4 S/ O+ @7 Q6 x$ I
content += _ " G7 e/ P5 B0 ~* w3 x# ^* W0 `: ~
"<tr>" + _ 6 W0 e) b3 F+ ^, Y* D
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
; M1 s1 \& n6 u; a- L "<td>" + bomPart.getProperty("description") + "</td>" + _ * O3 ~! y2 l* \2 e3 t
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ; F, h& O+ m' _
"<td>" + bom.getProperty("quantity") + "</td>" + _
; ~4 W9 A4 i7 m7 ~7 b3 R" Y "</tr>" ) V X1 Q6 c8 H. j
Next 3 o8 [% G! C! G1 m9 q& O5 V1 r
content += "</table>"
6 @6 V4 ~. ~0 Y+ I r. N. X2 q
* S2 Z) x; D/ z% @6 }, mReturn innovator.newResult(content) 2 G; ?) \) Z* F* ~5 A- B) B; }9 ]
* f. I# m9 {. D4 S1 H |
|