|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 4 S4 m6 d& ?6 u) U% I/ |' k! s
To query for an Item and retrieve its structure you build the query as the structure
. N% L; l0 P0 [/ L+ ~you want returned. Use the IOM methods to add the relationships you want and
* X. E }. h- M& T8 J) r% u! ?build the structure in the Item. The server will return the structure that follows the ( p- R2 C# u( d; c* C" [: Y C0 b# T
request structure. : e, Z' o( R- N" O$ B" z
This recipe illustrates several related concepts together, which are how to get a set 9 [* n; D& j8 ^9 `; g7 D& h+ l
of Items from an Item and how to iterate over the set, plus how to get the related ; a4 c1 F5 C, R9 O7 J V( t' b T
Item from the relationship Item.
% W2 T: {, a% \3 I8 I! l6 IJavaScript
! \* p/ Q+ N2 {/ ?1 n5 ovar innovator = this.newInnovator();
& t5 C' I: r5 X( ?! v3 \
( s' ^3 M& ?4 j5 f$ C, ^% N// Set up the query Item.
9 S. ~7 J5 L; V* A: w, svar qryItem = this.newItem("Part","get"); / Z9 l$ R$ Q; f, f, X" r1 g
qryItem.setAttribute("select","item_number,description,cost"); : @* V) s5 t$ e" O/ W/ K3 y# E
qryItem.setID(myId);
0 U! A/ r! j# p+ M
9 h) C; n- G! |$ n0 l3 s: J4 a// Add the BOM structure. 4 x3 H5 Z8 `: o& l7 l2 S) B
var bomItem = this.newItem("Part BOM","get"); ( P0 C2 ?6 S2 d" _" T+ n
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
& A# v+ Z8 I$ q5 yqryItem.addRelationship(bomItem); : y+ N, [9 i& q+ c; a
* w) @) Q5 K. X6 Y% {
// Perform the query. ; q+ }4 { p( r4 p: g7 v
var results = qryItem.apply();
9 Q5 w$ U1 l# m: R+ `; z i0 F 1 w; a/ ~1 O+ @% u9 z3 H" x3 c
// Test for an error.
8 L6 M6 E' U [: n9 @4 R0 Gif (results.isError()) {
# v* C: g: L0 x s$ \( m2 y: _ top.aras.AlertError("Item not found: " + results.getErrorDetail());
$ ~/ B ?; S4 w9 e) b G5 E) d return;
% T: e$ T9 O0 U6 v7 x0 o} 2 [7 E5 L2 o g) L R- o: s/ J
7 p4 N, Z4 X" w5 m1 d4 S& h// Get a handle to the BOM Items.
% G3 w- X( Y3 E' m2 T+ Ovar bomItems = results.getRelationships();
2 w: v; h( w2 f( G' H# [+ |var count = bomItems.getItemCount();
. c# M( z7 v6 R* J5 g2 D " U1 ~% K) p2 l
// Create the results content.
" \$ k$ S2 m/ z. f" jvar content = "<table border='1'>" + 4 F0 C1 U9 s6 w8 b
"<tr>" + . |" [* C. I3 _+ ^- }9 l8 r4 T5 `+ k
"<td>Part Number</td>" +
' z. S% q' f n "<td>Description</td>" + + t x8 t0 g {" N# `+ ^: c
"<td>Cost</td>" + ( B$ S' i0 \6 J0 y0 R
"<td>Quantity</td>" + ( y# N( o i7 U3 j4 c/ j4 K
"</tr>";
6 J- D, G3 h0 q( m% q. Y
; v8 M. W: J' Z9 |6 H* T- l5 c7 H// Iterate over the BOM Items.
( v k8 L- E& {0 p$ [for (var i=0; i<count; ++i) 0 f5 o- f$ N# z; V
{
* ^1 P6 p T( S. i% l// Get a handle to the relationship Item by index.
+ c7 A, j, W+ G. c var bom = bomItems.getItemByIndex(i); 0 p, c1 t7 `% C9 p) L
// Get a handle to the related Item for this relationship Item.
( h0 h7 v8 I- O" X1 u) O6 X$ o var bomPart = bom.getRelatedItem(); 2 ~2 Q4 S' a2 `2 x" w1 w/ e
4 s. M1 H3 R% _
content += "<tr>" + / p9 X% C+ q$ j
"<td>" + bomPart.getProperty("item_number") + "</td>" +
4 }+ ]% c/ u$ l {) Y9 i& @ "<td>" + bomPart.getProperty("description") + "</td>" + & ^; f8 f' L/ m( ^+ a
"<td>" + bomPart.getProperty("cost") + "</td>" + : T* K1 Y% w- M2 {7 h& `
"<td>" + bom.getProperty("quantity") + "</td>" + 6 s) T q, o8 P, P* ^
"</tr>";
5 Q' Z+ U" m1 m" j e; R, ~4 N, c: M} : Q1 U5 M. t/ K! @6 q
return content + "</table>";
* [* `- W4 `" d6 y; c( k2 c! a+ d3 N, Y/ ?8 P+ l6 x* C+ L
+ c$ s |1 A& |5 R1 F D$ L$ H1 Y
+ b( d8 O0 K3 T
* ^% S: ?! M* VC# f* L" g8 @7 I" o
Innovator innovator = this.newInnovator();
$ h7 u, m) _4 c3 X$ ?
# U5 G2 i7 S. D$ P3 a# F2 q// Set up the query Item.
: a8 }9 p3 C0 P9 }. [ TItem qryItem = this.newItem("Part","get");
' N- f9 h8 U7 y7 D9 _; j3 Q1 WqryItem.setAttribute("select","item_number,description,cost"); & ?% R/ i5 P0 z) i. u
qryItem.setID(myId);
3 F2 A3 @( B" ^% t
% N2 \7 T9 h& x4 T$ Y; E% Z! u// Add the BOM structure.
0 X$ b$ Z) o* k/ ]Item bomItem = this.newItem("Part BOM","get");
" ?6 f3 o7 q: ]6 z5 X K6 @bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
. H% t m9 ]8 ^' jqryItem.addRelationship(bomItem); 0 I; d& j4 V6 h# e
( }0 E0 \, }9 p, J0 d( g// Perform the query.
& L' V$ W) i [# g6 s" S5 DItem results = qryItem.apply();
/ w. X6 k5 S, A# z( t3 ^
/ k0 a! {; u) C0 ~3 _// Test for an error. 8 i7 ?* ^9 Z/ Z3 _
if (results.isError()) {
- t9 B0 W. m+ I9 X; A' f e! @ return innovator.newError("Item not found: " + results.getErrorDetail()); ; x4 G* K1 H9 Z* P
} ' J# f7 g, l9 n8 {- o4 {
/ `: ?1 e' }2 d/ I/ B6 R
// Get a handle to the BOM Items. ) J6 X% r: ?% l2 t0 L) I) e
Item bomItems = results.getRelationships();
% t: @" C0 m6 a' e& _int count = bomItems.getItemCount();
9 C. \. c4 v4 ~9 Mint i; . b5 l9 z6 {2 v# w1 P7 G
' M" }! z: K' y8 l6 ^ N
// Create the results content. ) U9 z. p3 [& k7 g- `. U
string content = "<table border='1'>" +
, D6 L9 P2 u& l% }) s* K "<tr>" +
6 u, w% |( `: n "<td>Part Number</td>" +
$ Z: Y' B8 q+ E2 Z, A1 \8 A/ K* P "<td>Description</td>" + 8 K( C8 P6 h0 |+ c3 F
"<td>Cost</td>" +
7 y" g! a1 j. g7 ~$ R! e# d) ? "<td>Quantity</td>" + / e6 r2 w$ N+ b+ i2 ?6 R" @1 e# `, h3 H
"</tr>";
2 s$ J0 q/ b6 B1 g* T* I: k5 \ 7 I7 `" N8 e# p- h+ A) I
// Iterate over the BOM Items. + u) Z$ ~, L2 t
for (i=0; i<count; ++i)
i& d) M5 q2 }( E. P{ 9 O$ [" z7 d3 k6 v4 F
// Get a handle to the relationship Item by index.
& T9 o6 A; Z+ T. X& s! r; } Item bom = bomItems.getItemByIndex(i);
- B9 _& p+ P+ f// Get a handle to the related Item for this relationship Item.
# u; j, z0 ?' c) U q! G2 E Item bomPart = bom.getRelatedItem(); ) o- E; E& ~" z5 i
* {: D8 ^" W7 X+ T6 w9 W: x content += "" +
: f2 _6 r( k# G9 b5 M) j: T "<tr>" + " C4 g" O- E2 D$ x- _
"<td>" + bomPart.getProperty("item_number") + "</td>" +
+ u$ t" I) y4 j& _2 x, A# ^ "<td>" + bomPart.getProperty("description") + "</td>" +
E4 t* Q$ O# \, Y { "<td>" + bomPart.getProperty("cost") + "</td>" + 5 G/ O5 Q$ h! t) P0 x
"<td>" + bom.getProperty("quantity") + "</td>" + . l% Q- e+ I. D1 M$ \
"</tr>"; 0 s! D7 R& m- P! w( q% ~
}
8 w M d9 G8 n" q+ `' l hcontent += "</table>";
9 D4 p3 x$ [8 V- l, P. } - r7 m: D! X$ q" |' |4 G( U( M! t. x
return innovator.newResult(content);
6 [( _3 C7 i3 A
, Y k! E% j& N+ N( g- B" V: e: P
# L0 O. i2 m( \' Z t! r* p
* ]7 t/ Z1 Y# D$ V1 K, p2 f3 F9 C2 D/ t, w# u: ?% O! p
* h% ], g+ \; C% G/ S3 I" G5 Q) H# O6 x. f' \4 Y1 f
2 H+ i+ l* h3 t ~6 N
Page 46 ) L) D; F; o- r9 r' \0 Z$ Z
k: @ A% U- ^
Copyright 2007
3 m( l& [) ]7 d; jAras Corporation.
( z' e/ t0 j8 ~, Z _All Rights Reserved. ( a5 p1 r; h6 S* v( H' v1 f0 R
VB.Net : d x" M) g% W
Dim innovator As Innovator = Me.newInnovator()
" c2 f3 R: U7 }4 j" a * Y6 C, S# X% e0 w T
' Set up the query Item.
9 H1 g7 ~3 e$ \, X% GDim qryItem As Item = Me.newItem("Part","get")
& w) Y7 l7 R: |& D4 e$ MqryItem.setAttribute("select","item_number,description,cost")
$ z& e# g' e5 _7 |% vqryItem.setID(myId) , H6 I) l* ]# m! A% V+ \4 D1 {
3 {1 k* Z* h @2 z' Add the BOM structure.
: G5 n! q" d- U, a( s: ?Dim bomItem As Item = Me.newItem("Part BOM","get")
6 r2 P$ { e2 ybomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 1 }% j2 F, e4 c5 [' |
qryItem.addRelationship(bomItem) 6 e/ l6 c/ y& t+ d4 M! C' E( G
6 v g4 F2 v# x( O) t- \& K' Perform the query.
- B( L0 t) ^% w/ sDim results As Item = qryItem.apply() + L, M) H- r& ^& z1 j& }
5 H/ S0 f: D7 F2 _( ?% j
' Test for an error.
/ w- {* l9 J6 Z8 e1 P, \- t" R/ YIf results.isError() Then
) a; u) Z4 t% o# { Return innovator.newError(results.getErrorDetail()) . n) _( d' ~. k% _& F8 N: T. _/ V
End If ; ~* N/ b; n5 S* S& T1 Q
* d1 p% F5 E* d/ w9 Y$ n' Get a handle to the BOM Items. # u5 B5 }& P7 V f
Dim bomItems As Item = results.getRelationships()
, a' K, V) M6 |# T' ~- e. hDim count As Integer = bomItems.getItemCount() / m7 K* z* d6 c% G8 F
Dim i As Integer 8 x& _$ v( Y' ~# U0 {2 w
: Y- f* |- Z0 L; y+ M, Y3 s2 n' Create the results content.
: v- M, i9 m6 q* QDim content As String = "<table border='1'>" + _ : e/ r+ @& T3 U! s- e& W
"<tr>" + _ * E$ R0 L! T0 L6 \$ g$ F2 n, @
"<td>Part Number</td>" + _
" k$ a1 {0 @5 v$ `( D" n "<td>Description</td>" + _
}; I0 L W. a, l* z "<td>Cost</td>" + _ ) }- K! x: m/ {+ Q" j; A) F
"<td>Quantity</td>" + _
5 w, C- L, h- z1 T% r "</tr>"
9 b6 G" A; x i2 @) } . }# D, c; p, j! v, d
' Iterate over the BOM Items
# r. m9 V+ ~! w2 b R, ?For i = 0 To count - 1
% \' Q& X1 B, `& ?( X3 k) O' Get a handle to the relationship Item by index.
' L/ \: O& e2 ]5 u- ?6 q6 _: n Dim bom As Item = bomItems.getItemByIndex(i)
% z+ H4 C: U/ U! Z' g g$ M $ c; n9 n7 E9 L: K- _
' Get a handle to the related Item for this relationship Item. 8 K" J/ m: p% z
Dim bomPart As Item = bom.getRelatedItem()
) C0 w: r* `9 q' X - ?$ F" b( F9 P
content += _ 9 r5 k J+ k; E) @- M, J& E
"<tr>" + _
* T0 V: S$ d( Q0 h% }$ N "<td>" + bomPart.getProperty("item_number") + "</td>" + _
6 E% r2 B& c( e0 h; U! { "<td>" + bomPart.getProperty("description") + "</td>" + _
& y ~( p* `9 w* K "<td>" + bomPart.getProperty("cost") + "</td>" + _ 7 Q: ?4 L" S' ~9 D* R) a
"<td>" + bom.getProperty("quantity") + "</td>" + _
2 T# ~' [4 {9 Q6 t! R "</tr>" ) T3 U. ~# @1 p7 }, G' e' ~# c. H
Next
3 }5 V% M( j6 Q! ccontent += "</table>"
2 P9 K+ S/ p8 a: w . H6 k7 P h, ? `) T& N
Return innovator.newResult(content)
! Q C# Q( o1 U, | R3 d! f
4 J6 e4 D! G. b: B' ~ |
|