|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique % W9 q: V/ s0 F% B6 w
To query for an Item and retrieve its structure you build the query as the structure
0 u, X1 H% [& U- |4 V: k( zyou want returned. Use the IOM methods to add the relationships you want and
6 O$ K+ Z U% T8 F* u$ gbuild the structure in the Item. The server will return the structure that follows the ! _/ C( A( e0 ~+ }* i
request structure.
2 v, s: g+ p9 \, k* e' wThis recipe illustrates several related concepts together, which are how to get a set # s4 a$ n- ?; f t" R; C$ Y
of Items from an Item and how to iterate over the set, plus how to get the related
G$ Z% ^! ]5 y* jItem from the relationship Item.
3 z2 g. |: ` L' K$ B$ `JavaScript
% ? g1 U& f8 Z6 Q% Yvar innovator = this.newInnovator(); 9 J: {) V( W3 L/ E+ B0 Q8 ?/ W9 p
9 E+ I* X" s+ o8 T2 J) T// Set up the query Item. 3 A# z: F% @: u
var qryItem = this.newItem("Part","get");
" X& ^) J( _" P" E, W% S3 ]+ FqryItem.setAttribute("select","item_number,description,cost");
9 C9 g" c# c: [/ N5 U( WqryItem.setID(myId);
: o4 [; {; h' r: N3 x9 ` ) y% _6 Z3 J! z2 a% ~% i- E9 _
// Add the BOM structure.
) K, j5 F; {3 ]* w( H6 Nvar bomItem = this.newItem("Part BOM","get");
" c* [$ z- }6 v* p, w7 Y; mbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
# U' Q8 C& j7 d/ [5 m3 ~& e4 MqryItem.addRelationship(bomItem);
) r; ]9 o- q" o, y: J7 Y
: v3 j' i8 X" B! {$ g// Perform the query. . @/ E- P6 a% z7 r+ c3 f+ p
var results = qryItem.apply(); - s4 f/ C- T+ d" d' V/ K
* J: J; E6 v/ {) A// Test for an error.
7 d/ q- F) i( c4 r; \% @if (results.isError()) {
* S! }( I, }# P+ M top.aras.AlertError("Item not found: " + results.getErrorDetail());
2 ?$ b2 X2 O+ A/ o L- W1 Z( ] return; - ?: Y) m4 s7 x l- Q1 S' s
}
4 U6 M& |& v) _1 y& u" o6 R
9 _, ~4 X: Q) h) |5 l+ R6 S) g$ y) X: [// Get a handle to the BOM Items.
7 h, T* a- n' |) v4 wvar bomItems = results.getRelationships(); 9 L Q( Z% c& n# k4 `, y
var count = bomItems.getItemCount(); : ]+ ^7 F( k5 O e; V: h1 H- S3 j
+ _0 w/ y/ b/ d6 [// Create the results content. 3 W; G1 \# o) G, K1 r) d
var content = "<table border='1'>" +
& _" e* d% N+ U$ J "<tr>" + / ]8 r! o; t( s! V
"<td>Part Number</td>" +
, N1 ~5 H% e# u$ `' n "<td>Description</td>" + 0 e: o& R; S8 _* @
"<td>Cost</td>" + # h; O8 l' L7 f$ F4 U8 Y
"<td>Quantity</td>" +
4 |5 q3 @' A4 \" `4 D# O- ` "</tr>"; + z7 |; h% [& B. o3 v# y
1 F1 H) l( ^* W) @2 i# D) P* M+ f// Iterate over the BOM Items. + x2 R0 t ?5 T
for (var i=0; i<count; ++i) 7 E- Y- l; U) S. H
{ 4 o. q2 z" A" b1 {4 L% s, r
// Get a handle to the relationship Item by index.
8 N! ^# [0 [ S5 N- C7 g0 B9 [. F var bom = bomItems.getItemByIndex(i);
5 M) C9 d. z6 b) t3 N9 Q1 x: e# N: ]0 O6 N// Get a handle to the related Item for this relationship Item.
; C) c6 N* F" [* G3 { var bomPart = bom.getRelatedItem();
3 D1 R( c( f, `+ d5 C
& m2 Z1 c( G: O content += "<tr>" + # ^, a. I2 e: p; U% s7 z* Y, s
"<td>" + bomPart.getProperty("item_number") + "</td>" +
) M! x# _) O3 }0 \+ u "<td>" + bomPart.getProperty("description") + "</td>" + 7 X6 e7 X1 Z5 U9 `
"<td>" + bomPart.getProperty("cost") + "</td>" +
) ~7 \3 q4 U: ?% u2 R "<td>" + bom.getProperty("quantity") + "</td>" + 6 j, T0 a& [1 B( D" \ C
"</tr>";
' E; |' b: q9 t& V- f}
& ^3 x9 E h f f' dreturn content + "</table>";
1 b2 n2 Z5 ~; e( s6 Y& b9 n3 y! x6 I. U9 z/ K- Q* v9 S; u1 N
9 f8 q1 T7 A9 F) t3 y: G5 z) {; ~: ?; n7 b! ~9 M( H
! S9 t9 w8 r& XC#
8 X% t" X% s1 u- Q7 |, uInnovator innovator = this.newInnovator(); ' I) E: h7 z6 E! {) \( V4 _- z" s$ i9 u
( v7 U: l) o* y. B# O4 ?. }- M3 Q// Set up the query Item.
~7 Q \) d: x- `5 J% f8 J2 zItem qryItem = this.newItem("Part","get"); - T) I- A- u Q# v/ @( K' h
qryItem.setAttribute("select","item_number,description,cost");
- K6 U3 |7 g% G; }! \5 \qryItem.setID(myId); ! {, `. J4 ^. O5 p: F
+ f! k" z$ v }// Add the BOM structure.
; Y( ]3 u% G" M' a% |) LItem bomItem = this.newItem("Part BOM","get"); + ^! n" T2 g8 i/ o
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); : }! I& o. t7 a& j. x1 D
qryItem.addRelationship(bomItem);
* ?5 J F$ q6 r7 s3 | V; b3 n. A$ F
7 n5 @ R- `8 A// Perform the query. - {, Z% N# A0 `* o+ I' H/ k7 O: m5 s
Item results = qryItem.apply(); ' N/ t E0 m* J2 _$ D, v# i
- A+ l$ ~" w. p0 `: I. b& ]6 }// Test for an error. ; n" j1 q4 {* g6 a# W4 `+ }
if (results.isError()) { " Q1 D( h4 ?/ A+ j( e
return innovator.newError("Item not found: " + results.getErrorDetail()); . H' c- E+ | {6 i7 D
}
3 k$ x/ A2 L: m( m3 W 1 W) P( K& s+ ?
// Get a handle to the BOM Items. 6 N4 Y; @5 E9 _7 j! @, p
Item bomItems = results.getRelationships();
, H+ M8 ^% J2 n1 g+ G- d9 [int count = bomItems.getItemCount();
2 z2 S$ j- d6 h! e7 k6 Gint i;
; k- |9 f) r, @, V
+ P& o* g( ~1 s' X( t0 k6 Y// Create the results content.
' K y( m% j" B8 c( D9 a9 ?4 O. Nstring content = "<table border='1'>" +
4 F+ G) s8 e& s$ F, l# e. y; c "<tr>" + 1 ]6 {1 i9 e" w b1 U- A7 c; |: B
"<td>Part Number</td>" +
2 c9 {6 p) b6 J* E0 {5 I "<td>Description</td>" + ; d: J$ @% J/ ^
"<td>Cost</td>" +
1 u1 ]5 B" L6 w0 U' ? "<td>Quantity</td>" +
9 F& i9 U$ I+ V4 G Y2 W "</tr>"; : C8 B8 ~/ g9 J$ C
+ R* \! z) X5 p$ q+ W8 w/ \5 Q// Iterate over the BOM Items. u- y% H8 q7 _7 j
for (i=0; i<count; ++i) ; k ]/ m* U" l6 |
{
' ^5 D! h2 |; h3 t// Get a handle to the relationship Item by index.
5 ]5 L5 P, Z1 y8 f8 c" m3 I; R Item bom = bomItems.getItemByIndex(i);
" \( E9 t" p: p/ U# w) P// Get a handle to the related Item for this relationship Item. ! d1 w- U8 a3 A+ M$ i4 J& M! I
Item bomPart = bom.getRelatedItem(); : A6 s( X" m4 ~
2 Q6 a' e8 M1 R6 ]% ]; J2 g7 t
content += "" + ' V1 H O$ b K6 v7 [8 `8 }! z
"<tr>" + 0 G C! g8 N+ o! e7 H
"<td>" + bomPart.getProperty("item_number") + "</td>" +
* p1 C# w. D: r/ T' x& x. p "<td>" + bomPart.getProperty("description") + "</td>" +
) P, X/ s$ `/ s* e% n8 k! H. v "<td>" + bomPart.getProperty("cost") + "</td>" + , c) G6 k$ x8 m" a; ?" V }
"<td>" + bom.getProperty("quantity") + "</td>" + % l0 z/ b) _+ B) p
"</tr>"; 3 ^) k( A8 y! l
} 5 H5 p. a$ J. P; H0 e
content += "</table>";
( g, ?, @7 ^/ P/ q, d8 A ' E% f0 ~1 Z/ `8 O' B; T
return innovator.newResult(content);
1 s) r' y/ V& \ _
/ L3 Q: a, {8 |! \: |
7 H7 H' a% ~9 @3 K; J. e8 F5 P% ] c: |% M) h/ w' R+ [
8 ?5 Q; S9 L, d( z R8 P' z( @$ j* R2 r- W! h! |
( [7 T$ d, b% G% ^
5 q( `+ z5 j* s Page 46
$ V% C2 @% L- O+ Q9 K # J; ^$ ?+ L8 f5 H" O
Copyright 2007 + y0 f: k, A! ^" _
Aras Corporation.
% J' k8 g4 P3 n$ \& D% s yAll Rights Reserved. + e% ~" o8 M: Q5 J
VB.Net
$ F3 W7 S$ K6 o7 t2 m4 d- d' rDim innovator As Innovator = Me.newInnovator()
, q5 m1 ^& t" {% Q . a; O# w8 H: j1 H. K! n' |
' Set up the query Item. $ N$ W8 q4 o3 t6 u+ u) v( y) W
Dim qryItem As Item = Me.newItem("Part","get")
: H1 x" a2 [: m1 Z/ k9 Y {qryItem.setAttribute("select","item_number,description,cost")
. d: @1 Y/ z4 T. `: `( VqryItem.setID(myId) 2 v! q9 G0 w% m' B- j2 m3 y( Y
$ W' t- v* k0 h4 a' Add the BOM structure. - U: D) H8 e! f9 b: b! ]
Dim bomItem As Item = Me.newItem("Part BOM","get") 8 A8 g6 e3 S& ?* u8 p, s
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
$ C* _$ |, Y( a+ D. X1 BqryItem.addRelationship(bomItem)
/ V# V+ k5 |9 P' D6 S" y& w$ a, @* ?. t 2 R3 }3 x3 F5 V2 W$ n: Q& A5 S/ W
' Perform the query. , @% q _. Q! V" A6 w$ L5 m* D0 e& J
Dim results As Item = qryItem.apply() , m4 Y4 D( T" O2 O
4 @; m' \) j. p8 x
' Test for an error. . Q, c, S( a, C9 V" [3 f3 W
If results.isError() Then
0 b/ {+ c6 Y# Q0 ] Return innovator.newError(results.getErrorDetail()) . z3 J/ w$ d: u2 Z; V3 w& \# Q
End If
' G( _9 I9 u0 O% a6 E % Q% A" ?) `2 c# k5 K
' Get a handle to the BOM Items. & Q- o" G3 w0 f2 [
Dim bomItems As Item = results.getRelationships() 9 \# W% l" i4 T! F1 D2 m: I/ K
Dim count As Integer = bomItems.getItemCount()
6 }7 r- V8 Y# z( D, tDim i As Integer # r' V/ O# y5 N$ j- C
0 ^: T `2 G; P' Create the results content. % @5 l& u( C2 Y2 S5 e! `
Dim content As String = "<table border='1'>" + _ 6 a+ z: f8 d: E4 E, M3 t5 W8 l
"<tr>" + _ ' h3 M/ z' B8 O F5 ]' _
"<td>Part Number</td>" + _
# B" M" J" k4 \: v "<td>Description</td>" + _
% D3 y; v! @) @) N/ d ] "<td>Cost</td>" + _ + w: c5 c# P6 e3 m. N7 O9 X2 B0 q
"<td>Quantity</td>" + _ , O f$ ] M8 ]* C9 y0 u% M" Q9 U
"</tr>" ' R5 f# z/ w/ G: \
; y6 Z. \3 u& a$ c8 d: u' Iterate over the BOM Items 9 W4 }6 u8 ]# a
For i = 0 To count - 1 0 F Z# }# W, d
' Get a handle to the relationship Item by index.
+ l- }1 Z! g1 r# [ Dim bom As Item = bomItems.getItemByIndex(i)
! K" g0 k/ I8 K# v3 T* k2 B' ~
0 o' w }% L- n) s' Get a handle to the related Item for this relationship Item. 1 m) Z+ l6 P5 v0 g
Dim bomPart As Item = bom.getRelatedItem()
' q2 y. p6 ?+ I 9 `# d9 D1 Y- ^
content += _ 9 C9 d$ a9 E% C2 {
"<tr>" + _ " ?- U0 H( I' ^/ N) j) k+ V$ b, C
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
4 G5 G5 t6 P9 a6 P$ M8 ?1 I "<td>" + bomPart.getProperty("description") + "</td>" + _
- p/ X5 f, Z8 U/ Z& Z2 [- p$ r "<td>" + bomPart.getProperty("cost") + "</td>" + _
4 C' {4 F# c" {$ e8 i. t "<td>" + bom.getProperty("quantity") + "</td>" + _ j/ R6 K" W% |% U
"</tr>" ; s4 ]1 I0 f f7 d. Z0 C/ b: n0 e
Next # b8 u+ ]( k8 E; _5 P
content += "</table>"
% K f7 ^+ C4 \
* @0 V' d$ M1 ]$ ]5 Q' cReturn innovator.newResult(content)
# X: m' n( h- x( Q; A" _* J; H- F; p- Y3 j( I7 k" y7 E; X! y9 Y3 B
|
|