|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 5 ]) c# a- Q1 d/ ^* S
To query for an Item and retrieve its structure you build the query as the structure
1 A$ b V) a, Y# Zyou want returned. Use the IOM methods to add the relationships you want and
. m# G8 j1 d* A* I9 d0 F+ zbuild the structure in the Item. The server will return the structure that follows the # U' t `# Q+ d& r3 \. h3 _
request structure. 9 V: ~. ? N: _9 h9 y3 E
This recipe illustrates several related concepts together, which are how to get a set % W; A& s5 D" \+ O2 `2 F, w+ \3 ~
of Items from an Item and how to iterate over the set, plus how to get the related 6 }- V& p5 M0 w# y3 ~$ v3 h- d
Item from the relationship Item.
) r7 K3 p$ _1 l0 K; lJavaScript
5 W4 d7 m, s& j7 h1 ^var innovator = this.newInnovator();
1 }/ L# d3 f* s( Z. c, k8 g
1 l8 ]! e7 j( O' X$ u* l7 s// Set up the query Item. , E# [( [8 _# n# } D- z( R
var qryItem = this.newItem("Part","get");
2 l+ R3 w" O: i; h* D5 Q* `qryItem.setAttribute("select","item_number,description,cost"); . [0 H5 }( U4 O* `' C
qryItem.setID(myId);
- K6 w9 S; t% ~2 Q0 J$ |, B6 _
: j y8 a8 K( ]) g// Add the BOM structure. ( r! r/ J6 a- i1 \' q1 h
var bomItem = this.newItem("Part BOM","get");
. H" F: G9 D9 Q5 _* D/ [bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ! ]# z/ ~6 \1 K# g6 T
qryItem.addRelationship(bomItem); 5 @; Y8 v" ]* [6 U" N1 H4 S
. p8 B. C" z8 D! Z" @% y n// Perform the query. + v* \9 B' ]7 a8 x$ E# T* E3 D7 r
var results = qryItem.apply(); 5 i% K. U1 S9 c' B/ o
$ f& a: T: t- j A. J0 k9 `
// Test for an error. ' D- ]. @* U0 j6 Y' p4 g6 i
if (results.isError()) {
+ S) {6 z8 @/ E H2 c) K top.aras.AlertError("Item not found: " + results.getErrorDetail()); ( z: S, `8 S/ o! g
return; # T% p: @4 @" n/ v6 H* R1 o% @
} + K6 |. ?% i& E
, N' a( P& W2 F+ }2 q! ]1 o
// Get a handle to the BOM Items.
0 u2 `( n* M8 L& W6 svar bomItems = results.getRelationships();
- O0 t3 q6 I3 H6 _* U, b0 b1 k7 Avar count = bomItems.getItemCount(); ' W! \/ I7 w# x$ G, m% L; W; S
! G' C5 S ]: n. ?- y// Create the results content. + H$ }' A. T; [2 b) L
var content = "<table border='1'>" +
+ U* [2 y4 N: O0 d "<tr>" +
$ U( E+ y7 t/ L. \4 T7 z9 a "<td>Part Number</td>" + 1 i6 w' k6 l5 t, j
"<td>Description</td>" + / S0 f1 E) E6 N! ]) Q
"<td>Cost</td>" + 1 P# [) u: U; y1 `
"<td>Quantity</td>" + % X; J1 z+ X3 k) i) d
"</tr>";
. m' `: R7 n) S+ }0 }- C
, I. r# V1 C$ q" p// Iterate over the BOM Items. 0 w/ l4 }* A! t! E5 K9 ]
for (var i=0; i<count; ++i) ' E7 d# N! X0 Q2 ]+ w! a
{ $ p) y" [3 r m9 i
// Get a handle to the relationship Item by index. 5 P3 T8 k# Y+ ^) O" {7 E
var bom = bomItems.getItemByIndex(i);
% X, W5 z, |9 T8 n, T// Get a handle to the related Item for this relationship Item.
* j: p& [) Y h6 ?3 B0 }2 A var bomPart = bom.getRelatedItem(); ! |0 Q4 s$ V; o) i7 p8 a
1 D0 S: X9 H5 ~2 B content += "<tr>" +
6 [: t* Y3 E5 l "<td>" + bomPart.getProperty("item_number") + "</td>" + 7 u% r9 F8 C! O* R2 e
"<td>" + bomPart.getProperty("description") + "</td>" + % X' e6 f+ v& \0 [: B5 B
"<td>" + bomPart.getProperty("cost") + "</td>" +
# q; }: n& c7 A, ?" {3 W( g "<td>" + bom.getProperty("quantity") + "</td>" + . g' |2 x6 Y: v' |8 ~% S
"</tr>";
. v+ {. Y0 u7 o2 l8 \} 0 s7 L) X- _# @* c; y
return content + "</table>";
+ {! B% X- y# f: d! X) `& N
! M% n0 }) E4 o: ]' ~8 O. w
7 J7 b0 i1 K; |. b4 E+ L3 C- m$ z, X% X8 v4 D+ Z1 \3 |+ ?
! \6 n: q( U. jC# 3 O# z, V/ _- v4 B( D9 P
Innovator innovator = this.newInnovator();
0 q) J3 W4 Y: D/ h2 j/ {
. V! _0 s! ?4 j// Set up the query Item.
9 i8 Z; J9 I' I6 v: ?9 _Item qryItem = this.newItem("Part","get"); 9 [! p$ h4 E7 v5 U( B- p7 Z
qryItem.setAttribute("select","item_number,description,cost"); 5 T Z$ ^& L2 z4 {0 b% ?+ B
qryItem.setID(myId);
! f0 H( e) K8 T% ]7 v# ~- j0 a
% d6 \6 H b# ?; b3 U" J// Add the BOM structure.
q7 I) y% d& k, G2 w( }Item bomItem = this.newItem("Part BOM","get");
1 q4 H/ G) Q* z. U$ ubomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
4 [* O& ]' H+ m9 G7 k( @( v2 SqryItem.addRelationship(bomItem); 7 Y; C# M: w. Y
+ y& i* K; t( E- N// Perform the query. / B( g5 h5 _* _- }( r
Item results = qryItem.apply(); 6 i! x4 D; O% R- k, u, r
2 X2 E+ K6 ]5 u// Test for an error. ' {3 h) p9 w. G1 ]1 i4 f2 @9 W5 L
if (results.isError()) { : a) R! R! y9 ~( M1 ]. @. u0 w
return innovator.newError("Item not found: " + results.getErrorDetail()); , Y$ b' o/ Z/ p0 d) u9 E$ j% q
} 8 d: k9 J, s' O" D! j4 m9 i/ Z4 I
3 |1 D: {( Q& Q// Get a handle to the BOM Items.
6 b! h% Q7 S$ a( wItem bomItems = results.getRelationships();
- F g& ]. o6 v( ?# V+ X7 jint count = bomItems.getItemCount(); - y7 I' q* u- B0 [' A
int i; / T& P. w% N% L( T2 H
1 C0 F- \9 Y/ t8 x! K// Create the results content.
; P; \: l1 F9 H+ o* wstring content = "<table border='1'>" + " o: m7 s. ]- `7 ~* k/ i; b' r
"<tr>" +
$ F8 M/ x( [3 `6 l8 ?6 u "<td>Part Number</td>" + ( \# n. \( c `6 P/ z+ S8 t
"<td>Description</td>" + $ W; J% y8 U, o+ S% I
"<td>Cost</td>" + ! ?1 Z& o2 m, r6 L/ G* u0 Z) A' g
"<td>Quantity</td>" + ; L; ^* G& c3 R# U5 S" a
"</tr>"; : P1 J. R- B/ N' M2 U. q5 ]$ v M4 N4 ~
' Z8 R4 t" g3 l- E4 r$ e// Iterate over the BOM Items. 8 \# q# T5 A( Z+ L
for (i=0; i<count; ++i) ! E5 d" `8 a- n7 V" v
{ ( W+ k) |" Q& H" k3 e: F# z
// Get a handle to the relationship Item by index. - ?. `+ ~, \* o) w/ b8 h4 V* v
Item bom = bomItems.getItemByIndex(i); 8 J7 Y$ A- ?) B9 m* A
// Get a handle to the related Item for this relationship Item.
I& P# [2 E/ ~5 G+ [8 ` Item bomPart = bom.getRelatedItem();
1 D, n# Z: J. O) c$ U. \$ M& o. U
* l0 b- T: c" Q; `3 G; ?+ p% Z content += "" + - m5 R7 J) P, u; r3 x
"<tr>" +
( N2 H: |% Y: p6 ^4 x: { "<td>" + bomPart.getProperty("item_number") + "</td>" + - n( D( h a3 a, C) Y
"<td>" + bomPart.getProperty("description") + "</td>" + : C: B1 t6 o+ k+ u/ O% Y
"<td>" + bomPart.getProperty("cost") + "</td>" + * Z; `% [% \- L- ?) ]
"<td>" + bom.getProperty("quantity") + "</td>" +
2 W$ i- l( Y+ m/ c4 b1 L( V "</tr>"; / x* Y0 r! X( }, d# _4 ~0 J" T
}
, n; O+ g9 j6 Q- `! u. c2 ]$ Hcontent += "</table>"; " f- @0 c( Y9 `1 J/ _$ m
6 Q- n1 P! r6 a Y
return innovator.newResult(content);
- ?5 ^. f$ G: j! r( P7 U
+ g( i/ Y8 v' v
. R* h2 `$ M" P; b* |& I. j
8 X T J | d( X; O# t+ T; P6 q, A: C& b( Z. r3 j+ V4 D4 P
?' F& J& F+ X$ O( N e
' t2 s1 Q$ Q; W% z
& Y/ e6 D- F% ]5 l D% s3 E Page 46 * S* F) i! s% O6 B: {
* `/ Z; {/ H+ j: V t0 N4 S
Copyright 2007 ! |$ _2 R7 e0 P2 c f
Aras Corporation.
" H7 T0 O8 s e9 ^) v* q* w8 @, YAll Rights Reserved.
/ b8 X( p: I) }3 q. I! RVB.Net ' }5 _- i* `+ M
Dim innovator As Innovator = Me.newInnovator()
# x. V5 G$ d) p+ Z6 E6 n
2 q" o9 w+ H7 b# H B& ]& c1 ]8 l' Set up the query Item.
4 @$ l, I& T# L4 d0 E$ `7 m, MDim qryItem As Item = Me.newItem("Part","get")
. W0 x' w% p7 D7 D jqryItem.setAttribute("select","item_number,description,cost")
* A$ E' e% l/ r: MqryItem.setID(myId)
* i5 x s/ W- W / U, m3 Z5 w: Y7 U' R" s* w
' Add the BOM structure. % }- R5 R, [- T4 g2 t& B7 h) }
Dim bomItem As Item = Me.newItem("Part BOM","get")
) b& g3 G# G+ W* ~7 r" i1 ~5 f% o5 CbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 9 T/ B3 M- k, v" {. \; d" K
qryItem.addRelationship(bomItem) 2 F. n( |- g5 o2 c& { [
2 T# {- ]% A# `1 h9 |; G) z! t
' Perform the query.
4 U% x. [+ D. E: }/ e: D, CDim results As Item = qryItem.apply() + |1 h1 O9 c. q, ^' q
8 M& M3 N6 {5 K, R. P8 r' ~1 G' Test for an error.
5 q2 I7 J, ~. A0 XIf results.isError() Then \6 L1 A* D1 S5 i
Return innovator.newError(results.getErrorDetail()) . A6 p# t2 A, A/ D- z7 X- x5 s. X5 P q
End If
& C+ H0 r! i- z% d
$ b7 n) j- a( R E- X$ H' Get a handle to the BOM Items.
' v5 ^3 y$ q" H( P3 M; iDim bomItems As Item = results.getRelationships()
" G" @+ e# z! s0 m9 y6 s9 J) eDim count As Integer = bomItems.getItemCount()
" M& |6 x" g/ O; X$ ZDim i As Integer
0 b! }$ H9 e' K7 ?7 J1 \
4 |. O) Q! }/ P- D G' Create the results content.
" o* Z7 ] ^% z4 \. zDim content As String = "<table border='1'>" + _ 9 b5 a3 Z7 x# U* q! c9 X6 J7 i u" [4 O
"<tr>" + _
& c& Y- k! K2 G" I; ^, w f "<td>Part Number</td>" + _ 5 _% M+ o4 ~8 G0 y# {
"<td>Description</td>" + _ , u' B8 c1 [2 i# C. V- D
"<td>Cost</td>" + _
7 ?* a4 u- Y, E! I4 n "<td>Quantity</td>" + _
d1 t- r2 N8 r% S8 X q+ J6 P c "</tr>" ( z! ?9 z' j0 Y6 Z8 t: C. @4 K
' i* z* _$ c; t# p- R' O7 j
' Iterate over the BOM Items
. x) \) m5 P3 Q5 m ZFor i = 0 To count - 1 ; h$ P2 D8 Y6 d2 {' a
' Get a handle to the relationship Item by index.
1 @0 ~& l( J1 x. @2 m# q) \% \* Q. { Dim bom As Item = bomItems.getItemByIndex(i) L1 F0 }( q3 t/ J
% E# S. d. F" [0 u$ _# T
' Get a handle to the related Item for this relationship Item.
3 l6 P3 m0 r5 n: _. M+ x$ o& M& { Dim bomPart As Item = bom.getRelatedItem()
5 f3 A1 E5 C U0 z/ @' W2 |0 |
9 b/ b1 E* B7 o8 y1 R+ B) K content += _ 9 n* G# w* L& W6 h* l5 V7 ]: i O
"<tr>" + _ . r6 J" V. i; ^" ~$ g
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
, V7 U9 z# F: J5 T8 M1 S "<td>" + bomPart.getProperty("description") + "</td>" + _ v% b; U9 [* b4 E. T+ f0 z
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ! ^* A+ H0 M z
"<td>" + bom.getProperty("quantity") + "</td>" + _
' Y) {4 ^7 X) U* p5 {$ }3 ` "</tr>" - l5 i% h+ b( P
Next 6 B7 d8 D3 p. Z$ o) l
content += "</table>" / A2 I( d$ d& e1 `
2 ]$ q5 B( \* Y% C4 YReturn innovator.newResult(content)
4 a! q3 x- m, L( \/ w9 s' O, A n/ ~% U$ W3 }
|
|