|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique * L/ \3 s! C) @5 Q* S8 ?
To query for an Item and retrieve its structure you build the query as the structure
- [' ~6 ]/ ^6 l# L- ~( Syou want returned. Use the IOM methods to add the relationships you want and ! G- V# @& @/ Q+ t
build the structure in the Item. The server will return the structure that follows the
3 U: t$ B1 v4 _) F# urequest structure.
7 U- q9 f$ |+ S$ y' _) c% @This recipe illustrates several related concepts together, which are how to get a set
1 a0 F2 k' X' h- t) Hof Items from an Item and how to iterate over the set, plus how to get the related
% G1 }, H, ]% DItem from the relationship Item.
' w& r) C, y$ b- h% U4 VJavaScript
3 j- e6 t/ X9 P# @/ V0 ~3 }9 cvar innovator = this.newInnovator(); 2 H i- P+ c- | D: `
# {8 ^0 V( u2 L& P// Set up the query Item.
* ~. i( B$ f- J/ Gvar qryItem = this.newItem("Part","get");
2 p% n( y. ^) d$ \$ ~6 _0 c: [! GqryItem.setAttribute("select","item_number,description,cost"); 9 B) H$ s( ~" y( a
qryItem.setID(myId); & U7 F9 }7 H- P+ N2 T
% w8 X: Y# ]6 {3 h1 o// Add the BOM structure. : D8 P# U, f8 R% e g% W
var bomItem = this.newItem("Part BOM","get"); * ]' z( y" O: r$ q* }
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
/ _ \. [- ~3 ~4 P7 BqryItem.addRelationship(bomItem); 1 Z) d1 h# k, i# E- v8 z+ _: S
* u9 ?: ^/ [7 ^1 ^// Perform the query.
$ Z; k" V @; V. \7 h$ R; nvar results = qryItem.apply();
$ t8 C5 Y+ ^$ [' x \
( E C$ s% s0 `$ ?6 q// Test for an error. % h4 r- `- B$ y
if (results.isError()) {
$ ^/ O, } w0 w! A. D0 ^ top.aras.AlertError("Item not found: " + results.getErrorDetail()); " y4 }5 s9 v2 ]) v. j
return;
9 |2 I2 u( w1 o6 I3 ]9 P}
( Z: |$ n X! j. t& g8 s& `5 L0 a 7 @& {( B. [! g: E! h7 \2 g
// Get a handle to the BOM Items.
" h/ z% ?3 Y3 Xvar bomItems = results.getRelationships();
. J* l' \* t$ b% Y& i, H" ]- xvar count = bomItems.getItemCount(); ( P4 A+ G8 P j @0 u) N* T
- i" H9 o3 F8 `7 B7 E& K3 g' q
// Create the results content. + h. J5 u7 S+ z" O: ]9 A" D
var content = "<table border='1'>" +
2 Y+ z, q8 B- @- W% I% t "<tr>" + 1 e0 m% f0 s% l O& j
"<td>Part Number</td>" +
- v* Y# P1 _3 C "<td>Description</td>" +
: q- C3 S3 |! z$ A "<td>Cost</td>" + 1 E. H# d6 l- J
"<td>Quantity</td>" + " e6 B2 S% ]7 p+ t( c u
"</tr>"; # e" M6 g: z5 `, G; i
( C% s$ s+ Z6 z' H
// Iterate over the BOM Items. 4 v- x9 i3 ^. i0 ~
for (var i=0; i<count; ++i) 2 z. W; ]7 b' k& R
{ . N) { W% U ]8 d* C6 Z. C) f# J7 k" L
// Get a handle to the relationship Item by index.
9 a, g5 c1 k6 s: M& p6 i0 N' C var bom = bomItems.getItemByIndex(i); % E6 W A" R+ ]" D4 f
// Get a handle to the related Item for this relationship Item. " G1 H g9 N& A# `( W0 g; J
var bomPart = bom.getRelatedItem();
. V9 y9 X1 T& R
7 T1 w% _, w% x9 R; L content += "<tr>" +
' j4 P7 L; s8 u; G0 ` "<td>" + bomPart.getProperty("item_number") + "</td>" +
! `2 C' U( _. E. r4 }$ k "<td>" + bomPart.getProperty("description") + "</td>" +
. ?' |8 }- D3 u4 w: h "<td>" + bomPart.getProperty("cost") + "</td>" +
$ ^ B) \. g5 F8 Z$ w2 p4 U* F "<td>" + bom.getProperty("quantity") + "</td>" + 0 g# D* N6 V9 {3 J+ g3 E
"</tr>";
: L1 `- d; c; n}
% {/ W8 i- o/ C! U7 ?return content + "</table>";# @* \7 u" k& c
: Z9 x# A1 u u6 y2 c2 x( ^# u
/ h8 t2 [ v3 ?: l g1 c3 Q+ z- W& {& [+ R `' m
$ C; [& S* g; M! l' P1 \C# 2 U& a$ }, V. ?6 ^2 A" F% |
Innovator innovator = this.newInnovator(); $ o, \- O& n6 ~3 l
% ^# E' s; S* O1 @# Q# v- h7 I9 T// Set up the query Item.
- p0 |2 S& Z& r" R+ qItem qryItem = this.newItem("Part","get");
7 ]0 H9 r$ r6 W8 `! zqryItem.setAttribute("select","item_number,description,cost");
& [# `/ }# `% l- |( g$ {qryItem.setID(myId); & ^# j* C. m: @6 J/ d& N! R* o! k
7 q# `3 n2 X6 x: j5 u
// Add the BOM structure. ' E% u( T( O0 z1 } w% o
Item bomItem = this.newItem("Part BOM","get");
' t6 J Z& t$ x u; }bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); * C9 a- W: d% { |7 s
qryItem.addRelationship(bomItem); ' v$ [; z4 U# \1 [
/ G( U1 [) K# N9 v/ }- p
// Perform the query.
. R7 f9 I$ @1 vItem results = qryItem.apply(); / H4 N: t( b" J2 p7 O* Y
- X9 N9 s7 w6 I0 |! B* P; Q// Test for an error.
2 v/ W. s3 `. F0 B1 Lif (results.isError()) { 2 i% u( M) j# r% {- q/ Y3 G
return innovator.newError("Item not found: " + results.getErrorDetail()); b( g! @# O0 S4 U. N# Z
}
, [5 A3 F4 a- L4 R
# a4 ~1 V( V: J4 [0 i E4 R. }// Get a handle to the BOM Items. 2 n( s9 D. n6 l3 |" H/ D+ \
Item bomItems = results.getRelationships();
) d2 p8 F0 s6 T- E4 N2 B) ^int count = bomItems.getItemCount();
9 p5 l6 j! }0 l( F, rint i; * e3 J; X3 g u5 `9 c$ F. Z' ]$ ?
! |$ o$ G I2 I
// Create the results content. 1 N6 E# | T5 Q2 D
string content = "<table border='1'>" + + }, y Y- H" T4 Q
"<tr>" +
. {' |, z9 O2 s5 G% c' v "<td>Part Number</td>" +
+ Q5 k) w0 T- J! E9 j: u2 o x "<td>Description</td>" +
- O. h4 m5 z- m! Q "<td>Cost</td>" +
& G6 M+ b6 Q' \ "<td>Quantity</td>" +
( I! ?3 Y. y& G2 V "</tr>";
. b# n! g; m3 M3 J" A
8 b. r. w9 I6 Y0 y// Iterate over the BOM Items. . N4 D9 @/ t" A$ c( j& j, D+ ~& I
for (i=0; i<count; ++i) $ ^0 M. Q! M. Y y& l6 ^) M4 R
{ 0 x1 `! I3 y" U5 Q; c
// Get a handle to the relationship Item by index.
0 g! @+ g8 Y5 i* V9 O Item bom = bomItems.getItemByIndex(i); , J* B6 Q, X3 x6 ~& T7 v
// Get a handle to the related Item for this relationship Item. 4 n+ P/ W4 g: K2 Z
Item bomPart = bom.getRelatedItem();
?3 _" F0 F% H" h2 N ; P, {8 h ]2 ^: b+ b- I
content += "" + 2 _* P& j4 E$ y4 N" K0 F4 y
"<tr>" +
9 m( |8 m" ^, w; l7 i6 P "<td>" + bomPart.getProperty("item_number") + "</td>" +
. u9 ?( I! K# c+ l "<td>" + bomPart.getProperty("description") + "</td>" +
; f* A( }6 [' A- U& w1 L- h "<td>" + bomPart.getProperty("cost") + "</td>" +
2 {# t# P7 c1 H6 T3 |$ X# `! M. W "<td>" + bom.getProperty("quantity") + "</td>" + ' S3 p) C$ l. @9 s) c1 l
"</tr>"; 1 Q9 ^& T" g# |4 @. N- V
}
9 U: P7 r) }9 E R+ dcontent += "</table>";
3 i6 |. G$ P M
5 n/ S0 b4 v2 B, }5 O: k; y0 kreturn innovator.newResult(content);
) s" l9 X, i! ]+ j. A3 Q& a" u- {: f3 n8 e3 d) ]6 E) M
6 s- s9 ]3 r) _8 t" b6 \' Z( b# e$ h6 Z0 W3 d
+ a1 J( z. {8 D2 i \
. B, e. ]; a# ]5 c: _
0 p9 G: N5 H) J0 _
- D5 t. Q& m0 E- h5 s3 |6 n+ S- u# c
Page 46
4 F8 ^8 M2 v& R. O: R7 p
5 ? J# X8 t9 [ ]8 l. kCopyright 2007 : ~( m1 c7 I- z2 |1 a& B& h
Aras Corporation.
6 y+ V/ @4 T: i* |5 IAll Rights Reserved. ' S0 z5 D: G" j
VB.Net
/ P5 p, {) N; y$ q) i# ODim innovator As Innovator = Me.newInnovator()
4 h( P4 }2 A+ |
+ F' I; v& j, a& R9 @/ k( W# e2 c' Set up the query Item. ) X6 d: P7 J/ x* y; l0 l
Dim qryItem As Item = Me.newItem("Part","get") . |, W. B8 t+ ?
qryItem.setAttribute("select","item_number,description,cost") 6 M0 Q& ?' O; p' H0 n' s0 z2 V( b
qryItem.setID(myId)
0 a! d1 B, C: g% x8 I , h) y. R+ b1 y" t& Y
' Add the BOM structure. 2 t/ e8 G7 H* G! Q# d
Dim bomItem As Item = Me.newItem("Part BOM","get") # h2 ^# F4 N1 n! B( X& D" ?
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 1 _" c- x: M7 g) q& P0 _& f: ~
qryItem.addRelationship(bomItem)
, i1 j3 f6 ]5 U/ M3 Y! A& i4 w# `3 B ( L- J( ]4 |' r1 V# u
' Perform the query.
6 d6 \- {, ]% B/ p8 X: WDim results As Item = qryItem.apply()
+ E: l k5 ~& Y% W" V ) @0 h( T5 h! ]( D
' Test for an error. . f0 e0 Y2 ]$ E# d M
If results.isError() Then . T6 \/ k; q( b
Return innovator.newError(results.getErrorDetail())
& T+ \0 f/ @1 C7 S1 \- nEnd If
/ S) U! p2 ]" i) P% }% @ 1 L6 }: L1 Q2 `) T* }- S0 k
' Get a handle to the BOM Items.
$ C" x6 a3 B k; L! g3 r- t! iDim bomItems As Item = results.getRelationships() 6 d {% I3 X( L$ h7 m4 X* d2 \
Dim count As Integer = bomItems.getItemCount() @$ p# R" a2 N
Dim i As Integer
& e$ z( A7 ~$ ?- r ( ~# n0 p( Q7 r1 ]: f. s2 y7 f, d
' Create the results content. $ c6 [( L, f0 g( c
Dim content As String = "<table border='1'>" + _ 6 `7 r: q% ?5 q1 i4 N0 T5 l
"<tr>" + _ / A9 ]' g+ ^" w# p9 s2 o
"<td>Part Number</td>" + _ " q( |# {4 z. b! X6 B9 @7 }
"<td>Description</td>" + _ 8 \. \ F4 D: U: g3 f6 G* N$ d4 p
"<td>Cost</td>" + _ 6 |8 V" Z4 I2 m8 K
"<td>Quantity</td>" + _
% \- Q+ {0 G9 j0 d9 K M "</tr>" & f4 P0 W$ w* J5 H
/ Q' W# @- \# b& b
' Iterate over the BOM Items
3 \6 R4 a- h( h. n2 F# {' mFor i = 0 To count - 1 ) n; w2 L; M# @- x7 J# b
' Get a handle to the relationship Item by index.
+ v2 U: A" H6 Z0 J0 M Dim bom As Item = bomItems.getItemByIndex(i) $ L. L* x3 b7 o1 Z/ @6 \
) F4 K7 G( S- {4 Q! X3 \$ M
' Get a handle to the related Item for this relationship Item. 2 A8 \' }* l- `
Dim bomPart As Item = bom.getRelatedItem()
7 T5 e0 V) j) t5 S
, }2 S0 S$ u4 C) s4 g) T; A content += _
# ^; {" [* f% b; x: r: w8 c5 L" v( u "<tr>" + _ " }" ~( v0 s& r n; Z* _
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
9 [8 m6 B& q& w9 p8 G "<td>" + bomPart.getProperty("description") + "</td>" + _
2 t) d; U1 f1 y6 p" @2 O. ~5 T "<td>" + bomPart.getProperty("cost") + "</td>" + _ & e$ U4 v1 i5 D+ D
"<td>" + bom.getProperty("quantity") + "</td>" + _
0 @6 D5 d% A; s "</tr>"
* s( K ]0 Y- e8 n7 B$ a& @Next
/ R+ m: R% F$ E7 X! _content += "</table>" 3 c' L8 x2 p4 p. T8 Q
$ B r8 Y/ M: a, B+ [6 C) yReturn innovator.newResult(content)
3 b! Q# ]/ H4 w8 ~1 d) N
9 q$ m. c' Z( f7 E& v7 J |
|