|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
6 ?1 P+ D, b! lTo query for an Item and retrieve its structure you build the query as the structure
! W. d3 E, o$ X' i0 n' o+ Fyou want returned. Use the IOM methods to add the relationships you want and 9 D8 D. C/ l" c, k7 c2 ^
build the structure in the Item. The server will return the structure that follows the % ~: v' o7 W9 A9 {3 [
request structure. 7 G& e# v2 J! C h9 w) w7 {
This recipe illustrates several related concepts together, which are how to get a set
' t$ g+ b' N2 |% P* oof Items from an Item and how to iterate over the set, plus how to get the related
4 a9 ^- @- O7 \9 ]7 ]9 Z# a6 N4 u- GItem from the relationship Item.
& V9 }; R- N {; PJavaScript
0 E7 e$ N8 c, w4 _var innovator = this.newInnovator();
, @; h; ~9 b' m. w % a9 S6 `: P% a. t6 ]0 P3 p# x
// Set up the query Item.
. e- w+ G$ N1 b1 m$ N+ Cvar qryItem = this.newItem("Part","get");
0 q8 P4 i* |# s! T* T4 _qryItem.setAttribute("select","item_number,description,cost");
( B/ R8 M6 [: L: F5 g; b; r0 aqryItem.setID(myId); 9 j5 d! |) d4 o( \$ ^" _# g$ c
6 _. C4 Q0 M8 Y4 j+ v+ L! w# N3 S6 i
// Add the BOM structure.
7 o3 X3 [* O- K9 Qvar bomItem = this.newItem("Part BOM","get");
) Z8 H+ d3 D% g, |bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
0 ]. P" z- h' h7 X. c/ wqryItem.addRelationship(bomItem);
3 U; |: N2 z' o( G/ F8 u1 g9 b+ N ^& `4 ?: c/ N7 Z
// Perform the query. . o0 O' q) |. [8 i3 }9 E p
var results = qryItem.apply(); * v" `+ a* V( B- S- n- s
5 K" _0 c9 R! C& z R0 Q3 V7 Y2 e
// Test for an error. - o5 `7 Q% m! x$ r# Z( W: c
if (results.isError()) { - U- c$ W8 x$ v2 \$ I! k+ x
top.aras.AlertError("Item not found: " + results.getErrorDetail());
4 C! k9 M; ~$ T1 m return;
% f( R6 y/ ]1 l} , v# w" A" M( D2 K1 ~% ~
, m# g" O+ O& o5 ~6 M9 T# N @
// Get a handle to the BOM Items. + G$ [, p& `! E3 ^1 G- [
var bomItems = results.getRelationships(); " Y# Z1 |6 [' l% {# q
var count = bomItems.getItemCount(); ! I% h9 G- I) V4 e4 g
0 O7 o5 q* R" b! l
// Create the results content.
& _, L' n' C% H$ o/ O+ @) gvar content = "<table border='1'>" + ) C' T$ e) X" @' i
"<tr>" + 2 k0 z- L$ A4 v0 Q0 a: x
"<td>Part Number</td>" + ( X+ a9 a ^4 V% g
"<td>Description</td>" +
% D! k/ Q; v) n4 q C: ` "<td>Cost</td>" + 4 X1 L, O# ^( D+ E9 ~4 ?, e D
"<td>Quantity</td>" +
3 g1 Z* s( V" S$ A+ O1 M1 }1 E "</tr>"; ! }& ]& h: J. D( S3 K
9 y' h6 X3 D" i" Y9 r3 M& d! G// Iterate over the BOM Items. : |" E5 \" r9 E1 O `2 s1 o" ]0 R
for (var i=0; i<count; ++i) - K; [- u2 V9 f
{
( ^4 [. N: K& T- b// Get a handle to the relationship Item by index. * u1 {8 F" o' i8 x
var bom = bomItems.getItemByIndex(i);
6 C/ e. E4 q. k// Get a handle to the related Item for this relationship Item.
( z7 f$ ?, \/ ]% m var bomPart = bom.getRelatedItem();
: H9 ?5 ?$ o3 A
8 L& z- h4 ~6 X1 l5 M4 \ H/ Y2 ], ] content += "<tr>" + 8 {- L: y0 z6 Y8 S
"<td>" + bomPart.getProperty("item_number") + "</td>" +
+ K$ l: U! j9 R5 F "<td>" + bomPart.getProperty("description") + "</td>" +
( N- W2 z/ l( Y; B "<td>" + bomPart.getProperty("cost") + "</td>" + 6 v( p L5 j4 s5 {. K0 a
"<td>" + bom.getProperty("quantity") + "</td>" + / F9 r' b3 N% q$ E) F
"</tr>";
) N8 k( L8 y+ j! h}
; B6 ~0 }. `- n. ?7 Ureturn content + "</table>";( [7 f+ m4 ~7 i1 W8 o' O& d' C
( K1 G, @" v8 k) q8 c
5 `. c0 W$ I9 u- i1 R" ?9 {# p. ?
2 @" U5 S8 }! U
7 A" N, P4 O5 z% V- c$ u
C# 1 u* T# Y+ [; n/ V l, u4 i
Innovator innovator = this.newInnovator();
2 o" u: m! H8 V4 [( S! a % {( G/ D0 |0 X8 u' @; |
// Set up the query Item. , I; u/ {* P+ R/ X
Item qryItem = this.newItem("Part","get"); & p" ^* w9 i" P* f
qryItem.setAttribute("select","item_number,description,cost"); 0 l. _3 e! I B; a
qryItem.setID(myId);
$ r8 Z" @& F, u* Z9 b
# V' c, b- X. x3 P8 S0 j3 N$ J// Add the BOM structure.
0 M/ w7 B, D+ Y! g2 }Item bomItem = this.newItem("Part BOM","get");
! c! z) c4 S( _5 XbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); " w4 E8 V: S. \4 ~- p& M
qryItem.addRelationship(bomItem); 0 A; ^/ N' I4 |0 Q8 ?
6 e+ k& ?: V( K/ s7 u// Perform the query.
( n" n0 S% z! \% |, r5 kItem results = qryItem.apply();
- { N; p8 B7 d, E7 n& _1 Q& }" [
! n" ~$ _0 r0 w! q2 U1 Z2 |// Test for an error.
1 V T% X! B4 [* a0 ]if (results.isError()) {
/ D, S4 Y2 u) o! S; B return innovator.newError("Item not found: " + results.getErrorDetail());
2 r# W) K* l5 d& h* B) e}
/ p' T }4 Y7 F3 J; J
9 i* |/ y, w$ j// Get a handle to the BOM Items.
0 v/ Z$ s. \ K1 SItem bomItems = results.getRelationships(); 1 N9 Z" f2 ]+ Q& X6 b9 |
int count = bomItems.getItemCount();
1 M/ x8 T+ }9 Bint i;
5 V8 ~7 f# w' f$ _* L$ K) F
% c% J. B7 ?6 O, q6 _/ Z0 A// Create the results content. & r) z7 b. v0 @8 F8 ]( F7 o
string content = "<table border='1'>" + 3 s# L) y) Q* y
"<tr>" +
0 ^8 n, ]3 T ^1 t "<td>Part Number</td>" + # q) ]1 F1 ]9 a) M' }4 K0 i! q
"<td>Description</td>" + " H% V) X2 _5 P/ e7 T
"<td>Cost</td>" +
* y2 J8 C- a7 h: E v8 J2 Z "<td>Quantity</td>" + - |" f5 p; X2 Y: c+ b* H' F( f
"</tr>"; $ S2 w8 G% m& u+ Q# w: m
6 ^ ]0 K `/ s: ]
// Iterate over the BOM Items.
( a) N& O& l6 @' K$ Afor (i=0; i<count; ++i) : J* {$ i( p* x$ y' ^2 v$ J0 h
{
4 x* m8 q9 G( x/ f7 z# |// Get a handle to the relationship Item by index.
$ k0 }" s5 H- M, N Item bom = bomItems.getItemByIndex(i); ; k# \) h* k* f: D( Y V0 y
// Get a handle to the related Item for this relationship Item.
+ W9 i6 s+ |: n3 d- I Item bomPart = bom.getRelatedItem();
4 o) [$ `: T4 s& z) q
9 W; Y) x+ w9 k( ?6 W5 d O7 ] content += "" +
. I3 h H" [1 _4 [ "<tr>" +
: [& f; \- A) K W "<td>" + bomPart.getProperty("item_number") + "</td>" + o$ ?- ~7 }/ c4 v* L) h
"<td>" + bomPart.getProperty("description") + "</td>" +
) I( O( O: W3 w9 }7 i1 g; r "<td>" + bomPart.getProperty("cost") + "</td>" +
' l) N- c: {1 c5 ~5 a "<td>" + bom.getProperty("quantity") + "</td>" +
" w5 ^$ T' c- H5 _" `% \7 G( z+ a "</tr>"; 3 k! f d- E: b) J/ F) [5 p8 o
}
% m% [( y0 u, i1 N1 X( M4 c% z, Kcontent += "</table>"; 3 C' V+ a# g+ T. G
7 w+ e! O6 r! I3 greturn innovator.newResult(content); ( i5 s3 E3 A1 E
& x, ?* a$ w6 L0 M( o; U
4 C! z' z% T! R9 ?6 n
' D$ g- p: F' j, \6 ~% p% J5 f2 i. q% b
) \$ S1 V% K2 ~6 Q+ c
3 |, I0 f. S' f
% Q( K" w+ Z0 P6 G Page 46 # h$ K6 A6 t0 n6 m
. T8 U! r2 e) B2 A) i$ h
Copyright 2007 0 o' w6 X h8 R* I8 U! D4 J
Aras Corporation. ) B+ R; b5 a, U* Y- g; @# y- b
All Rights Reserved.
' O* X# W/ k/ e8 G# s9 ?VB.Net
% |+ `- U, ]0 ]% T4 K" zDim innovator As Innovator = Me.newInnovator() + G; M3 o! h1 c) L3 u y
9 W/ J ~' ^8 K' ?" t
' Set up the query Item. ; ]. @8 F( V5 }
Dim qryItem As Item = Me.newItem("Part","get") * Z$ Z) k5 Q( _. G! h
qryItem.setAttribute("select","item_number,description,cost") V7 @* h! u, a% H7 [
qryItem.setID(myId)
) W" G Z# g0 } \ O& O / e8 z6 w# a5 w+ s- _; m# }
' Add the BOM structure. 8 b0 e2 F3 E. `
Dim bomItem As Item = Me.newItem("Part BOM","get")
# H/ y7 u6 a2 O' [5 `) \& MbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
: x+ N# y+ o2 w9 X+ f4 hqryItem.addRelationship(bomItem) 5 W! |' ^! K% L7 T9 G
* |# x, O6 M m; Q, I' Perform the query. 7 p5 |. O3 ]/ T, b* p& G
Dim results As Item = qryItem.apply() : R% X5 g7 y: _5 ~: s6 R. B
- C5 C% a9 E- l$ k
' Test for an error. " f1 |# v$ N" r3 [1 @
If results.isError() Then : r2 o4 d. E; K& t
Return innovator.newError(results.getErrorDetail()) & P9 C' G2 b' T5 W- w) M
End If 1 f. `9 j9 T, B9 g
V3 _. a- q/ m' Get a handle to the BOM Items. * j4 i4 @: I0 y4 M6 O' p1 y$ {
Dim bomItems As Item = results.getRelationships() 4 Y7 V! I4 F7 w
Dim count As Integer = bomItems.getItemCount() % H' C. l; r; N; y
Dim i As Integer 6 E& u, |( H. c) J' {
" C$ v& i- K/ I; a9 ]# @* G
' Create the results content. + n0 `! Z& S: q- t
Dim content As String = "<table border='1'>" + _
* o% s; b2 E% i "<tr>" + _ 6 n q6 y7 M9 t& S8 U
"<td>Part Number</td>" + _ 4 J. a2 O3 J" p2 `1 P
"<td>Description</td>" + _
0 Y2 B6 @8 }% `' K) O* P "<td>Cost</td>" + _ : C* l5 ~$ h7 w+ v5 m8 A
"<td>Quantity</td>" + _ . u& q' w) T3 C1 `. P. s2 H; A
"</tr>"
# N/ U; a* |* L( }: N o9 j
7 A7 B$ z6 F [" q8 g7 t+ `* x Q N: S' Iterate over the BOM Items # O/ l3 N) {! Q2 N& h, |- P
For i = 0 To count - 1 5 P+ Y* n# j( z: g: @4 |" M! H/ ^3 T! h
' Get a handle to the relationship Item by index.
- _0 O% L( K1 _; R9 c Dim bom As Item = bomItems.getItemByIndex(i) 3 p. ~' v d. H! N6 ^$ r3 e/ {
$ `+ y& _/ N) L4 n9 Z- f5 F% c! s3 O
' Get a handle to the related Item for this relationship Item. 0 G: E' f4 [8 l( t
Dim bomPart As Item = bom.getRelatedItem()
4 Z. m! c9 _2 b! Y' t) }: J 4 n4 x2 e. Z( _9 i; O3 i& \0 [, V
content += _ % a. V3 A3 e. j ^/ t; {
"<tr>" + _ ! ]6 S0 m7 ~ |6 L5 @: F9 R
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
$ X1 A8 Q( P k "<td>" + bomPart.getProperty("description") + "</td>" + _ / C( H# i1 T" R3 m5 F' D% V
"<td>" + bomPart.getProperty("cost") + "</td>" + _
6 R: P( }. Y& h f, f. Y% l "<td>" + bom.getProperty("quantity") + "</td>" + _ & o2 W0 e3 H9 O. R/ ^$ j
"</tr>" + f4 r5 w# v. g9 M
Next $ }- s. a9 h6 @
content += "</table>"
+ b% H0 Y9 ?, ]1 X8 Y ( p: p% k; H3 r P; O* T/ c$ C
Return innovator.newResult(content) ' i% q7 A. j" G/ l5 w) W
* @2 F" N& {9 y& d0 z |
|