|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
7 j9 Y) T2 W" QTo query for an Item and retrieve its structure you build the query as the structure
9 R i8 R i6 `0 O6 J: Zyou want returned. Use the IOM methods to add the relationships you want and / G2 ^- S9 W! P2 V: h
build the structure in the Item. The server will return the structure that follows the 4 j* v( J y* ?
request structure. ' d' x& i# o+ ?2 S t
This recipe illustrates several related concepts together, which are how to get a set : a0 J7 I; n9 _9 c2 g
of Items from an Item and how to iterate over the set, plus how to get the related
/ M% _; s5 m; N4 p! I6 M; NItem from the relationship Item. % e) f- p3 z7 @
JavaScript 1 H, Y z9 t; X6 b
var innovator = this.newInnovator(); ! `; N7 [" ~- u0 ?, v$ J& x' l
& L- E& u; |4 H6 C! S/ h
// Set up the query Item. + M' `/ V9 o# W8 L& Z
var qryItem = this.newItem("Part","get"); 7 p. f0 }& A' s4 A
qryItem.setAttribute("select","item_number,description,cost");
" K0 o, f5 o$ j p; ^' F ]qryItem.setID(myId); & t9 G, V. Y/ }( F/ i
[; g! ^# q- L+ D4 o- C. B5 R
// Add the BOM structure.
5 c; F; Y/ Y7 e2 Dvar bomItem = this.newItem("Part BOM","get"); . X7 R! H' e0 c+ Y1 A* d
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
" ?* o9 {2 C# v eqryItem.addRelationship(bomItem); 5 [3 B3 R9 D0 U' D# @8 e$ l
( T- u& L9 W+ O5 ]. [/ [4 l// Perform the query.
: H, ~2 D1 b6 R+ k; t/ Y+ ]5 W* [ zvar results = qryItem.apply(); % h7 o0 M! E3 k- y8 I9 j
% f: g+ K9 O! ^2 l* G( N+ S- r// Test for an error.
3 [9 Y' I& R0 Zif (results.isError()) { ' }; U. `+ ^! s" k% E6 ^( ^) A
top.aras.AlertError("Item not found: " + results.getErrorDetail()); - f. X7 W" I% i& W
return;
- H2 S4 v8 p' s} : Y1 _. s7 T) ~0 U* n; f) u
* T$ a8 P- ?6 a1 K% p" S// Get a handle to the BOM Items. $ R3 K0 J9 s' i+ v' l8 N
var bomItems = results.getRelationships();
) j/ }, P( G: O7 _7 Hvar count = bomItems.getItemCount(); $ E$ {* j+ }* R- L: U' A* C+ ~
?/ V4 N* a I# n1 P2 I' T// Create the results content. 2 V3 B; H2 S4 w( B
var content = "<table border='1'>" +
5 u) c, w5 t- E; v/ L; W7 I4 d "<tr>" + & l+ p: Q$ M. m/ ~
"<td>Part Number</td>" +
1 h3 O- c, U* n: e- j X6 M "<td>Description</td>" + 9 c5 S: d: V" Y4 A6 t8 T
"<td>Cost</td>" + ) \, V3 q; F. G% y5 G+ y- [4 g% F7 H6 `
"<td>Quantity</td>" + - j4 c2 n; h: S0 E
"</tr>"; $ P/ ^( K* [9 \: t& T3 L
% s8 m( W ?1 n; F1 Z4 w& I2 R5 b// Iterate over the BOM Items. , T2 k+ S6 t+ Q2 {( g, L5 X
for (var i=0; i<count; ++i)
3 w" U" X8 i: L' u4 x; p! e{ ! F1 M9 F+ p/ D4 C
// Get a handle to the relationship Item by index. / y) b4 x) \! i8 r& ?8 ?( Q
var bom = bomItems.getItemByIndex(i); ! [1 z+ j' B) B8 q c4 ]
// Get a handle to the related Item for this relationship Item.
8 u1 e, C; K, Q var bomPart = bom.getRelatedItem();
9 }# T* k4 `. ]8 ^0 r4 s ) `) Y% C3 y p1 F
content += "<tr>" +
7 Z( v0 \$ Q7 w# i "<td>" + bomPart.getProperty("item_number") + "</td>" + & @3 S* | n! B7 b0 I* [/ O8 N; a
"<td>" + bomPart.getProperty("description") + "</td>" +
h# Z2 e" Q: F "<td>" + bomPart.getProperty("cost") + "</td>" +
" n, Y& G" {: K, U/ M0 L; |. _% i$ | G: Z* { "<td>" + bom.getProperty("quantity") + "</td>" +
6 i& d: V* {. p( i8 @8 f "</tr>";
8 @. Q3 G8 V- `}
* t' R/ u) m/ N( a) Breturn content + "</table>";* A; {& P, t( ?7 S+ c! T9 q6 `
* G/ z+ i7 G, w
- b0 O& z3 d( J& I3 E
, r+ [: ^* ^4 ^1 S9 ?
7 v; |2 N6 d% i3 SC#
' y+ w5 z/ N1 c3 A2 rInnovator innovator = this.newInnovator();
: s/ q* P3 g4 N5 j
; `9 @& Y+ ~! i3 M0 q// Set up the query Item.
+ ]# a0 n0 u; c7 G2 xItem qryItem = this.newItem("Part","get"); 6 V2 ~7 M4 V+ g- I
qryItem.setAttribute("select","item_number,description,cost"); 2 v; H; k9 Z O2 v# j
qryItem.setID(myId); - S9 H. b! j. m7 b/ ~1 m3 `5 k
3 ?) ^. B( L1 }4 S% V
// Add the BOM structure. # H C* S2 R3 S3 ?1 W
Item bomItem = this.newItem("Part BOM","get"); % n2 B. r* ~( X1 N2 C7 G
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ' n9 Z% k# J, w! Q( Z
qryItem.addRelationship(bomItem);
5 V& M+ s1 k, Q9 U6 x 5 z! w# u2 \3 ^+ r# D C
// Perform the query.
8 r$ P1 W. _8 M1 bItem results = qryItem.apply();
. Q7 Q* u( [5 y# Q% h9 v * g2 R: ^: C. z' b3 O& t
// Test for an error.
1 T6 Y. W U7 Zif (results.isError()) { 7 p0 R* a b( E# o: O
return innovator.newError("Item not found: " + results.getErrorDetail()); " q. q" }" N6 H' W
}
3 v5 k& ~4 J5 O+ ~6 Y+ l # T8 ]3 d- M b3 O# A
// Get a handle to the BOM Items.
' R5 |, N! V0 O9 c* [Item bomItems = results.getRelationships(); : O, N' s2 P, A4 e
int count = bomItems.getItemCount();
2 \' c% j. q; p* sint i;
6 T: ]4 R* t2 H6 X2 i$ Q7 ^; P% J4 _, z 0 V N) e9 ^" u0 q3 a2 ?; ^
// Create the results content. ! ~- C2 r( P5 B/ t5 {
string content = "<table border='1'>" +
5 e) D5 q9 I& J% }; N* D "<tr>" +
9 z: E' h: v% a* O8 g" e; x7 u "<td>Part Number</td>" +
8 w8 g4 C* \! ]$ v/ O4 ^ [ "<td>Description</td>" +
5 t9 L; @' b/ s+ u% [( X. }( F "<td>Cost</td>" +
" \6 `* V) ]) E "<td>Quantity</td>" +
4 f( G2 Z" E/ E) d "</tr>";
" b% Q% j: T% a2 g
! q& o) t. w! g2 L$ ]// Iterate over the BOM Items.
7 i$ B) @' [$ U1 {% |; C5 r3 yfor (i=0; i<count; ++i)
5 u. l/ L/ Z$ {" D5 ]3 c1 |{
9 c) X, X% {5 x W2 v// Get a handle to the relationship Item by index. 9 U+ H1 Y3 n$ A$ Z7 V. b3 q7 Z7 B
Item bom = bomItems.getItemByIndex(i);
" F a( q, d0 [* \// Get a handle to the related Item for this relationship Item.
I" }2 a: G: t& n8 k3 H9 X Q* L Item bomPart = bom.getRelatedItem(); 6 o+ s- x, Z1 G4 F7 F
7 A3 O* v9 ^& t5 E content += "" +
3 T" s' D# f2 ~2 _- ~ "<tr>" +
% Q6 N. A# }& r% y9 o "<td>" + bomPart.getProperty("item_number") + "</td>" + ( i/ z5 H B/ ^9 t6 Z1 L, c3 Y
"<td>" + bomPart.getProperty("description") + "</td>" + # V; m, Z6 n, \
"<td>" + bomPart.getProperty("cost") + "</td>" +
' h: o1 Y) ]; ]: G "<td>" + bom.getProperty("quantity") + "</td>" + 0 B" T( b {5 l/ c- E# b
"</tr>";
5 v) o1 ~" i# B. d# N! g} * \: A$ K- |) K/ W. X* b W5 J( \ }8 J
content += "</table>"; 5 e8 I. A U) {( B
/ R2 a- ?8 {* l) ~" f
return innovator.newResult(content); 3 {3 k* W& l& Y. Q
% {2 D5 a$ c$ ~1 [; x
/ q: ~3 c- V% P
# p5 T" x( g( [, ^ `$ ?
9 W( w% M( L+ }$ i! ^& K. Q3 P$ c" j7 y5 C
) r, o5 S4 D$ P/ I- t
- Z; y7 T4 K- B: z+ O Page 46 * [) r( b$ ]3 Q8 ^/ q- [$ w! Z
* W9 Z" @ Q/ P' e8 A: J. _6 j
Copyright 2007 ) W E" Y& M" K J
Aras Corporation.
- s7 Z- P, ^- |! Y3 b7 \ y$ o r* kAll Rights Reserved.
6 j! F9 K/ Y& }8 OVB.Net 1 M# p% X3 G+ H L* }' X
Dim innovator As Innovator = Me.newInnovator() " P6 F' c, k: |- w
8 t. k; `5 | f2 v* ~3 V' Set up the query Item. 2 {$ W! ^. `; o5 d8 I
Dim qryItem As Item = Me.newItem("Part","get")
6 B% }5 A+ o0 t. r9 _, o+ `qryItem.setAttribute("select","item_number,description,cost") $ B( m; |. H( C& `: [
qryItem.setID(myId)
' d+ B+ K1 p' ]3 [- {" e0 e w: a9 E- t A
' Add the BOM structure. $ P! G& Q3 V1 J/ @
Dim bomItem As Item = Me.newItem("Part BOM","get")
3 j/ u, k# R+ k% gbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
# Y4 ~( p1 I, ~* [/ }; nqryItem.addRelationship(bomItem)
4 O+ S1 m; ^* n4 \4 w
, U6 a4 A) H; A: e' Perform the query.
4 v1 d- `3 v+ p1 G) }3 lDim results As Item = qryItem.apply()
2 H8 E' u# x" z, M# c 9 [6 A" e; b0 g6 d' @8 h; x0 w: a% }# @
' Test for an error. 0 D/ d) B6 j! o1 y5 A8 i
If results.isError() Then ) w8 d, g5 _+ |
Return innovator.newError(results.getErrorDetail()) : a3 Z' R$ E* L5 T- V* N
End If 6 a( V1 E* @$ q: S! _
0 |8 u) ?, m6 o( D* b( ]2 d' Get a handle to the BOM Items. $ O8 B0 [! X- j4 o0 @& ~3 n
Dim bomItems As Item = results.getRelationships() & H+ p: p* x5 H; N# E1 g9 g1 `3 W
Dim count As Integer = bomItems.getItemCount()
' G/ {' {9 D' a% h- M( F$ n2 PDim i As Integer 4 L3 U, c3 g: m1 b ^) t
/ }: C7 R! [$ W$ q! d/ E' Create the results content.
) M! k# N* _1 Y R4 GDim content As String = "<table border='1'>" + _ + w. Q0 q4 h- V
"<tr>" + _ ; x! x& J$ O- H9 y
"<td>Part Number</td>" + _ : [8 F' R6 A' {% F2 F5 w
"<td>Description</td>" + _
7 X1 Y. C: h8 j$ _+ y; C "<td>Cost</td>" + _ ( k. R) o, G+ _: ~1 e
"<td>Quantity</td>" + _
: B8 y4 r0 n- h6 C; V. g* [" g# F "</tr>"
" l' d3 h: l6 A" ?7 K( E6 K
- B2 C# _5 i, E, I' Iterate over the BOM Items - J/ f+ f4 s4 z! Y8 m
For i = 0 To count - 1
6 E3 L, {* i! x( y% Y, g6 z' Get a handle to the relationship Item by index.
8 ?! W X+ t: T Dim bom As Item = bomItems.getItemByIndex(i) % l# t3 Y" _& g9 h* k
7 o; u& f: E$ I" [0 G
' Get a handle to the related Item for this relationship Item.
1 c+ z, j9 b, ^& q1 q) F4 j6 _# | Dim bomPart As Item = bom.getRelatedItem()
; R* ^. _: x' J- ~2 S) i& J, ~
3 s- N3 y' O7 }1 ~+ p0 d content += _ & x( B; l+ I% b2 P
"<tr>" + _ 8 _2 y+ g+ `# q% t3 F5 k
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
/ P( J; r% ?: N3 ]" s "<td>" + bomPart.getProperty("description") + "</td>" + _ * f8 v8 z: X% F# O; b* A
"<td>" + bomPart.getProperty("cost") + "</td>" + _ - @8 O8 ]& M2 t* i
"<td>" + bom.getProperty("quantity") + "</td>" + _ % C3 R* _' w: m1 w
"</tr>" 0 K' I0 Z2 R! H* T, i
Next , q0 Z' W `2 j1 K6 k1 M
content += "</table>" 5 K9 ^2 b' A) C
& O1 v, i3 z* N' i* i C
Return innovator.newResult(content) 1 \5 G6 p) B+ l* O: f( f0 G
2 Y1 C8 I( d/ V/ {/ ? |
|