|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ! J* ?/ Z; s, ^! H& m
To query for an Item and retrieve its structure you build the query as the structure - ]0 K' I# W# V* D8 S& {" o: G
you want returned. Use the IOM methods to add the relationships you want and 4 J( i# i& |4 Z- V
build the structure in the Item. The server will return the structure that follows the
' ^- H$ d" m- u4 |/ ~5 V$ O5 Nrequest structure. # l5 F% r0 X* V; {9 }: ^
This recipe illustrates several related concepts together, which are how to get a set
# g8 I$ v. [: R% O- Pof Items from an Item and how to iterate over the set, plus how to get the related
- _6 A9 j: v D* UItem from the relationship Item.
8 }& q N0 v! s+ p9 gJavaScript $ l6 H3 E/ E& e3 w! f% S
var innovator = this.newInnovator(); & G2 z+ H+ O- w! y* J
9 D, ^6 V8 }, C/ H1 ?, h
// Set up the query Item.
, l: h+ N3 m* k" `) H% ~: k) C" Jvar qryItem = this.newItem("Part","get");
* f" L, a/ E3 O9 e1 R2 ]+ YqryItem.setAttribute("select","item_number,description,cost"); / W" q" m8 a$ b& V
qryItem.setID(myId);
$ c& Z6 u. T5 P3 |( q/ M& B
! r& f! c0 m+ V, P+ m// Add the BOM structure. ) y) e- |2 N& @
var bomItem = this.newItem("Part BOM","get"); 3 e: E+ D y( p# u, e; O
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
4 }! U: X( \- l9 v+ DqryItem.addRelationship(bomItem); 6 q# O* G2 F5 N# J$ y
% M4 G u) h: E1 e. n// Perform the query.
, r, v' c4 J; D7 _var results = qryItem.apply(); $ H' h% Z0 }! J$ b# X/ R
4 b! a! C9 U4 S6 F/ I
// Test for an error. ( R, F' P" T. G5 n9 _/ ?+ n
if (results.isError()) {
1 R0 P- Y* } A9 ^' a1 I6 U top.aras.AlertError("Item not found: " + results.getErrorDetail()); ! `; g6 O, G3 F
return;
7 N. l) w/ y. U- j! o& r$ s} 5 n+ M1 Y! B7 R
) |( D- N: B, e1 H- o# I+ z# C
// Get a handle to the BOM Items.
; A8 d C. a% c/ xvar bomItems = results.getRelationships(); 0 U' ~) g% B* W0 i7 M g' X
var count = bomItems.getItemCount();
- {, @) |8 N% c# }% l& e% E ) @% y! C) {6 B9 W2 j6 h$ I2 {
// Create the results content. ' G6 k$ n% x( X5 b6 Y- `9 }) }
var content = "<table border='1'>" + " R) e& q h% z' v2 ~+ o
"<tr>" +
7 X7 d+ s; X9 i# } "<td>Part Number</td>" +
8 e, ]- W. G% ^1 }- {" x "<td>Description</td>" + ! q6 v2 h6 E1 k9 c
"<td>Cost</td>" + ( D: C$ }$ v+ d$ g" v
"<td>Quantity</td>" + 3 {( n, f2 \& n7 n
"</tr>";
) o' b$ k) E7 k. h: a
& X. o# R, \1 C* V5 t( _: r( J// Iterate over the BOM Items. & k) l! _$ i* M1 O9 F6 a6 s
for (var i=0; i<count; ++i)
# i# t' B2 A4 m( n$ @4 W) p. h! l# B{
m3 p9 Z5 a5 U$ F% p" j& N3 u! l// Get a handle to the relationship Item by index.
6 ]! P% F5 G* Z+ F" d ? u var bom = bomItems.getItemByIndex(i); . y! J" T% P/ R/ A4 E1 [% g" H
// Get a handle to the related Item for this relationship Item.
* `# v, }! r: O T9 ^ var bomPart = bom.getRelatedItem();
) f- f8 y# f1 C& s5 X: } ( W8 v; w s% G6 [
content += "<tr>" +
9 T! y- O7 F: S "<td>" + bomPart.getProperty("item_number") + "</td>" +
& e$ @+ X6 d% Y& g4 S N "<td>" + bomPart.getProperty("description") + "</td>" + , h7 b4 g3 N7 M) b: g! P
"<td>" + bomPart.getProperty("cost") + "</td>" +
6 k! l- ~) \* _. r# N "<td>" + bom.getProperty("quantity") + "</td>" + 1 d3 }6 I; _8 s6 g; B$ \
"</tr>"; * t+ `. j ]1 k8 X D2 Z
}
" c9 k9 R4 X6 f: I( W# f) |$ Creturn content + "</table>";- |. ]: I3 J& A( X" N. x( l& e7 ^
* K4 [5 c( g& v$ a% T: f
+ j, j* s4 ]: c4 ^- `3 m: f. P2 a; v3 l2 f) u: h: Y, [/ d
$ }% ]: X- q1 A
C#
. u, |6 ]4 B5 ` n' ]; G0 g1 gInnovator innovator = this.newInnovator(); " ^# N" B& u3 h0 V2 e( ]. U
8 P" U5 n( h4 d V- m# v// Set up the query Item.
3 r+ o( J% H6 cItem qryItem = this.newItem("Part","get"); ) |% O+ c8 d) M7 B7 j5 o8 n& C
qryItem.setAttribute("select","item_number,description,cost"); % E1 s. S- c( {% T% [
qryItem.setID(myId); 6 I5 y! Y1 ]# |9 L- m1 Z' J$ Q
- `* E |; |: [) \// Add the BOM structure. 4 S/ N6 h; ]5 `# w' {9 m; z* x" w6 [
Item bomItem = this.newItem("Part BOM","get");
- h r& a. S8 e) ~' a9 ?2 ` abomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); % f$ E' E# l- c5 J; q$ y" ]
qryItem.addRelationship(bomItem);
; l- O6 A9 b, l8 g 7 \: E; q& B8 `$ h Y
// Perform the query.
0 y& ?! D2 J/ ZItem results = qryItem.apply(); 3 f& P6 u0 c9 c7 {7 u4 b
: Z, q \: t1 z% f3 U4 B9 B2 J
// Test for an error. * M+ ] x# g3 ?1 G9 u* U. C/ M, N( l
if (results.isError()) { 0 M8 P" N3 S8 x/ R/ K0 A
return innovator.newError("Item not found: " + results.getErrorDetail());
. T* ?$ N& D$ @3 t& o} 3 w2 d/ D1 M. q4 f3 \
: Y( o) i" Q7 A, D6 g5 T: q) R% _// Get a handle to the BOM Items.
# p& ]/ _0 }8 b9 J- y3 a1 n) |4 CItem bomItems = results.getRelationships(); 5 g! K+ _/ z# Z% V; ?$ A
int count = bomItems.getItemCount();
* x. r3 a# H! o, Mint i; ; V& S) W* a5 R
9 o: v/ `% \+ P+ s3 A) Y' Y0 h// Create the results content. * E7 P# f7 e1 s/ b" X- @9 O
string content = "<table border='1'>" +
1 {8 f. z* ~7 y "<tr>" + * F5 x: o& k6 x7 X
"<td>Part Number</td>" + ) p- c! X g9 y2 S) B
"<td>Description</td>" + - K7 r9 y( t( s5 X# V6 A
"<td>Cost</td>" + 6 |3 c$ c3 u" V7 ^$ r$ m
"<td>Quantity</td>" + % U; Q6 h8 V" {5 U1 e X1 Z
"</tr>";
" R7 Z0 O- z. d% g v ) t3 n2 l$ U; r* t
// Iterate over the BOM Items. / t9 Z: M" U. x3 h0 Z3 S
for (i=0; i<count; ++i)
" f' A5 b, H. T- L: J% N! W% ~ L{
. ?; _8 y2 D( m t/ a2 P0 A// Get a handle to the relationship Item by index.
( z p4 _4 n; U O0 f" u5 n$ R Item bom = bomItems.getItemByIndex(i);
& D; m3 K" P! ^: `2 Z. h// Get a handle to the related Item for this relationship Item. " D2 D$ k- x. H4 j0 U
Item bomPart = bom.getRelatedItem(); - D/ U2 A; D- K9 N( k
8 `. s* d% ?. |" W
content += "" +
+ V' r5 ]4 }! ~' j! o* ^ "<tr>" +
5 n6 i7 f- W5 E# ]8 Z "<td>" + bomPart.getProperty("item_number") + "</td>" +
+ b8 X/ N+ C7 x5 ]- O8 f. a0 m "<td>" + bomPart.getProperty("description") + "</td>" + 0 Y3 r$ `, c ~2 Q8 H8 r
"<td>" + bomPart.getProperty("cost") + "</td>" + ( _7 _' D* u2 l* A& w
"<td>" + bom.getProperty("quantity") + "</td>" +
& a7 N. E" R" _ "</tr>"; 2 M& F K: \: K7 W) Z# v J, d, l
}
! Q1 |% n" f3 t! x1 Y. s7 ycontent += "</table>"; , M b6 L/ {# M
! G/ Z" k1 \+ |3 e: [; O" L
return innovator.newResult(content); * \2 q2 w+ s& T; x/ v" {8 ?6 I* L
( \' Q$ x* _2 a* s8 Y& |/ g7 u% X1 c0 q
8 { d/ W. \! m' y4 V
3 f5 f+ K! ^& V9 O( j j1 Z5 t% T% ~3 U v2 o7 m9 }
8 u @# ]5 R) j, H0 m
! x" W( z$ W( E" Z
Page 46
: U( H4 c( ?9 p% F - M6 t8 Y! E/ h; j4 [
Copyright 2007 . i4 T: ^9 e% }# T( ]( U
Aras Corporation. 9 q* E# ^8 G6 c
All Rights Reserved.
) Z$ ~ ?% N& \& [) C5 jVB.Net
4 a+ x% r: ?* c& Y" Z- ADim innovator As Innovator = Me.newInnovator() ) Z9 k$ X0 g* n5 y! [' ?
7 ~- ^6 `& y, M3 S; R! {
' Set up the query Item.
- p7 i( F/ S% I% j4 {7 b- ^: ODim qryItem As Item = Me.newItem("Part","get")
8 t( }- j+ }5 D( C# n- HqryItem.setAttribute("select","item_number,description,cost")
( M- h! m9 n2 S/ j# {5 d* Q- @5 ?3 GqryItem.setID(myId)
' }* Q: \+ a4 a
8 _) _$ B& R9 n+ D( q' Add the BOM structure.
+ { E- m. o9 k4 O3 U% PDim bomItem As Item = Me.newItem("Part BOM","get")
3 f& e$ }. M6 Q& b# \; t; VbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
2 I1 @8 L) o( F; L, z- }qryItem.addRelationship(bomItem) : S) }2 P' F f7 a1 s+ K2 j
) @( e# s4 k: n: g# e4 E/ R' Perform the query. ) G( f' N9 m6 l
Dim results As Item = qryItem.apply()
3 k% v% D; w5 i " v( G4 O: w% X0 P: R3 Y
' Test for an error.
* A# b- ]" I& t8 cIf results.isError() Then
4 p4 U2 f. n+ u Return innovator.newError(results.getErrorDetail()) 7 w( t9 _5 z" u" a+ W" r7 e
End If
2 E4 l/ R5 n, B! V, v# u, u. f) K : |9 }$ L6 S1 K
' Get a handle to the BOM Items. " a- h- D. o! [) E8 n
Dim bomItems As Item = results.getRelationships() $ G9 Y( t" l1 O3 Z+ ], A
Dim count As Integer = bomItems.getItemCount()
! T: z+ j ]/ d9 x4 GDim i As Integer
* c) g& I# g! `+ q: f L2 ] ] 9 e. }: B; E! v
' Create the results content.
7 D5 J7 v4 a/ [7 LDim content As String = "<table border='1'>" + _
# Z9 d% c8 \; l6 w8 P "<tr>" + _ 5 k5 t7 Y# t; u7 w9 {& W
"<td>Part Number</td>" + _
3 D" F$ p4 n: |% M1 O "<td>Description</td>" + _
9 |; I H8 J. v+ U( A$ S) W; s/ C/ y "<td>Cost</td>" + _
- g' g7 c/ C8 | e" z "<td>Quantity</td>" + _
2 L" P& g* B. S: Y- i4 ^ "</tr>" 8 v/ B$ k) t( K
1 v' }6 O7 P+ s0 D6 x
' Iterate over the BOM Items 0 ^9 X; C% a4 S) V( u6 U+ U
For i = 0 To count - 1 & ^ ?9 n' r! E a- N
' Get a handle to the relationship Item by index.
/ \$ o3 _$ l, ~+ M s/ G7 I Dim bom As Item = bomItems.getItemByIndex(i)
$ i- ^9 l2 s# X! Y" T& N4 U8 x
3 k# } |9 s& w! Q' Get a handle to the related Item for this relationship Item.
* N/ r; T s- v% f$ O Dim bomPart As Item = bom.getRelatedItem() 7 V9 a* a9 P& s! i1 e0 Y. o
3 \% P9 O, C( G! ]# P( L. Q5 T% E content += _ ! V# t7 H; Q2 A
"<tr>" + _
- Y& J# w [+ K! Y "<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ r( y" Y, J, Y# s% N( l# ?0 R( |
"<td>" + bomPart.getProperty("description") + "</td>" + _
" Z1 z: L8 a" L6 `2 n3 s: e "<td>" + bomPart.getProperty("cost") + "</td>" + _ / A+ r! N: Y% ]( B
"<td>" + bom.getProperty("quantity") + "</td>" + _ & U! X9 O( c' r, Y* h! Y7 P) D
"</tr>" U: S! H) r/ M& i" x
Next , ^; H# M: J1 A) O/ J% P
content += "</table>"
( W6 |0 |. n) Q. A) _5 g' \
& K5 z+ I. N' n# I1 ]7 T RReturn innovator.newResult(content)
7 Y, z n6 c( w6 ^2 Q( q
8 x( k% y# Q% l) r |
|