|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
9 j0 g3 t1 U7 V3 I6 _3 VTo query for an Item and retrieve its structure you build the query as the structure
( G& f# W5 u; X" S6 O: R6 y+ syou want returned. Use the IOM methods to add the relationships you want and
$ O% i8 b: z1 Gbuild the structure in the Item. The server will return the structure that follows the 9 r3 t: ~* B m; k# K* E( ?
request structure.
% U G( v8 x2 r# QThis recipe illustrates several related concepts together, which are how to get a set
# }+ m) q- l$ f, q; R2 F1 l: u% sof Items from an Item and how to iterate over the set, plus how to get the related . c0 P! i# e" p0 K9 n* m" l
Item from the relationship Item. ' U" o$ E: c% l/ U; R: N
JavaScript
0 r4 S6 _ X& t7 ?; C; {var innovator = this.newInnovator();
1 F! {& F# E1 P) I4 L3 L 8 M1 b6 C+ v) `. D% l5 ^% Q
// Set up the query Item.
. G6 C# A! o8 ]1 r4 p8 G6 Vvar qryItem = this.newItem("Part","get"); % c3 q0 {, N. }$ ?
qryItem.setAttribute("select","item_number,description,cost"); 4 G/ O8 @' Y7 ^- [
qryItem.setID(myId);
n5 ?1 w7 K8 B) ^! ]
) H, M3 ], C9 I% _, v: M& E2 r; w3 n// Add the BOM structure.
; J( f. m; ?4 \1 p3 H) l) D$ I5 Svar bomItem = this.newItem("Part BOM","get"); 7 M5 K& L( n4 {
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
7 b N8 C3 G2 U% h8 i* W3 ^qryItem.addRelationship(bomItem); 9 R; Z( L6 y% U6 U/ T# N
' q$ m# d( g% A) |// Perform the query. / K5 m; A0 n K4 c' L( B
var results = qryItem.apply();
% Z# G4 n3 r2 u
# _- o$ R1 m+ [. v' U n; n// Test for an error. * F3 L6 T5 h$ @" h
if (results.isError()) { , m+ y9 Y! E. U" j2 O- o' h5 i
top.aras.AlertError("Item not found: " + results.getErrorDetail());
- O* f- u1 E3 ^ return; 2 K& p% F( [3 j6 R. D" t
} ; x! u/ S9 ^8 q( o; b; t
4 h4 a. C3 b* I9 H$ m, W
// Get a handle to the BOM Items. $ b; ~# O( ]9 p( ^0 A- {9 p7 S0 N8 `
var bomItems = results.getRelationships(); ; x6 t3 _2 l9 s8 P' t
var count = bomItems.getItemCount(); 6 I2 D( F# X5 F; e; U- ]
5 y1 d* I9 n$ I* g, K) F" q3 v* V
// Create the results content.
1 P" O; c/ L2 Kvar content = "<table border='1'>" + ) _' L4 J6 `) b, F& [
"<tr>" + ( g1 @1 k; T) O j2 b1 O( J1 L6 w
"<td>Part Number</td>" +
7 {* x s' A4 i" j- O, m; o9 m "<td>Description</td>" +
. N$ [7 Y- ^$ K "<td>Cost</td>" + ' F) Z0 P) q: V* l9 H d
"<td>Quantity</td>" + / W5 c5 v% l( X
"</tr>"; ; q- ?0 K- ~+ ~) q, N w! J) x
# d& p6 U# }% |8 h* {) _
// Iterate over the BOM Items.
) m7 P" Q4 @% c" S" s& hfor (var i=0; i<count; ++i)
a$ k) c0 g2 y Q6 p{
- H5 R1 [2 Q2 q+ V// Get a handle to the relationship Item by index. 8 g2 v/ D& q2 B$ {7 j1 Z
var bom = bomItems.getItemByIndex(i);
; S! E& s/ F4 Y1 f// Get a handle to the related Item for this relationship Item.
' e, X9 i! w; ]0 e) n var bomPart = bom.getRelatedItem();
( H7 t) H8 N3 e 7 p1 _5 O2 ^: l! \+ d3 F; F J
content += "<tr>" + 2 r: C% q) V6 o+ I
"<td>" + bomPart.getProperty("item_number") + "</td>" + : h* g3 i8 l) u+ \3 n8 c
"<td>" + bomPart.getProperty("description") + "</td>" +
( r8 C6 ~* M* F# t. f% W7 j# N "<td>" + bomPart.getProperty("cost") + "</td>" +
" v( [% F% Y% c9 n0 b! S& j$ _# p) a "<td>" + bom.getProperty("quantity") + "</td>" +
' g8 }. W' w8 ^0 z "</tr>"; / h. ]* W$ V' r) D! {
} 6 [, G+ y/ u9 r2 q3 N5 e: Z" ^
return content + "</table>";) t1 y q- r8 W% r9 T
, C, w N9 ?; ]# D0 V" [
+ ? ~2 J4 f3 U# M/ S9 ` ~: J
1 k* H6 J0 q+ H2 {" fC#
- N! b& h6 O( X+ @8 cInnovator innovator = this.newInnovator(); 2 q' O4 t$ w, u( Y I1 h# c$ F
% {: U- R P# c# C3 p8 i1 m* S// Set up the query Item. 2 R4 i9 ?: j" @& S; s, R
Item qryItem = this.newItem("Part","get");
0 b$ y9 Y% b- _- F# iqryItem.setAttribute("select","item_number,description,cost");
. y& n u# {# l2 K) r3 X eqryItem.setID(myId);
0 `: w. p1 T2 W# N, D, ] 1 l" T8 y) u0 T5 e9 k
// Add the BOM structure.
6 N: B) d* n! f6 r1 TItem bomItem = this.newItem("Part BOM","get");
, e3 Z' B4 S; |bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); " C, W1 K0 ~; i- n$ \8 a
qryItem.addRelationship(bomItem); / f. e5 w7 H% j9 F& l2 S
9 \4 i1 z! C# ]* F6 t" Y, h// Perform the query. / `) G Y! _! c/ I; A2 J+ Z
Item results = qryItem.apply(); . B0 v: X7 ]: v8 J
% `6 {3 D/ V& z0 p# C- u
// Test for an error.
/ I; ?' M. i7 e! A2 Uif (results.isError()) { 4 X. R% ^: X) ?# S
return innovator.newError("Item not found: " + results.getErrorDetail());
o6 F& h. e( X8 D3 D; W+ d4 H} / }' A; u8 }% T2 m' |/ {/ a
1 L4 d* ^5 }9 B |# F9 H0 l
// Get a handle to the BOM Items.
% @/ Z0 u: O6 Z% LItem bomItems = results.getRelationships();
) v( j1 O8 O# Bint count = bomItems.getItemCount();
- p4 q: o* M) p" a4 Rint i;
' \1 D9 o3 i# F! S5 |6 Q+ J ; G% u9 i/ b: S6 j% s Z- o" I+ p- `
// Create the results content.
& N9 o5 B0 d* istring content = "<table border='1'>" +
& p' |* A" N# [ "<tr>" + # E3 p! R& c G( _5 e. m+ H
"<td>Part Number</td>" +
+ H# j/ K0 c/ ^3 u& Y/ G "<td>Description</td>" + : [- w& O8 k: x8 `7 V3 E2 @( \2 _
"<td>Cost</td>" + ( N O, n% G* g
"<td>Quantity</td>" +
2 M, ^" z$ z2 y! P) g( F2 \ "</tr>";
- N3 ~4 B2 {$ l' Y: D6 k: ? j 3 Y1 ~+ w: E2 o& M7 c& s
// Iterate over the BOM Items. s. C& I* u1 L
for (i=0; i<count; ++i) 8 j* Y5 ?& m) K2 |4 c
{ ; Q( Z# R# X0 d
// Get a handle to the relationship Item by index. h- F. r% j+ c5 X0 P9 K8 w/ G
Item bom = bomItems.getItemByIndex(i);
0 F( H! S9 J3 d y- w% P// Get a handle to the related Item for this relationship Item.
6 G. J% C4 F* k0 O2 J Item bomPart = bom.getRelatedItem();
/ o! p4 ?* V& U# s - y6 h% D& V* K$ f! P3 V# W
content += "" + 6 q$ T0 R/ c+ i, v" e' D2 c7 I
"<tr>" +
8 _) n% k" F* @4 \7 s, b "<td>" + bomPart.getProperty("item_number") + "</td>" +
6 {, E" T+ g9 \. f( r& z+ W6 E "<td>" + bomPart.getProperty("description") + "</td>" +
$ V- n$ U& d7 f- N+ E( [3 j. y "<td>" + bomPart.getProperty("cost") + "</td>" +
9 m# j$ ?& a( |3 q) G! q "<td>" + bom.getProperty("quantity") + "</td>" + . P/ E4 S% s u0 X: ^- N0 {! z' K
"</tr>";
5 b. d% `2 r/ c% G}
" V! {3 f5 t9 ~. N( U8 M1 e9 Pcontent += "</table>";
9 E" N" l! a9 @+ L9 a3 m7 n
7 k X8 Z( `$ N- s+ w! u4 Creturn innovator.newResult(content); ; o4 A0 ?7 y& W' D6 @* f9 ]- {
: a: t. s. \& a* ^) P o# A
3 M7 w8 q/ U0 F
& g. H& K, X* |: \& b( ~" K+ e( s; x& `+ V) j: K
3 Q; C+ X+ x9 J* v7 y
4 s: S, P! c1 @/ T" v3 H
- b6 f3 D* A1 @; p! ^ Page 46
: \, a) l: k/ c& j+ e
9 f1 D; C. f, qCopyright 2007 ! y: L- Y; Z/ |. ^- P# s8 x
Aras Corporation. ^- i3 |# l! [8 _5 @
All Rights Reserved.
5 w& P& q3 X3 |5 I0 J1 PVB.Net ) g! \' ~% k3 q8 ^+ M( z; G5 V
Dim innovator As Innovator = Me.newInnovator() ' d- b' Q* d. `) W6 P
$ b7 o3 @/ E d+ `
' Set up the query Item.
. W; q" o$ |3 X4 d6 EDim qryItem As Item = Me.newItem("Part","get")
8 d5 u" ?. E, Q3 e; n. `& [qryItem.setAttribute("select","item_number,description,cost")
+ l) s! T9 S% c6 n3 y. |qryItem.setID(myId)
1 b J: s$ f* I2 }; G 8 Q& j! Q2 g F) G# P. w
' Add the BOM structure.
( _* M8 ] G @ u G3 `( H2 MDim bomItem As Item = Me.newItem("Part BOM","get") " g* k9 D5 y' ]# M
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
# l/ ]0 ~4 ^: H0 dqryItem.addRelationship(bomItem) * R* V. q$ K+ l! I( v- y7 ~( O* l- i3 X
2 b+ Y8 c3 i' f9 E1 n' Perform the query.
l- O! }2 {- i, j% {! mDim results As Item = qryItem.apply() 6 ] K6 \( y0 t# H) S
+ m! G8 I, D# d$ @$ h; {6 x' Test for an error. , w. |: b* p. f4 |/ f
If results.isError() Then ! q) d$ S$ E, Y, d0 b. s# W+ C
Return innovator.newError(results.getErrorDetail()) 1 I, a0 x, l* [9 r: i6 R; H
End If
/ t% S- f* x6 N4 @9 R; [! x3 i ' ~6 I6 g& q& g& T3 o8 H
' Get a handle to the BOM Items. % ?0 L3 W1 [! q6 e3 {. M- f+ O! M
Dim bomItems As Item = results.getRelationships() 6 {: W9 L3 s. [ G4 n' ]/ Y; S
Dim count As Integer = bomItems.getItemCount()
- H- _* P! a8 bDim i As Integer
, J |' T3 E. `1 | N7 E9 P/ \- {
' Create the results content. 2 g/ ` K. p6 T1 b9 V
Dim content As String = "<table border='1'>" + _ ; d" C% j( I: Y- N% b+ b5 C
"<tr>" + _
& Y5 q. C; Q) X9 a" J "<td>Part Number</td>" + _
& z% ^6 @; p- _% l0 g "<td>Description</td>" + _
# q' v9 P9 `6 J* g G& p4 r "<td>Cost</td>" + _
0 {: o- q3 v* ?5 O. d "<td>Quantity</td>" + _
! D$ f. K( [9 w! ~6 e/ ` "</tr>" ; ]' X, e7 o! M( [6 F
3 W9 ^1 J+ t2 @/ c1 I
' Iterate over the BOM Items
) ?3 c6 L% }$ f/ C; pFor i = 0 To count - 1 + @- R# w x' k
' Get a handle to the relationship Item by index. 1 z1 b8 N! M0 D: l
Dim bom As Item = bomItems.getItemByIndex(i) 1 ]4 g% U$ T% X% e
- k0 C9 _1 F$ u8 @# p: U1 E; Q
' Get a handle to the related Item for this relationship Item.
5 c# p0 y) E e7 l9 F" H# V$ ` Dim bomPart As Item = bom.getRelatedItem() ; \; X. i* x- A8 Y* _# x; ~7 [
9 @; k r6 U( _* }+ m7 n
content += _ * d2 I# }0 F+ _: n; a
"<tr>" + _ ( I9 f, Q7 J8 X3 U6 k' U w
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
+ i4 o8 L9 _6 g "<td>" + bomPart.getProperty("description") + "</td>" + _ 9 q6 f" i1 P5 U1 g$ J# _; l- ~0 e @" ?
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ( w4 W, {7 C" N# u0 I
"<td>" + bom.getProperty("quantity") + "</td>" + _ 8 _; G( K* W5 ]& t
"</tr>" * R. R- t4 z9 L x( ?& f( J5 u. J* z
Next
5 v5 {% J- k; J' ]. q+ h4 \/ c/ Kcontent += "</table>" 3 I+ N- ?* U& |3 c+ F: }9 M
9 Q1 C" A/ V7 U
Return innovator.newResult(content) " ~5 l! j& x1 M$ \3 g9 d* C6 O
6 ]! r9 e. z: R3 e$ h
|
|