|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ! j- V/ A, n' N# T0 s
To query for an Item and retrieve its structure you build the query as the structure 6 t v/ I8 m& ]& n. I/ g. I) @% Q
you want returned. Use the IOM methods to add the relationships you want and
) [6 v5 h1 T$ jbuild the structure in the Item. The server will return the structure that follows the
) t: H+ u; z4 @. v* j, j; m4 Z9 xrequest structure. / F% z# B5 X. ~' c6 U& P
This recipe illustrates several related concepts together, which are how to get a set
1 ~- [, U4 f& [5 @/ [of Items from an Item and how to iterate over the set, plus how to get the related
N& k; k# {5 [) W9 i. FItem from the relationship Item.
8 K$ z- i/ z7 @6 ~4 y3 Y2 Y; QJavaScript
( j5 m2 L& b& M& I& g; Tvar innovator = this.newInnovator();
5 @# b; R4 ?8 s) X, @& M+ X# C
3 L$ S- e/ a8 M0 _! ~, \, K// Set up the query Item.
P9 U; t7 T. l3 Cvar qryItem = this.newItem("Part","get"); - v4 C& y2 G# u1 t" W
qryItem.setAttribute("select","item_number,description,cost");
/ n0 ?6 ~6 X4 l# HqryItem.setID(myId); + }( G: z: M5 A c$ Z
1 N' ]6 E; m" ]+ e7 f# b// Add the BOM structure. 9 n1 `) G1 @6 Z4 u) d
var bomItem = this.newItem("Part BOM","get"); ( J6 p) |9 p, ^0 b( {
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
- b9 j* {" P9 a7 t, H5 EqryItem.addRelationship(bomItem); 7 f. C; h! e; F" E! L1 y& R/ S
/ A8 f# q Y) v5 k; s" L# d$ q
// Perform the query.
* ~7 |1 F9 \) i7 S( D) svar results = qryItem.apply();
- ]; b |# M. l( c# D - k' V4 S- O- k0 B1 C) M) j9 [
// Test for an error.
0 L9 ~( W% l, \7 N3 rif (results.isError()) { 8 \) ]/ I# @ }! e& ?2 z' G0 a
top.aras.AlertError("Item not found: " + results.getErrorDetail()); # T: [) o, c( u0 |4 d# ~3 E
return; : q0 N" k6 J) |0 S/ o
} 2 V5 v6 H3 F: n/ J* N7 g
% u- ^0 W' Q2 S
// Get a handle to the BOM Items.
z3 q, W% B5 M. c( O7 i7 X- Gvar bomItems = results.getRelationships(); ( s* Z, _3 C" X* K" c6 ~3 K- x
var count = bomItems.getItemCount();
% m' U# z; N) x) ? s7 ^ * e/ h" }4 O( Y# \! n5 D& t
// Create the results content. . h# a7 ~% B1 m g7 _/ ?+ c
var content = "<table border='1'>" + 4 n* a/ J) o) l4 M( h" {+ t
"<tr>" +
& Z+ G' x$ E" E& R "<td>Part Number</td>" +
. O. w; F& U' Z "<td>Description</td>" + ! a) d, r' [# V3 V2 U) ~8 N6 R
"<td>Cost</td>" + ' o" |8 w, I: T" D4 s
"<td>Quantity</td>" +
( H7 R/ u, `3 B+ Q, Q( d7 M1 l "</tr>";
; Q! E! H2 [! C
% s3 i6 `6 L. m$ o) E; o* m3 \* y// Iterate over the BOM Items.
! g2 B4 N1 M0 ~- A5 Tfor (var i=0; i<count; ++i) / k0 S, Y0 q' u2 u
{
) N% ^4 Z7 J8 y1 y// Get a handle to the relationship Item by index. / Y8 H- W/ x* y- W- ]
var bom = bomItems.getItemByIndex(i); 4 i: u# t' Q& n' n. B0 ]
// Get a handle to the related Item for this relationship Item. 8 u# \! i, W$ ^! ^8 }% p
var bomPart = bom.getRelatedItem();
1 z; w6 K' i" Q& H
$ X" b' b: v8 L" E content += "<tr>" +
/ G8 i7 o# _/ A; j8 u1 `& k, Z "<td>" + bomPart.getProperty("item_number") + "</td>" +
7 A& R4 T! P1 v "<td>" + bomPart.getProperty("description") + "</td>" +
. X# V- l/ H" b; ~' I* W {8 N "<td>" + bomPart.getProperty("cost") + "</td>" +
0 k$ z2 k% z( r, D* c& A$ O6 ^ "<td>" + bom.getProperty("quantity") + "</td>" + 8 ~4 }2 d2 S6 E2 @4 ~: `9 L) v
"</tr>";
* _+ S {* h3 g2 q' \$ G- v} 9 F3 h% P7 z8 g8 W
return content + "</table>";
. n! h' ]+ y4 X/ i1 @
, v/ s) U4 I. N) e
3 t6 A$ D& Y ^
- Y6 ~3 q `' V4 y( g! T5 b) { @' q) [4 W- A" h) X
C# ) \; k, L7 w/ @
Innovator innovator = this.newInnovator();
, T/ e; P a1 Q$ u2 o4 b ( g# ]7 m. _2 H5 \, ^; J1 C
// Set up the query Item.
P1 y: O/ L5 c* Y% C. xItem qryItem = this.newItem("Part","get");
* i+ T9 P" B$ m7 T! ]9 s* B& R! PqryItem.setAttribute("select","item_number,description,cost"); . {( [( p; G! t/ P) W- [* H
qryItem.setID(myId);
3 Q5 x! H0 C& I, N 9 L" A' z" |0 `' d
// Add the BOM structure. 6 `2 f7 u7 i: Q6 g) M2 q# ]/ J8 w( q9 L
Item bomItem = this.newItem("Part BOM","get"); 1 }# H k5 y; j+ @
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
) n5 J+ U+ m+ {: Z1 i. LqryItem.addRelationship(bomItem); * g6 B) G0 `( W ]
4 X. L. \1 w2 Z. Q9 t: ]
// Perform the query.
3 z6 j5 u |" R! y" I" X. h+ ]Item results = qryItem.apply();
$ o% i" x0 J' c4 K f: P+ D' F. o4 @
, ^( u Z K! j$ o" y6 g// Test for an error.
3 A8 m+ d% [& | Iif (results.isError()) { & s6 B. _, c) j7 u" e
return innovator.newError("Item not found: " + results.getErrorDetail()); " p9 |0 T: E# u- l
}
; A) g1 F$ q+ D/ O/ I( W% ` $ Z! {& n8 j( x0 N+ S
// Get a handle to the BOM Items.
; }3 x) f& }0 R/ \# EItem bomItems = results.getRelationships(); 3 L5 @) m+ k4 q- w% w# }) ?4 {5 w
int count = bomItems.getItemCount(); " x1 `3 [2 n5 f0 J7 m
int i;
/ ?! K1 q1 e% L1 u# o1 `
& @7 N' H4 t& S// Create the results content. - _& j7 r' i- [( p
string content = "<table border='1'>" + 1 [& p8 F3 y0 S+ k$ a3 D3 r& h
"<tr>" +
$ |# M. A9 f7 j7 R$ e& \ "<td>Part Number</td>" + " p6 X5 a/ R* v
"<td>Description</td>" +
5 C+ d( m2 B8 N "<td>Cost</td>" +
7 w: \% L9 R( g4 A) E; ?4 y "<td>Quantity</td>" +
3 _& j0 |5 [ z7 o- y" C$ z. @ "</tr>";
8 s7 M9 i9 ~' n% k % n: Q7 U0 |& q" Y% `6 t& F0 q
// Iterate over the BOM Items. : G+ o: D6 ~' c
for (i=0; i<count; ++i)
# k0 i. t1 x+ Q/ l9 b{
5 `% ]- Y U. [8 h$ t// Get a handle to the relationship Item by index. Q& ]* M+ G" ]& I9 L+ G
Item bom = bomItems.getItemByIndex(i);
) O/ F# g7 M+ [9 K/ x. ]& g// Get a handle to the related Item for this relationship Item. : Z& l; ~$ O3 ]0 E3 A
Item bomPart = bom.getRelatedItem();
' u- b" y0 M) E f1 C4 m* S
+ n9 ~: {% s- J" H/ A" |! |9 `9 S content += "" +
( e! n; k" k/ O+ _ "<tr>" +
5 ^+ d5 B4 D/ Z3 z0 U7 E N "<td>" + bomPart.getProperty("item_number") + "</td>" + 1 D/ x8 L$ V& T: p i( ?
"<td>" + bomPart.getProperty("description") + "</td>" + 1 }; J8 J% ^* K
"<td>" + bomPart.getProperty("cost") + "</td>" + * H5 r% ~. G7 h
"<td>" + bom.getProperty("quantity") + "</td>" + 4 v/ H4 o$ l/ [3 o9 m
"</tr>"; : m7 e& l3 s I# \
} ) A; S: A1 g2 D* x
content += "</table>"; ( `& z, G( h* b4 |$ C
4 O$ [ N W- ? C. w$ u% X+ X q" Q
return innovator.newResult(content);
% O5 p# g4 V4 @5 p$ q0 W) H7 f' ^! Y E
( W4 D# j8 p9 h* M; D: I0 g9 D' e+ `4 \" [
! M o$ a$ G5 p
) D- ^9 d5 u7 c6 a$ _
/ A# W) |5 t) g* n : B# Z& u t* k- h; I
Page 46 2 Y+ p" j- T; E5 N+ W3 F5 f1 K3 E
& ]+ G1 I4 D$ `9 m1 m0 k$ jCopyright 2007 * x& n j- ?0 }( X, V' ]0 |
Aras Corporation. 4 u$ {/ A7 \4 C3 I
All Rights Reserved.
8 Q7 {5 g8 p) q$ q- F) S. HVB.Net / B* E( ^7 y: u0 {+ f/ @3 o6 m
Dim innovator As Innovator = Me.newInnovator() % I; l3 K% W( t
, Q8 u, n- D, Z& R
' Set up the query Item. + C7 k! U6 O" ?, e U
Dim qryItem As Item = Me.newItem("Part","get")
; _8 G: K! l) S& vqryItem.setAttribute("select","item_number,description,cost") & y t0 b3 N" ]9 K0 Y& c. v2 n
qryItem.setID(myId) " x' k, I% x- _" F
$ w1 S0 o3 C2 B, V' b) `& e' Add the BOM structure.
% p% j! r# }1 {; jDim bomItem As Item = Me.newItem("Part BOM","get") + v4 U! P& U* l* L
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 6 a, v' q: g# b/ ]: M1 \
qryItem.addRelationship(bomItem)
+ P' L9 c c& J& }$ D 4 ?0 Z$ {; K' [: h2 l6 Y
' Perform the query. 7 T; G! C+ ]: E- Y6 A
Dim results As Item = qryItem.apply() 7 y! k' N+ ]# E
) m( r) Z% y, m( w! ?' Test for an error.
9 s+ R! {1 H, O; e) uIf results.isError() Then
. v8 j: x/ h5 \% [- @! U Return innovator.newError(results.getErrorDetail())
- J" ^1 I8 c6 XEnd If 7 D$ h' [: i# {2 e4 T: E
5 r# i& r% L2 r1 P' Get a handle to the BOM Items.
" Q" G# s' ~! @ d# o: x% B+ ]# V8 jDim bomItems As Item = results.getRelationships() ; I+ b# [1 O R
Dim count As Integer = bomItems.getItemCount()
6 b4 {0 s! a0 l- C6 o6 l' fDim i As Integer
0 G. _ \, B o" @* Y2 w
! }0 N. a4 N/ K3 T5 q' G8 Q' Create the results content. + ~' b8 n, Z1 t0 ] v
Dim content As String = "<table border='1'>" + _ 2 G8 {5 T. k% N& t; r
"<tr>" + _ " Z6 L# x9 t9 G0 h2 n
"<td>Part Number</td>" + _ 9 d/ X+ f! }2 ^4 ^! m# g
"<td>Description</td>" + _
: f7 [8 G% J5 v# w4 D: x4 l "<td>Cost</td>" + _
0 z( z' \) d, X "<td>Quantity</td>" + _ 0 S. G/ r. t+ ~: f6 C& w
"</tr>"
3 a/ [$ a7 w! A) ]3 ~# d
7 M& {1 E* M; {1 r# H4 w# V' Iterate over the BOM Items
, f# L+ j' ]2 i+ K& Y+ ? J+ zFor i = 0 To count - 1 5 ^( P! y2 K. K8 z
' Get a handle to the relationship Item by index.
- }* B- l' q7 ?# \; _. A& f Dim bom As Item = bomItems.getItemByIndex(i) 7 _0 a$ o6 ~; l
5 |3 Z D, ]) ]$ z4 ^0 R0 b
' Get a handle to the related Item for this relationship Item. + j, a* v: V; a7 [
Dim bomPart As Item = bom.getRelatedItem()
/ Z6 D: n$ V3 M( V% a" i2 y& v Z ; F6 v, ^: q4 l3 o9 U+ G) w' {
content += _ f, l+ h: J" ?
"<tr>" + _ - R: f; }, [: l! G; p3 c7 i; G
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 d& z6 Y, m0 _& i8 Q# K' p' y
"<td>" + bomPart.getProperty("description") + "</td>" + _ & g# z) v F. ]: |( w0 |
"<td>" + bomPart.getProperty("cost") + "</td>" + _
, z) x1 {! P! b$ D, y( D# I3 @( O4 E8 K "<td>" + bom.getProperty("quantity") + "</td>" + _
: }2 D5 @ y2 r# r" p% G "</tr>"
3 ]. J! ?6 h" i$ d8 g8 p6 q" z8 ^Next
; _, |4 ]' C$ G. B: M9 a3 jcontent += "</table>" 4 ^3 j. ], ?2 b3 d: q$ o( z( n
1 s& s' x- M8 `* j+ X
Return innovator.newResult(content)
3 {" H- \1 h4 b% _2 H1 |, Q% k$ X$ j# n$ B/ {0 k, W
|
|