|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 6 R2 ^; s" U9 R4 s( _( |
To query for an Item and retrieve its structure you build the query as the structure
) e' Y4 |, L$ M& \! F9 S# N/ @you want returned. Use the IOM methods to add the relationships you want and + ]) ~2 u/ z: {
build the structure in the Item. The server will return the structure that follows the
5 N E& P$ K7 ?1 irequest structure.
# ~6 S% _4 S- t2 rThis recipe illustrates several related concepts together, which are how to get a set
% F: ]; p% _+ h" ]2 Xof Items from an Item and how to iterate over the set, plus how to get the related ; z" w. c) P8 W; d% n5 P
Item from the relationship Item.
+ J& v2 T. X6 z5 U! v( y) UJavaScript " C( k4 }& d! ~( T
var innovator = this.newInnovator(); 1 ~8 x. {6 M, F* Y: O" \, W0 V- Z% }
, g6 w" z& H: c4 d+ ~/ Z// Set up the query Item. 5 {; C& E' G# i! J5 W# f
var qryItem = this.newItem("Part","get"); 5 m- l0 h& y. l- ^& Z/ k
qryItem.setAttribute("select","item_number,description,cost"); " V9 v5 E# V$ v( Z6 V' A
qryItem.setID(myId);
% d$ v) O7 |: R$ E- X* b
8 [! A% L) r6 j1 V// Add the BOM structure.
* N5 x9 _$ w9 r* ]" M3 Dvar bomItem = this.newItem("Part BOM","get"); 3 y K9 O! x( L1 D: l$ B
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); / Z/ G" e( u4 C" X/ b9 A
qryItem.addRelationship(bomItem);
: z; D/ b9 t) \
& \! L# \: u: Y- v: H0 z) _// Perform the query. - P3 ~6 ?3 E' `" U( ]8 k
var results = qryItem.apply(); ( w3 S% b4 ?# P$ {( X" G \
/ f3 ^8 e7 t. w' t; P! O
// Test for an error. $ A# U: B9 }5 T4 s
if (results.isError()) {
8 V/ }6 s- L5 Y. | n top.aras.AlertError("Item not found: " + results.getErrorDetail());
2 C* n; E; A0 ?# h: _; R; Q return;
& i4 S2 N& H9 j}
& C! k! }+ Q3 Y( U1 }
5 ~* C( C* k. @4 C! {( c// Get a handle to the BOM Items.
/ m- j6 Y3 F5 T0 W2 Q' Yvar bomItems = results.getRelationships();
% z2 w4 K/ W5 ]8 ]$ {, evar count = bomItems.getItemCount(); ) B9 X ?/ m, A0 O
, D+ ]6 r8 S2 ^1 |
// Create the results content.
- {, X& B, L5 `' C$ fvar content = "<table border='1'>" + ' Q. @$ U; \' i
"<tr>" +
/ ?( k9 f4 O2 G2 C2 U& U "<td>Part Number</td>" + 8 m* m3 r4 O9 w: a' v, r5 u
"<td>Description</td>" + 4 p2 P1 P' i' y' Q x0 X$ y+ k
"<td>Cost</td>" +
* z9 J0 W* w t! `! ? "<td>Quantity</td>" + + j4 l9 q0 e1 i) b$ @" S5 F; B
"</tr>";
$ \( Q2 X; l m1 A 0 ]8 |/ M9 Y% J0 P0 b: `7 O
// Iterate over the BOM Items.
' ]( y* ?3 l2 O8 B$ ?/ Ifor (var i=0; i<count; ++i)
, }9 F Y5 ]; [! u; t{ ' a3 h: Y' B9 _6 S9 |( t
// Get a handle to the relationship Item by index.
4 L# M1 W/ i- C& n var bom = bomItems.getItemByIndex(i); ! v4 ~& k: t1 K) v+ t7 U
// Get a handle to the related Item for this relationship Item. 5 O) p: y9 |! @0 U; v
var bomPart = bom.getRelatedItem(); ; G! n0 f; D0 U* M
/ N6 x7 V7 |5 [ K+ K8 E
content += "<tr>" +
8 J; z7 R& }. B( ^1 ^' k "<td>" + bomPart.getProperty("item_number") + "</td>" + R1 }% ?9 m- |9 O" a' u6 ~
"<td>" + bomPart.getProperty("description") + "</td>" + 6 Q; \+ t* K- P; Q6 g; G% _
"<td>" + bomPart.getProperty("cost") + "</td>" +
' y6 }# f G6 R "<td>" + bom.getProperty("quantity") + "</td>" + # ~/ v8 u7 @2 q3 o, T3 y4 v
"</tr>";
' D7 w1 Q' Y5 r( r0 e}
1 ~1 ?6 d2 T* R, v1 i+ Treturn content + "</table>";% x7 k& k9 q( G4 e: M; B
. @1 g$ F8 P0 t; } J" S
8 K0 l1 ^$ _7 [
+ ^- u0 j" y5 c9 f x6 Y0 h5 n \' D
C#
" j, U% M4 P8 `: ]% A/ ZInnovator innovator = this.newInnovator();
6 V( d3 V/ r4 Y" I5 _' L+ p0 U : M L) k9 {4 E- O2 I' h
// Set up the query Item. - R& P& `. A7 E/ U9 v
Item qryItem = this.newItem("Part","get"); 9 H" V" d, g" g! F6 y. Z* P
qryItem.setAttribute("select","item_number,description,cost");
) D! W" S* }& v, u; m/ uqryItem.setID(myId); ; s b k0 x, I% F( e
4 a( m% q" C0 D6 f) o0 _
// Add the BOM structure.
" \& E: G4 w) j5 a$ N, _* V2 t% DItem bomItem = this.newItem("Part BOM","get"); & [: o/ G7 H( v) P" {7 Y" u' O' _
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 6 _, ?9 a% A7 K" z ^/ o) T
qryItem.addRelationship(bomItem); 6 A2 ]! h, j3 v# w! x
8 }) O* V9 M1 F. j1 ]6 L// Perform the query. 4 ], B5 l5 e, ?& C" V: ^
Item results = qryItem.apply();
6 F! r; g- _1 N" B0 {( `1 m; D4 X , P! p9 H* R# X( q) I( t% M. c
// Test for an error.
- b1 O/ T2 { I3 v# t- Rif (results.isError()) { ! c$ y7 `& V; y2 g4 l+ v
return innovator.newError("Item not found: " + results.getErrorDetail()); # [; |3 ?4 G( j& n# K7 m
} 6 V* p9 b' @4 g- b! W$ S* j4 N
# \# f: X1 j4 z" k/ G+ K
// Get a handle to the BOM Items.
* g, a9 v; c2 c; }Item bomItems = results.getRelationships();
6 Z' z9 c+ @+ l5 |/ z, F! g; lint count = bomItems.getItemCount(); 2 O4 C1 B# Z# T) q1 t- Y2 R( L" O
int i; : T8 V# e; |" y: @
. K) l! e# L" s9 M' x: U9 V
// Create the results content. . I' J5 g; C7 G
string content = "<table border='1'>" +
9 e$ D+ d' ~! M" O+ h4 o1 w "<tr>" +
* v r: E5 y6 _/ T "<td>Part Number</td>" + # w9 \4 m# e4 D* k5 s: [2 v% T
"<td>Description</td>" +
7 E: @- |3 c# h9 \2 Z( a "<td>Cost</td>" +
- Q! i. E$ i2 F& U8 N "<td>Quantity</td>" +
+ G0 V( f. B1 h. X# C( O4 o "</tr>"; & H: n3 Y. {8 Y3 O
- j- o% J" V" w( i/ u// Iterate over the BOM Items. 5 |/ w1 D; I& j D
for (i=0; i<count; ++i) * O4 y- [) R3 C
{
0 S. m! ]9 g. j) s' T8 I( ]7 C// Get a handle to the relationship Item by index. 9 q& Q, R9 Q% Y
Item bom = bomItems.getItemByIndex(i);
4 b6 b$ a7 D- `9 E- B; y, @// Get a handle to the related Item for this relationship Item. - A* T6 o+ B& w9 Z
Item bomPart = bom.getRelatedItem();
2 F) F" Q0 y5 f
9 t5 u& u0 G" y( P content += "" +
5 H$ g# d+ w* A C2 p# b. r "<tr>" +
* x: N3 ~9 z8 R4 H "<td>" + bomPart.getProperty("item_number") + "</td>" +
R2 F& X# ?0 c; w, @, Y "<td>" + bomPart.getProperty("description") + "</td>" +
}% _& m% r/ e+ b2 Q% y "<td>" + bomPart.getProperty("cost") + "</td>" + " s: P9 J9 u7 w3 X$ z. \% \
"<td>" + bom.getProperty("quantity") + "</td>" + ! _ D2 l% u. k6 u1 a( [
"</tr>"; # Y0 g$ B A) a/ d- G0 a
} / P' j! V7 a/ E" P
content += "</table>";
- u( ]2 R" J1 g6 z7 y" P4 Y- r ! X; Y9 y/ a. `5 w5 D# ?6 t
return innovator.newResult(content);
4 H; ?0 W- n3 B) D: M. A+ G4 \2 |+ O) V5 g0 R+ k& j( W' X
$ m9 S5 T7 h R2 K
4 r! i2 k, F( G. [$ N8 T# |. n( G9 r& n; Y* a8 v
# J0 @5 R# Z+ @% l# X
' q8 q" d8 c' i9 e4 m
, Z' H) `$ L4 l. \' s" C Page 46
" R. G* K4 G3 u8 U/ N
# a$ r4 }' a6 G' ?) zCopyright 2007 % }& i* I( k/ F8 Y; k+ o) s6 a% B, Z3 w
Aras Corporation. : J5 ?! @/ ~; @7 R7 P
All Rights Reserved. ' R; a U" d- K4 D) K
VB.Net ; V. W5 v( _9 h7 B' T9 D
Dim innovator As Innovator = Me.newInnovator() X( `3 m/ b: H/ M! p! I
# ?! a) v. v% g
' Set up the query Item. * ^* M; c( \& X: w' X
Dim qryItem As Item = Me.newItem("Part","get")
. U' f/ E% q- U, ^. W4 d$ i. VqryItem.setAttribute("select","item_number,description,cost")
! F+ E6 ]& J7 X; {# UqryItem.setID(myId) ! X. T; ?* o: ]8 P8 l5 M+ F9 y& Y
* Q2 _3 h. {3 a; G& I
' Add the BOM structure. 0 \, N1 m J, l4 U8 o" g
Dim bomItem As Item = Me.newItem("Part BOM","get") : U! y/ S ~" V' t2 n; G
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
) ] J* C% `4 Q4 M) dqryItem.addRelationship(bomItem)
2 D, l; S/ Y5 M" z
, X* Z' v+ o' ^6 d! ?" M' Perform the query.
1 @3 D3 X1 `( J% [, ^* rDim results As Item = qryItem.apply() % P1 d. Z# g/ C) t' f5 H+ T/ c
/ B7 v0 k* R: L% `1 c8 o
' Test for an error.
8 x- k+ O% {) D6 x: S: d: BIf results.isError() Then - u/ w G8 j: m' a& V$ E& w
Return innovator.newError(results.getErrorDetail()) % m4 ~4 Y9 D9 P# {
End If
) x1 {9 Y% n/ P' k4 A; u
. q F9 l! l) T2 f' Get a handle to the BOM Items.
! t9 I$ h) G8 D6 Q6 d7 bDim bomItems As Item = results.getRelationships() ) q/ n3 }$ z& X( H$ j9 B. P
Dim count As Integer = bomItems.getItemCount()
( R m0 n! ~1 V& E5 O1 i7 [Dim i As Integer
3 b; g( b+ J# M$ o3 ?9 \6 G( q
2 X; @; ^6 o6 g# e3 r) Q | S, m' Create the results content.
0 I0 o8 n" | h; p, H4 d' xDim content As String = "<table border='1'>" + _ % R1 n8 q( o3 M# q9 p3 f
"<tr>" + _ 6 q2 D& N; f M% P9 y
"<td>Part Number</td>" + _ . C8 Z @* I0 A' @; g
"<td>Description</td>" + _ # P) Q- J: {* E/ W0 H! J
"<td>Cost</td>" + _
b; I1 O2 s- q8 L" {5 r: a. Y; Y "<td>Quantity</td>" + _
1 q1 Y! T) b0 T# ^. f& A "</tr>" ( n9 u! Q, {0 S7 B& }" A. |4 |3 A
/ K1 M8 w/ H) t5 y# H
' Iterate over the BOM Items 4 `: S. d% E* x- `
For i = 0 To count - 1
T8 j4 m; A9 Y" Q% B. s0 r' Get a handle to the relationship Item by index.
8 n: V" L$ `: _ Dim bom As Item = bomItems.getItemByIndex(i) ; L- l( T4 B, T4 P% L+ F" m/ p! r! d
& \# T# O0 |% t, v5 g; e' [
' Get a handle to the related Item for this relationship Item. $ n4 p# D) B5 `% Q) L% q4 w
Dim bomPart As Item = bom.getRelatedItem() $ V4 R& d2 e/ O3 T; T8 @. Y
: R$ ^1 ?$ u9 e' G0 ^# `
content += _ / i ~. K% t0 y/ ]9 Q
"<tr>" + _ 8 `7 X7 X3 y1 o- s( l2 Y
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 h5 p! @% i5 r6 e. A1 i) Q
"<td>" + bomPart.getProperty("description") + "</td>" + _ 0 i( Z- |* z' F& I3 D
"<td>" + bomPart.getProperty("cost") + "</td>" + _
) O. c6 l% i9 F2 _" `5 t "<td>" + bom.getProperty("quantity") + "</td>" + _ 7 ~# k+ l, N0 d$ N0 L7 s3 u
"</tr>"
4 t9 @4 }! |8 o6 C! n# N6 M' k6 u& DNext ; n/ e$ n N& e/ }; D; H
content += "</table>" ( G( b6 g5 C7 s9 Q
: }8 y; X O4 @, R9 B9 C, t G
Return innovator.newResult(content) 4 i, Y! u! {* \+ P1 Z$ S
( t& Q7 Z9 D8 I( ?
|
|