|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
/ _* y7 p: v3 u- c4 ^To query for an Item and retrieve its structure you build the query as the structure
4 ^$ _+ z8 s Uyou want returned. Use the IOM methods to add the relationships you want and 4 U% f' m6 z- t
build the structure in the Item. The server will return the structure that follows the " g9 @' @" ]: ?2 s4 W7 T
request structure.
; Y* Y( Z+ @$ w3 uThis recipe illustrates several related concepts together, which are how to get a set 0 @; T$ E2 @7 H' p5 H6 ^" B
of Items from an Item and how to iterate over the set, plus how to get the related
4 s/ W0 ^7 e; \6 ]" `Item from the relationship Item. - ^' a: u/ t1 H0 J7 X, v+ {1 ~8 |
JavaScript % N8 t! b% n3 Q* Y' O0 [
var innovator = this.newInnovator();
) O* N4 o) n9 A" u2 M/ N * o& q: r. @4 c0 F3 U# c4 T* G
// Set up the query Item.
* B, v; s6 z% {; k7 Qvar qryItem = this.newItem("Part","get");
& R2 H3 T; p% i( i3 JqryItem.setAttribute("select","item_number,description,cost"); * E: m2 D2 T1 P# G7 W; T
qryItem.setID(myId); & m/ Y- {5 l! |/ l. p( H) I' W' ?
; d" b2 x$ P, B// Add the BOM structure. 6 C" i: w/ x+ l1 D. W5 u
var bomItem = this.newItem("Part BOM","get"); Q0 g D/ n+ Z; \- r" o
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
; Q. M% x& a- l$ r+ B% {9 a \/ l! AqryItem.addRelationship(bomItem);
+ x/ S4 m0 }" o" M
( F5 m: j8 g" v! k// Perform the query.
/ J6 }, H2 d2 r; }6 p/ D5 Y3 Vvar results = qryItem.apply(); / t$ ]8 P- a2 E8 S' e8 L6 H
" D& d+ C& u! ~+ }// Test for an error. ; k2 f; u v/ i, j" t$ a$ w5 c/ @
if (results.isError()) {
" S& m+ n; e. a, v top.aras.AlertError("Item not found: " + results.getErrorDetail());
1 r; w5 q+ R9 Z, q Z u; c return;
6 U @ y) I" E! l9 E; L) o! K}
/ X3 Q0 K" C V! ^' q6 s' L# q' q& i % b- P& ~ B, S3 b% d- ~
// Get a handle to the BOM Items.
0 z- B7 U3 F' m; bvar bomItems = results.getRelationships(); 7 C$ A: Q" P T9 r, D
var count = bomItems.getItemCount();
7 a: a; e9 j' t- E2 P _- } , C5 g' w. [' ~
// Create the results content. ' L5 R2 a7 }" ]
var content = "<table border='1'>" + ; b6 ]5 D {% G
"<tr>" + 2 x, e4 B5 m# H: m9 A, h
"<td>Part Number</td>" +
5 h' H/ r7 n* I. e+ A3 X "<td>Description</td>" + 5 |* T0 g/ B6 H, {+ h, F
"<td>Cost</td>" + - o% V: n0 n( t6 u a6 u
"<td>Quantity</td>" + 8 K# r" ]: n7 Q" x4 ?
"</tr>"; 9 `+ S6 _. B9 N; s4 Z
/ w* c; R; q5 g4 z1 l
// Iterate over the BOM Items. 2 n. Q( S% X6 f% W4 r3 l
for (var i=0; i<count; ++i)
7 Z$ |- S' V0 U4 R{ 8 {9 A; `) W! ?) L7 D+ ~4 K/ [0 M4 H
// Get a handle to the relationship Item by index.
# l5 M+ S% ~. j. c0 T var bom = bomItems.getItemByIndex(i);
D& Q( L% Y6 U5 u* a// Get a handle to the related Item for this relationship Item. . P0 x c; T2 {: [/ }% j
var bomPart = bom.getRelatedItem(); " H7 x) J' g. Q' f1 u1 ^
w+ g& C. {/ {$ `) ]6 @ C; f
content += "<tr>" + 8 P" r! g2 y6 i: w+ f9 O U
"<td>" + bomPart.getProperty("item_number") + "</td>" +
* a n/ s' x+ H6 G3 l7 y* f9 e "<td>" + bomPart.getProperty("description") + "</td>" +
# U2 r9 e/ ^) d "<td>" + bomPart.getProperty("cost") + "</td>" +
/ E9 t( O# m T0 b; ]1 e "<td>" + bom.getProperty("quantity") + "</td>" + 0 x1 { a* [! h) B# z
"</tr>";
5 l# x* g% R" s}
% } J. F* D$ D/ e3 \return content + "</table>";
; V: X" O7 e$ ]% Z1 T" v3 g. I5 L0 F* ~0 A% u; z2 `
( Q" t$ T4 O, b( [5 W& ~* ^
4 W/ P, n6 ]" b I7 M2 q# ]7 z
( z W g) _( M0 iC#
1 s2 p5 ^. h3 V$ |8 c! Z, X, [3 u8 z7 PInnovator innovator = this.newInnovator(); ! ~' V$ E- w V
; i& U+ P4 x( x; T7 ~' ?4 |9 z* c// Set up the query Item. & Y3 [* d I W2 E) z" G. m6 j
Item qryItem = this.newItem("Part","get"); }$ ]2 I% p8 } ~
qryItem.setAttribute("select","item_number,description,cost"); : } V: \; b7 z' \% b* m) [
qryItem.setID(myId);
9 E. j" ]7 Q8 S2 [$ A! ?4 z: _
! }( B( j& E$ k/ K* R! m# G8 A- @0 Z1 a// Add the BOM structure.
! {, `: s/ @2 oItem bomItem = this.newItem("Part BOM","get");
, I. f& ^& R3 O) cbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ( r! S8 | a2 f0 K7 F
qryItem.addRelationship(bomItem); 3 s7 N4 F0 B( o& X# x7 M
' c4 T: P5 F2 b l
// Perform the query.
! v- a: o5 y0 Y8 TItem results = qryItem.apply(); $ K2 V9 R" b3 c5 q
- D1 u+ ]" B+ u- r* ^: @' W// Test for an error.
% G6 u, ]9 `# [& r+ R/ Tif (results.isError()) {
' x9 R1 H2 C: H return innovator.newError("Item not found: " + results.getErrorDetail());
. K' W9 s( A4 ~, r; c* |}
! H- w! S/ O2 \. @6 c / e( C" v! ~* R9 v5 G; x" x9 A
// Get a handle to the BOM Items. ' Y4 w* {1 Q- }4 O* x) |+ j& l
Item bomItems = results.getRelationships(); . C8 w' D! ?1 N8 p/ P
int count = bomItems.getItemCount();
. I& L% j6 T# S& }9 Kint i;
. E' I' }/ a, `# G # ], G8 F4 ]3 s2 u" J
// Create the results content.
7 t, \: f5 U3 d( @& D; wstring content = "<table border='1'>" +
+ i: [: A1 v9 e8 j+ O3 s "<tr>" + # H: U! l3 R+ E* B3 Z N
"<td>Part Number</td>" + - K+ P# V0 W& h& S. ^7 R8 U `. Q
"<td>Description</td>" + 6 R$ n' g5 _; \2 k6 D" |1 q
"<td>Cost</td>" +
5 m! I% O- _* u- \: Q4 m; n "<td>Quantity</td>" +
9 i1 R* C. d6 x7 O. c( Q "</tr>"; 7 V6 l- @" }) j! N
4 C2 U7 m) d/ i4 M9 S// Iterate over the BOM Items.
1 @. g6 N D6 M* v4 U. U3 afor (i=0; i<count; ++i)
6 j0 D6 b. R1 z' q3 Y; M1 j, o. o% K8 v: @{
n5 X, k7 Y. O// Get a handle to the relationship Item by index. / x0 m* a( J+ m5 a) q. P
Item bom = bomItems.getItemByIndex(i);
( d/ |0 t+ j# @* c: S6 i# V4 i7 _// Get a handle to the related Item for this relationship Item.
* @' d/ K, A1 V/ ]3 F Item bomPart = bom.getRelatedItem();
& E% ]/ E6 n) d
% Y0 x. u& h Z( ~; ?$ m content += "" + * E' h5 l+ g. O% K2 X% Y/ j* o) O
"<tr>" +
2 j6 y' l2 q: n& v* o; y; e "<td>" + bomPart.getProperty("item_number") + "</td>" + ) r, `7 g. G" T6 _9 j5 J2 L1 z
"<td>" + bomPart.getProperty("description") + "</td>" + ) K( ]& A1 c2 E: _2 ~
"<td>" + bomPart.getProperty("cost") + "</td>" +
7 E7 `& I# E" d7 I5 m$ V "<td>" + bom.getProperty("quantity") + "</td>" +
; ~% ^- V% N* i7 C; U "</tr>"; 1 P0 a! K, a3 u/ W% W+ a
}
+ c p& x9 a! N5 K) A$ j" Xcontent += "</table>"; * M# U# {0 @( P7 p+ u
$ C& |4 A- g$ A' j% u+ f( [
return innovator.newResult(content); 5 R f9 Q9 R3 ^, P0 R
A& d* S+ L& l& \ D
7 r. m9 E) e `+ ^4 N x) g
( q1 f& p/ T* w( R2 A7 s4 T% l/ N- ~
9 R+ @9 }" j3 U" P+ e6 z
9 g5 p. l9 m' c% |+ k/ B' C ' I( s; B: K% N& l Y. }3 O; W& l
Page 46
' e A9 G( T% T& Y+ p- ?
3 n4 o+ a8 I( ?2 ~) D% u6 jCopyright 2007
5 y3 T3 J9 b3 e* x7 cAras Corporation. # ?: _. o" Q4 {# _9 P3 F" Z3 n5 m
All Rights Reserved.
3 I3 `1 s" L& [; v0 M: MVB.Net
6 R6 {% {: U4 C4 GDim innovator As Innovator = Me.newInnovator()
m. V. C% V+ I# ~0 A, `
8 @6 q4 B: q" G8 W$ O0 g' Set up the query Item. : ?7 c! l! U! ~( C# Z2 H& t5 z
Dim qryItem As Item = Me.newItem("Part","get")
6 k0 m% r5 {8 n; }# WqryItem.setAttribute("select","item_number,description,cost")
' k- j; z; P9 t/ FqryItem.setID(myId)
+ O9 c( F0 j1 M, M S. [' V
0 ~* ^% }9 g( L4 N6 u( q' Add the BOM structure.
1 O7 @3 i! A7 q( s0 \2 zDim bomItem As Item = Me.newItem("Part BOM","get")
: a7 A. K0 S/ g5 ~; u! YbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
2 a( I J- l1 vqryItem.addRelationship(bomItem)
5 }4 X8 m( n- |1 r+ j0 I) m9 L 1 X0 e* y9 F" Y
' Perform the query.
2 H- s# V, ^1 `- jDim results As Item = qryItem.apply() ' h0 }. q" V2 H- D+ n, c2 L4 ~
* v' a3 g9 b7 A* g+ c$ s! E' Test for an error.
$ w0 ?! r; K5 q! P" J/ v* TIf results.isError() Then
- U5 D/ y- o/ y' `& w1 {! j# q; |' H Return innovator.newError(results.getErrorDetail())
2 i' ?& `+ e$ Q3 H; ?End If
( e* R/ Z, n% [1 D
8 }, b6 K1 E# b1 F* b H' Get a handle to the BOM Items.
' V3 D! t8 w( p9 T* PDim bomItems As Item = results.getRelationships()
% _' I% k+ L, t4 M2 K3 o# T5 K, PDim count As Integer = bomItems.getItemCount()
8 B: D$ Y6 \3 k4 hDim i As Integer 7 m) P# C; ~% u7 W8 [
1 \! d4 Q( `5 W- Z |4 s: s
' Create the results content.
2 L0 l$ F0 F* o. FDim content As String = "<table border='1'>" + _ ) o. @$ t( m% c% }4 Q! D
"<tr>" + _ 1 u4 M5 v! ]' F. \4 i% Y/ @
"<td>Part Number</td>" + _ 5 v: g2 v* s$ I! H4 I
"<td>Description</td>" + _ - \8 p* [5 @4 V, ~2 \+ |8 P# @. o
"<td>Cost</td>" + _
( e1 A2 Z0 G8 B8 Z z2 {5 t7 Z "<td>Quantity</td>" + _
t" i+ X- f) C1 e( {6 G "</tr>"
6 h/ X6 @6 {- [7 T$ r
. C+ q) T6 U8 W' Iterate over the BOM Items
7 o' W0 T4 L0 @* a! l; \! a% \+ pFor i = 0 To count - 1 ( c1 g' X; D3 d) }, l& t0 M7 j1 @1 j
' Get a handle to the relationship Item by index.
; x& A" `5 |' u- z/ O: a Dim bom As Item = bomItems.getItemByIndex(i) ! D# [. q% u( K1 `) n8 z" ~0 a
7 a5 _2 }/ B5 O' Get a handle to the related Item for this relationship Item.
1 W+ q6 U0 C" k# O9 l& p Dim bomPart As Item = bom.getRelatedItem()
7 N5 J% R0 h$ M/ k& X$ `
( V$ z% [2 h1 |$ q. k$ x content += _ 1 d. K, w z. S0 E
"<tr>" + _ 4 X7 q5 s1 T9 `) C% ~9 N# l" ]
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
& P/ \: R; j3 u! g1 H7 U "<td>" + bomPart.getProperty("description") + "</td>" + _ - x" i. n. i; h# m9 Z7 v/ F2 K
"<td>" + bomPart.getProperty("cost") + "</td>" + _ + ]2 w% g. [7 k5 I# r' V p. [
"<td>" + bom.getProperty("quantity") + "</td>" + _
, p$ O. T& g# A2 w "</tr>" & g2 o# r1 q+ a, G0 o
Next
( Y& b' {! W/ S: Y: H, Tcontent += "</table>" 3 A/ q1 i1 P" U" x
7 T, D& D& V. T0 w6 B
Return innovator.newResult(content)
# O/ u( Z3 A# {7 l9 U$ S* Y' R
& F. {# R) o3 s+ u" w B, } |
|