|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
Technique 6 _0 S N( ]' u6 Y
To query for an Item and retrieve its structure you build the query as the structure . z4 e j2 e# f$ b/ c
you want returned. Use the IOM methods to add the relationships you want and ( [" U( P! u8 g7 s2 J
build the structure in the Item. The server will return the structure that follows the 3 D4 E3 p, Q# ]. V* p, |8 Q
request structure.
' y& `2 H9 w' Z. c2 QThis recipe illustrates several related concepts together, which are how to get a set & \8 ]: x. e1 }1 P$ W
of Items from an Item and how to iterate over the set, plus how to get the related & t) q# e9 A* z) j5 V8 h0 X4 t, M( o
Item from the relationship Item.
" u; o! P+ n8 [ a4 q# aJavaScript
$ M1 a9 B) V! C+ d& E$ Rvar innovator = this.newInnovator(); 0 V- E4 K- E4 {" l/ W0 A
1 n1 S1 ?& J8 K4 P b// Set up the query Item.
" \% @5 w5 j, h- c& Yvar qryItem = this.newItem("Part","get"); + q5 y% T, r0 P2 z$ d$ N0 n
qryItem.setAttribute("select","item_number,description,cost");
1 q, g! D0 R( y5 N9 \% wqryItem.setID(myId); 5 v4 c, b. O% z" ~
9 X1 Q x- n. G& T" O
// Add the BOM structure. 2 U+ f% y; q$ j- i5 }. B5 k- X, \
var bomItem = this.newItem("Part BOM","get"); / Q' C+ i3 D% M$ t
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 3 O* r: K0 U6 h Q% l" d$ T
qryItem.addRelationship(bomItem);
; ^+ j' Q3 I- B2 H3 P ; p8 O w. {' v% l; y
// Perform the query. % R# K3 J& e& m2 {* N
var results = qryItem.apply(); + f, b" q2 I5 L P( G
B5 D9 @4 `6 w5 ^
// Test for an error. ) w7 T) O4 q( E6 F. B
if (results.isError()) {
- [/ q; O1 _7 ^5 C$ `/ O# w0 k top.aras.AlertError("Item not found: " + results.getErrorDetail()); 7 c, V- Z; X& ]; c! Y( J7 _, H
return; ) L6 X7 e4 f& I. i& \2 |
}
\7 y, ^* T+ Y- w% i' e 7 N, \( S' _9 p
// Get a handle to the BOM Items. ) p" z7 M: k; W/ ?3 q% p) b
var bomItems = results.getRelationships(); 7 ], b0 f; M: ]
var count = bomItems.getItemCount(); 7 g9 V9 V: R) j+ o
# e2 s9 p2 |8 Z8 F, @
// Create the results content.
3 ^" P" ]6 x6 {) Qvar content = "<table border='1'>" +
" k5 l5 k- S; M+ Q' B- T8 Y, ^ "<tr>" + 1 C) d5 b1 }0 }! _2 L, j. w
"<td>Part Number</td>" +
+ R1 y$ h& L O# R- x1 _ y "<td>Description</td>" + ' [! B$ y7 t4 S. l3 B( y R
"<td>Cost</td>" +
; ?8 I/ `" @; L7 t9 e: F7 C "<td>Quantity</td>" + $ Q( ^: P. E4 b. L
"</tr>"; 9 c' w' \# T9 r- v7 U( i
+ S% r" T- s, K0 s8 E' {" F' C
// Iterate over the BOM Items. 3 ] u/ n6 E3 [9 u6 C
for (var i=0; i<count; ++i) 1 D2 X0 [3 e9 L$ P7 A8 p2 I
{
2 j( N5 l4 h+ ^+ M2 p+ J6 l// Get a handle to the relationship Item by index. & h2 `* X& y- l$ w9 } c
var bom = bomItems.getItemByIndex(i);
7 S: |; m( @1 t8 g% x// Get a handle to the related Item for this relationship Item.
& _3 v. H7 P$ C$ \4 A+ r* x" D; k var bomPart = bom.getRelatedItem(); ( M3 H( T$ V5 N$ A& f1 T1 t) d
8 s H. t+ M. }6 V7 x content += "<tr>" + 1 \! \ N2 E) d- Q- q! v' @- M
"<td>" + bomPart.getProperty("item_number") + "</td>" + # ?! K, P4 h$ V" o9 b, {* K/ O
"<td>" + bomPart.getProperty("description") + "</td>" + # A5 D q* \% h0 B/ r/ [- y$ m% s
"<td>" + bomPart.getProperty("cost") + "</td>" + " V: h- i. F1 S% {5 c' A0 R4 ?- w
"<td>" + bom.getProperty("quantity") + "</td>" +
- ]: c7 S, _) y: T1 j7 r5 l) j "</tr>";
6 _9 L* j/ a3 {( J9 Q. z$ C}
! R7 m& ?/ K+ O3 u% n9 n1 ~" Kreturn content + "</table>";. p/ V3 M; k: N! V+ i: W- q) Y! v
8 Q* N' C6 S8 ^' i
* r* Z2 Z: l! P7 j5 H
% Y5 }4 Z' a) [' q/ t5 m2 ]- k
# w6 N. _7 E5 q0 r* QC#
" d+ V& C/ L1 C R" U2 dInnovator innovator = this.newInnovator();
% l! c7 T* K6 w. ~+ Q+ J 3 ]$ R3 C1 c5 ?4 q
// Set up the query Item. 7 ^ I3 m0 t6 Y, c
Item qryItem = this.newItem("Part","get");
# a. c$ B5 G1 Y8 r+ VqryItem.setAttribute("select","item_number,description,cost");
% A" h' l- o# z" {: WqryItem.setID(myId);
. \' E: r8 C, b _$ r# ]! e
: p, @, z4 U9 @0 h// Add the BOM structure.
3 h$ m! k0 o2 t! ^0 U6 X( }Item bomItem = this.newItem("Part BOM","get");
7 a, \6 @; u l* C9 c" fbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
+ T# Z8 I/ v( d$ G8 U& N! r& d$ hqryItem.addRelationship(bomItem); , ^* z0 i* K* T
( M9 `$ M! a# \4 t+ ~
// Perform the query. 4 u# {( r$ g: a8 l
Item results = qryItem.apply(); ^6 q6 E0 m# {3 f/ V
* o# m* g8 Z. ]3 c2 I8 [7 B+ ]// Test for an error. / ]5 }, R9 m$ H
if (results.isError()) {
1 X8 B' d+ ]2 k- ?; ^* m return innovator.newError("Item not found: " + results.getErrorDetail());
0 L* {$ [1 x6 m# `7 u2 Z" p+ j} & m( E' _. X& f$ W" N8 [; o% c
+ F2 x0 d% ], F9 P( L$ v- J7 P0 t4 ^
// Get a handle to the BOM Items. 6 ~( x" g% k! K5 K# w
Item bomItems = results.getRelationships();
; Z* x$ g+ A8 s% Pint count = bomItems.getItemCount();
3 q9 w5 U0 j" Vint i; 3 G @) v3 R- J2 {
( s+ G$ u4 Z% i3 _* {1 \ p
// Create the results content.
1 C# t# k5 h7 @! B9 J, N, z* Astring content = "<table border='1'>" +
5 Y+ n! s1 ~& B "<tr>" + 9 K3 G, T/ B0 T: x8 ~3 w
"<td>Part Number</td>" + $ _. G" X7 v5 ~0 E
"<td>Description</td>" +
0 ?- t7 F, N- m! ~0 o "<td>Cost</td>" + & ^2 Z9 L- a9 N b2 U7 i) P
"<td>Quantity</td>" + 1 w' l+ L: b# k
"</tr>"; * |( p* E6 E* {; t9 g
2 q7 V% H, F! O3 J: v
// Iterate over the BOM Items.
3 f! Y) r. m* b: ]/ `8 H/ pfor (i=0; i<count; ++i) $ m3 N& N3 ?) H+ o) q2 i2 T& {
{
* F3 q- f6 R) u- h! ?) e+ X, W1 b// Get a handle to the relationship Item by index.
9 }5 x6 M. h- }( V& g0 } Item bom = bomItems.getItemByIndex(i); , v% _& G/ h/ P6 v& k1 f# w
// Get a handle to the related Item for this relationship Item. & q3 d8 ]! t: A/ x
Item bomPart = bom.getRelatedItem(); 1 @! a2 ?( D- C6 J) B
: }5 u7 ?" g5 g& d- y content += "" + 6 y6 V; j& a5 W* r, j# a
"<tr>" +
5 ?9 T& \0 P- o6 }$ J) I) A, e "<td>" + bomPart.getProperty("item_number") + "</td>" + ' x, S W" j1 b7 ~
"<td>" + bomPart.getProperty("description") + "</td>" +
* A% S* a- l4 }: Y- I) Y9 \; y) ?9 B. F "<td>" + bomPart.getProperty("cost") + "</td>" + 0 m7 x- U! o! u3 Y: J% s2 @) J4 ^
"<td>" + bom.getProperty("quantity") + "</td>" +
6 [3 ~" n) S! b "</tr>";
* {- E6 Q$ H7 Q}
$ _4 t6 x9 {7 a, K. I' ccontent += "</table>"; 5 O& D, w+ T9 w
0 }- l# H$ o7 d5 R6 _' Xreturn innovator.newResult(content);
1 o/ ~7 Y1 h; Z/ y+ y
0 _* t$ J7 N# L- h6 Q/ j
0 }; P3 e2 a$ P5 R9 h6 {+ T! c
* F/ O3 e/ l3 V" Q, f4 |, v$ V1 K- q2 V
3 \. u" V. j. q' \7 M- V' \: m) I
- P& i/ W. ]% b8 n! }8 Z8 r. F# d& z
( q% W2 O* d% f/ o Page 46 * m4 |0 N; q' K2 v- \8 b
. D1 P- ]) Z4 I: i0 t# E% S I- ~Copyright 2007 ; B& a0 `& K( ^3 r( r b
Aras Corporation.
1 H: `: R3 w4 S. {9 `( I/ K. d8 WAll Rights Reserved.
2 _: W7 G4 @: I4 ^; QVB.Net - {8 v4 e% E0 p! v, |9 g
Dim innovator As Innovator = Me.newInnovator()
3 N6 ?( b/ J' c# W8 Q1 w1 o , m" a& F3 F' W# h4 I
' Set up the query Item.
) k$ T q3 v' a R9 E- l- \Dim qryItem As Item = Me.newItem("Part","get") ! Y2 p$ ]4 Y/ a) d9 {4 v
qryItem.setAttribute("select","item_number,description,cost") : ~. X+ |$ ]( Z- I
qryItem.setID(myId)
- e+ _' q1 T5 C! R9 K
, ^% o. B* m& e, `1 M- {' Add the BOM structure. , D' a/ p- `" Z0 p
Dim bomItem As Item = Me.newItem("Part BOM","get")
- a% ?) k% q/ y9 hbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") X) U9 K( r7 A; U) p' X/ D; I! R6 s6 z
qryItem.addRelationship(bomItem)
7 O7 T7 m0 f; y% J3 s, x7 r" O 5 }6 G) K+ t& X' I
' Perform the query. 0 Z0 T3 T. j& r' W) {
Dim results As Item = qryItem.apply()
$ \2 H4 z8 K: F2 z' l/ m2 U7 R2 A
2 {! `- e1 V0 C5 p0 c' Test for an error. ! {, ^7 V4 |* s8 `. u k
If results.isError() Then ! R; o2 P% q9 r% D* S* U
Return innovator.newError(results.getErrorDetail())
7 ]8 h/ d5 Q+ k4 X3 t) H. jEnd If
5 B& o- }% \- a$ G& H a6 [) Z# \ Q: b q8 @
' Get a handle to the BOM Items. 7 v) J1 U: h4 z' }- o) F" \: I+ ]' c
Dim bomItems As Item = results.getRelationships() & ]& {# _: x9 i6 G" h- R( n/ _
Dim count As Integer = bomItems.getItemCount() # k, B* P" U) O- q6 Z# ~
Dim i As Integer & O0 U: ` {: R$ ]4 K
* V# ]( j& x3 @4 O' Create the results content.
! g2 c! b2 [8 {' [+ C9 R- s# iDim content As String = "<table border='1'>" + _ + l" }4 a7 ~$ ^* R4 J/ Q6 N3 D: v
"<tr>" + _ # f& _# Y$ B3 J& c% z, O+ f" y
"<td>Part Number</td>" + _ % A6 R$ _8 R+ }
"<td>Description</td>" + _ * I3 H2 h3 P/ z9 K/ @" X6 G
"<td>Cost</td>" + _
/ r) C0 H! w3 u' m1 R* N8 ~3 k "<td>Quantity</td>" + _ 8 R& w, s! w& `1 ~8 M- [3 I2 \
"</tr>" ; ^$ t$ ^- w9 ~( g8 V9 ?
% d/ ], f3 K m9 {. T+ v
' Iterate over the BOM Items ( |$ Q5 G3 j# E7 K' z: G" l7 F
For i = 0 To count - 1 6 C! X" f& n& L8 M' l9 G
' Get a handle to the relationship Item by index. 5 _/ `/ M2 q; [6 ~
Dim bom As Item = bomItems.getItemByIndex(i) # _6 A$ ^( o$ s* v/ G" Y
" r# l, c$ \4 ]. ?' Get a handle to the related Item for this relationship Item.
1 s' p1 ?3 @3 M. c" D( d Dim bomPart As Item = bom.getRelatedItem() . _9 Z0 L$ J! h0 I9 u
2 S3 J ?3 ?7 n# m
content += _ $ P7 ]* K+ h+ l7 F
"<tr>" + _
" S1 a$ r$ o5 r0 B* E& } "<td>" + bomPart.getProperty("item_number") + "</td>" + _ * I# v; s4 J* h" x: D3 g$ `
"<td>" + bomPart.getProperty("description") + "</td>" + _ 8 U1 z/ Z' R. c
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ( J" V# J! d. S, ~
"<td>" + bom.getProperty("quantity") + "</td>" + _
- F @; r& _. N1 ]) U3 ]% f) j "</tr>" 9 O" @9 T. G5 r. ]& n( p% h# @
Next
; I9 C0 Q, d8 k' N' q5 R7 H8 i' S5 K+ ccontent += "</table>"
) E* x4 w+ l0 c* V/ N. M/ l
3 x$ l' h( k. P" K; HReturn innovator.newResult(content)
, h- W/ Y( O# ]0 ~. F* A
0 _/ E, s% M6 I8 `4 R: |: {3 H" j7 z |
|