|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ; ^7 J+ C: M- T8 V, M
To query for an Item and retrieve its structure you build the query as the structure
?7 g' d) Q9 d, p0 ~2 c6 Uyou want returned. Use the IOM methods to add the relationships you want and 6 j# E, o1 Z$ \# z
build the structure in the Item. The server will return the structure that follows the
; b7 ]- u4 R8 g0 Z1 f# c V! Frequest structure. 9 W4 [6 ]& n5 J/ P6 o/ m6 f2 X+ e- ~
This recipe illustrates several related concepts together, which are how to get a set
. ~5 F q, D. @& G& fof Items from an Item and how to iterate over the set, plus how to get the related " N/ { q+ t7 H1 O3 s b
Item from the relationship Item.
% n* I, c3 U$ |- @JavaScript
6 `( F9 x6 V# Y3 v# f7 ~var innovator = this.newInnovator();
9 E# s: G/ H' @$ z9 q3 R4 V& E * s, J6 l! W% \: q+ p
// Set up the query Item. \9 `8 |1 }' J. O; G
var qryItem = this.newItem("Part","get");
- O8 v' \ ~+ v# ~. h- kqryItem.setAttribute("select","item_number,description,cost"); 0 h {4 d& X5 |% L- _" m; H
qryItem.setID(myId);
" ]6 \) _0 F m + _4 m, ~# d. x+ Q6 ^
// Add the BOM structure.
; i1 i6 d m x* Rvar bomItem = this.newItem("Part BOM","get");
( {0 Q$ n3 R3 D9 hbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ; R/ F4 J. i/ g# E+ u/ Q/ Q# Z
qryItem.addRelationship(bomItem);
" G; E$ y, s: @ w
& E; O7 P5 k( J6 ?) N& M/ U& y// Perform the query.
3 O% j" L- N$ C* Rvar results = qryItem.apply();
# b) m {5 y2 f) S2 F( ~/ Q v* y
) [, h( D' J# P( v# \// Test for an error. $ b9 T; _( c. r' w
if (results.isError()) { * d: o- ^4 Z, b9 C" l
top.aras.AlertError("Item not found: " + results.getErrorDetail());
# \0 i8 h1 S- @$ _# J return; * v& u4 j+ L& F! S9 y
} d( b ~! b. L e3 t# S
+ O$ g( G4 {6 G9 A% W
// Get a handle to the BOM Items. ' A: l; j3 ~6 H1 F% U w5 N" I
var bomItems = results.getRelationships(); 8 g1 X$ F) P& z4 R9 c: p
var count = bomItems.getItemCount();
) x# S0 i5 I- R0 Q$ O 8 g) I" i2 U( k; n
// Create the results content. 8 I l+ |! N) U0 \
var content = "<table border='1'>" + * H, T; g! D2 Z+ L' `0 u
"<tr>" +
7 e9 R) G1 _, ^: \- q! Z! X4 y "<td>Part Number</td>" +
6 {8 @( X- o; T/ a$ f+ ] "<td>Description</td>" + 2 c1 M9 e& J2 l- b# l
"<td>Cost</td>" +
) h f% i" H) A9 B& F8 G# G "<td>Quantity</td>" +
) _8 U( g6 V, C; n7 A! E "</tr>"; 3 Y. R! k2 ~ `% ?* R0 g+ b2 U
* F& r" s$ Y3 A- {, e; X// Iterate over the BOM Items. & U. w, X N9 Q5 ]+ D& n3 [5 B: ?
for (var i=0; i<count; ++i)
/ {& C ]8 C$ @2 N- z; s: o8 W{ 4 l, b3 I f4 I
// Get a handle to the relationship Item by index.
9 d- W( d+ W- P. ] @" v var bom = bomItems.getItemByIndex(i); r/ W! j- w5 e* H' V
// Get a handle to the related Item for this relationship Item.
6 N5 n" j, ^3 L var bomPart = bom.getRelatedItem(); ! r# j6 C+ f0 \' D5 N$ C5 u
( `, t7 S6 H7 Z, R5 b; ] content += "<tr>" + : X& `. a3 Y" x& \0 {
"<td>" + bomPart.getProperty("item_number") + "</td>" + . @8 x' P8 j6 f( d: ?
"<td>" + bomPart.getProperty("description") + "</td>" + & j# p% s( y, X2 F5 }7 w
"<td>" + bomPart.getProperty("cost") + "</td>" +
) j: H. w$ `$ h1 x$ N/ T "<td>" + bom.getProperty("quantity") + "</td>" + / ^4 E" G' b" r3 Q. f n
"</tr>";
7 ~9 c8 L/ ^4 n% G5 \9 r9 ?}
8 y! D# d* e8 O5 K/ K" Vreturn content + "</table>";- J" ?; Q% k* a8 ~7 i( }
4 z8 |. T' T" V8 F( r4 l' `2 Z
# V' y6 T$ {; {# G6 |+ J. s: q: C9 m0 @1 x$ H x' x4 |# P
* W) k2 T& g5 K4 N7 Y0 ?; tC# % x4 F# |* M7 {0 ?; g& @6 s% E' a
Innovator innovator = this.newInnovator(); 4 a/ W* H; i/ V( {! f
) z5 k! S+ r" K& u) l- x
// Set up the query Item. 7 ]9 x G0 h" A5 v- ^0 W
Item qryItem = this.newItem("Part","get"); - m' ^6 N# [9 D6 \+ E e `
qryItem.setAttribute("select","item_number,description,cost");
$ W3 s2 k; j* O# kqryItem.setID(myId); & ?5 o% f: j2 h; S4 O: f2 R& l
, R' t$ ]0 n% K3 Q6 G+ i1 @! ]3 E// Add the BOM structure.
% ? y7 h& C4 T a; L- k$ cItem bomItem = this.newItem("Part BOM","get"); 3 P8 x8 {/ E& L+ Z$ d
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 2 P2 O, D j2 a0 B- L
qryItem.addRelationship(bomItem); t8 |! b/ |- o
8 b9 P( g( Y" V, T( g// Perform the query. 5 u# A$ s+ F" M3 t7 g
Item results = qryItem.apply(); ! U6 I, }1 Q3 k0 b% J% Z9 m/ h
+ o) s9 c- g+ K5 Q1 c6 V ]9 P& U
// Test for an error.
. L4 o- I6 {! {: b4 G2 X Xif (results.isError()) {
9 ~, t- Z! F7 }: F3 u return innovator.newError("Item not found: " + results.getErrorDetail());
8 B2 h6 v1 f6 m6 f0 ^7 y ~}
: L' W, l7 T- O5 W0 A6 w$ i
& v( B( R6 q- v _// Get a handle to the BOM Items.
( N. t. L/ n5 h: [Item bomItems = results.getRelationships(); 4 J. u* O% ]7 w* Z8 K/ }" a
int count = bomItems.getItemCount();
/ {" | `1 A3 I6 ^int i;
' C: E1 \) H, G
- M/ ]) n- ^0 v: e' l ` F3 [; g d// Create the results content.
6 c* Q$ ?9 [8 d6 J* U$ Rstring content = "<table border='1'>" +
/ ^9 K: R5 N6 J% h3 P# V "<tr>" +
1 P( h( Y+ E! t7 X "<td>Part Number</td>" +
3 G; R* J1 D2 v# E: D "<td>Description</td>" +
. y$ g A; Y: y$ [ "<td>Cost</td>" + . ?! r$ a: f# [) b9 q! c) U* \
"<td>Quantity</td>" + ! N* C5 k- S0 z0 ?3 L1 V
"</tr>";
* P7 ]6 D8 W3 V
7 ]( F! |2 R- P: \2 h// Iterate over the BOM Items.
) k+ \. g" U9 \for (i=0; i<count; ++i)
6 m! t/ |2 Y9 J( u! @: k; @+ U{ ; A0 D& {' t! B$ ?6 d
// Get a handle to the relationship Item by index. 5 n& Z! i# Y f# ]7 X; U
Item bom = bomItems.getItemByIndex(i);
0 I) a1 U) s3 P. i F// Get a handle to the related Item for this relationship Item. ; j, V' [4 [2 Y9 O
Item bomPart = bom.getRelatedItem(); * V9 l5 @' G' c
$ K- |( b1 ^. M& X
content += "" + ) Q4 G! R& W ^/ @
"<tr>" + / U8 g: Q+ W+ {
"<td>" + bomPart.getProperty("item_number") + "</td>" + 5 a1 C; A S& |" i A; U
"<td>" + bomPart.getProperty("description") + "</td>" + : U' @2 l$ a2 Q" ?( l8 x
"<td>" + bomPart.getProperty("cost") + "</td>" +
! D+ n5 R( M: J+ [# f "<td>" + bom.getProperty("quantity") + "</td>" +
' t a1 s5 z: h% Y' V "</tr>";
, D2 y% ~/ R* `6 b}
; e9 N; B+ ?# Wcontent += "</table>"; 7 K4 Q3 {9 y: i& ^$ v5 i; }
& D3 s& ~* N% w$ v! Sreturn innovator.newResult(content);
) W$ F' E+ \3 r" z# l4 M* _. ^
, Z4 p8 g4 h. @. C$ K- _5 [0 H Z8 z
& K3 @: | j7 S% v. ?
* L3 ~2 f3 A; e/ v: W- I
- v+ {/ T! l% A7 L$ P
R+ ] L# W( B' {9 r2 }
( b; Z7 g/ d, ?
* G* a5 I, ?* q: y Page 46
% v0 P J6 p; J( ~2 p9 f 4 q5 _+ e) S# j6 {
Copyright 2007
+ K6 T1 r/ Z% k4 MAras Corporation. 6 E, N* Y# Y9 L: S# D" ~" T$ u
All Rights Reserved.
+ s7 [* k& J h- _6 l3 I: e/ UVB.Net
H: _0 y: E6 W. xDim innovator As Innovator = Me.newInnovator()
[$ L4 ]3 ^ h- k0 ^: j $ l2 [* X! I4 a u. C& [+ N
' Set up the query Item.
* n* f0 \$ {& N: Z8 x0 HDim qryItem As Item = Me.newItem("Part","get") : x9 y# n" K5 @6 b5 F# W/ W) @0 t0 {6 u
qryItem.setAttribute("select","item_number,description,cost") ( f* f9 M) o3 s x/ |" t5 U
qryItem.setID(myId) # k6 X6 A9 j4 ~) i
; m$ x$ x& q9 G1 F) @
' Add the BOM structure. ( k5 z$ _; d; g) J L0 U
Dim bomItem As Item = Me.newItem("Part BOM","get")
( C% L& a" V B2 Q# n) }bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") : M, {6 Y* i+ [. k( y/ W$ b1 r
qryItem.addRelationship(bomItem)
% K4 d1 a& s; G' ~
5 i# g4 b; q6 Y* R' Perform the query.
3 X$ Z3 {& C, z k/ g h, oDim results As Item = qryItem.apply() 3 K i' c9 U8 L: K) k0 h1 P* _) g K
; ~3 U( M+ ]& _7 k1 w' W' Test for an error. - }8 D. X+ X* H, t6 x& Q' B1 ^
If results.isError() Then
& c5 V; c- y* K% j; p7 u; b Return innovator.newError(results.getErrorDetail()) * `4 [$ W& T! ]" R) b8 S
End If
8 K" F4 j3 [ I% @% y c 9 y& t7 e. N, ~: U$ R6 l, P
' Get a handle to the BOM Items. + x; W- F. u0 a; I: Z/ ]
Dim bomItems As Item = results.getRelationships()
' N9 d' h1 N% W& T$ F% v$ s% IDim count As Integer = bomItems.getItemCount()
: S# [" X- v( M2 h) dDim i As Integer
0 J* L1 g7 Q+ G1 ~! V* I `$ ~, i: a' o
' Create the results content.
$ ?- I$ g3 D% \/ E8 \; L, hDim content As String = "<table border='1'>" + _
" I# F& z F0 i: m1 c$ m "<tr>" + _ ; e# [5 r% D" m7 j
"<td>Part Number</td>" + _ " a: U: F0 E' o- M1 _) C
"<td>Description</td>" + _
+ G. C9 t2 B: Q8 f4 V( q "<td>Cost</td>" + _ ; f. E. a0 I" A1 ~8 c
"<td>Quantity</td>" + _
, A. C. c3 ^, z* Y0 O) T6 ]) F "</tr>" 8 S/ U6 V( z4 f4 l7 {
0 W- U4 P1 x7 @. U' Iterate over the BOM Items 7 ~" A7 z4 `* n! M- h1 Q# o
For i = 0 To count - 1
, C! Z, a5 x o& x d& q$ x0 W3 i' Get a handle to the relationship Item by index. , Q/ ?0 k, ~2 Z- ?8 _" Q
Dim bom As Item = bomItems.getItemByIndex(i) 7 I) Z- h$ x( x; x: g( [
B" j6 Y& G0 e# L4 K! ^! S, Q; L' Get a handle to the related Item for this relationship Item. 1 M) N. g+ b, A S [
Dim bomPart As Item = bom.getRelatedItem() ! n+ l8 _* J/ s, O
" D& Q4 @3 J6 C2 k- ^* A& z content += _ ! o) N$ Q- S5 u) M1 g! \/ h3 t# i
"<tr>" + _
0 P4 W$ i& R: i8 C% N7 v" _ "<td>" + bomPart.getProperty("item_number") + "</td>" + _
0 ~! N4 [ B* t. ^5 Q6 A* n" _ "<td>" + bomPart.getProperty("description") + "</td>" + _
# O, F# d, }6 F; d+ } "<td>" + bomPart.getProperty("cost") + "</td>" + _
% l2 g, D) f' _; a! T0 i0 G "<td>" + bom.getProperty("quantity") + "</td>" + _ ' ~8 V) S8 f; F2 U
"</tr>" 0 {# t9 O6 b0 j" p, T
Next
" n3 C$ ^; S3 {3 s# Ncontent += "</table>" $ p, u& k. n6 Z2 P! ~6 d% N5 ?
* d) S! ]7 ]6 h+ q ^2 Y& u: J
Return innovator.newResult(content)
4 q; w3 n! s8 I# @
/ D) [$ T2 s8 e& l* t/ H* T |
|