|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique + q5 ^4 ~4 D0 g$ K( j
To query for an Item and retrieve its structure you build the query as the structure " V2 ~: f2 j% c
you want returned. Use the IOM methods to add the relationships you want and
6 G. I) r! h% g: wbuild the structure in the Item. The server will return the structure that follows the
4 L& ~ H( C7 h# \3 Frequest structure.
5 `' F. X- t6 l7 w1 GThis recipe illustrates several related concepts together, which are how to get a set 6 a* d$ G8 Y% N7 D
of Items from an Item and how to iterate over the set, plus how to get the related $ p1 W% k" C3 d- I: j6 x0 j
Item from the relationship Item.
# ]+ {; N8 B# U( x$ t, A% N. BJavaScript / @1 ^' Q* R. s
var innovator = this.newInnovator(); : y# w, i3 m3 F( ?0 M, l
9 L+ v8 ?4 m n" z4 G$ P& g
// Set up the query Item. / M/ g; Q4 i$ W$ z
var qryItem = this.newItem("Part","get");
' j+ _7 P0 U: X) P4 wqryItem.setAttribute("select","item_number,description,cost"); 2 o3 y z+ D8 v2 y+ g1 c( y
qryItem.setID(myId); . x+ |: H5 G4 j. r8 z/ e" \
: w3 ]$ x; Y5 I% ` ~
// Add the BOM structure.
" |, [: w$ {% {8 F* Q9 bvar bomItem = this.newItem("Part BOM","get"); 0 ?' f3 i3 t+ e( i/ u, s
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
1 u5 k& e( Q' _qryItem.addRelationship(bomItem);
9 c1 b; o; x$ h6 g9 ], ]$ I
0 l1 w) _* q* ]) _0 u$ \// Perform the query. + F7 ~- q$ B5 Y+ s4 W
var results = qryItem.apply();
: n: n' j# {, f5 J! y" g' b4 F: I( _: b 2 D( M5 Y0 C+ M: @
// Test for an error. 8 [1 e1 C* ?7 r' f
if (results.isError()) { 5 `5 P) O+ [' ~/ c( v) q5 g. K/ d, @
top.aras.AlertError("Item not found: " + results.getErrorDetail());
& d/ q2 ~* j( e: T return; & X! T) x' [2 g# G6 F; u4 X
}
7 z9 W( W/ O. M. _# R4 ^9 l, d
[1 g4 N( n# B( Z E: W. B// Get a handle to the BOM Items.
+ a3 p6 E( ]" gvar bomItems = results.getRelationships(); 1 D* R' s6 Q. K4 Q b/ ~: f6 T& B
var count = bomItems.getItemCount();
7 E2 o. X7 J8 t1 Q* p! [$ B& P k+ {) F- M+ G+ p) v, G4 @7 Z. h
// Create the results content. n" J2 J& m& v6 Y( E9 k. B
var content = "<table border='1'>" + , I; i' [& E. \) F5 P$ p/ d0 ~
"<tr>" +
, ?; {& y3 d# h6 ]! g "<td>Part Number</td>" +
1 C9 i6 D# O- a0 i2 }7 B "<td>Description</td>" + & ~: ?8 I. b7 {' l" H% F# x7 l
"<td>Cost</td>" +
5 R8 r( v1 e7 @: n+ c "<td>Quantity</td>" +
. T" N2 R' J) U5 A, n6 F "</tr>"; $ y$ o/ k8 F) ~
% g. @* B9 S' Q. S6 r; |) D// Iterate over the BOM Items.
5 n) i9 Q1 g7 Y" kfor (var i=0; i<count; ++i) 1 ?% W) @. B" Q2 Z- m; C
{ 6 U, r3 }* K( z. o' f
// Get a handle to the relationship Item by index.
! c$ H' E! z* h% j. W: c# o0 H var bom = bomItems.getItemByIndex(i);
" Q8 o/ K3 |9 O: z0 M, i* \. N- A// Get a handle to the related Item for this relationship Item.
" n! C3 e, H3 M9 I# i var bomPart = bom.getRelatedItem(); ) U8 b$ `2 E/ m# N; [7 i
2 T; i( w7 L0 \
content += "<tr>" +
5 t+ N/ u. z, c3 U" ~. X "<td>" + bomPart.getProperty("item_number") + "</td>" +
) i+ G$ r4 ]3 H" k5 ]3 X "<td>" + bomPart.getProperty("description") + "</td>" +
8 v- d) @, _ g' \1 A "<td>" + bomPart.getProperty("cost") + "</td>" + $ {8 j7 j1 f g7 V
"<td>" + bom.getProperty("quantity") + "</td>" +
. M& {/ i/ d# s9 ]9 h4 m. E "</tr>";
5 R* ` ? Z; P: L/ N' E! [/ o} 0 |+ W6 r+ z' b
return content + "</table>";5 v0 O2 m& |9 K& H( D8 p
( L. z4 B5 m/ O3 |/ t. q% p9 z
6 k, V# P& S0 o9 S& v# o/ e
@! f3 ], i2 [/ Z( Y1 I
9 o' i# a4 V) }7 {# m+ V7 IC#
9 ?! }% j% j0 v6 C4 uInnovator innovator = this.newInnovator();
) e; K$ t8 z: F$ z) \
5 f& E' V: v, A% e// Set up the query Item.
- O6 y- j$ y: Z" I/ DItem qryItem = this.newItem("Part","get");
0 ~5 _0 L C+ r, u3 u; I% KqryItem.setAttribute("select","item_number,description,cost");
1 Y7 J- R a8 r5 @8 A SqryItem.setID(myId);
, t1 @5 q- ^& j) ?
' `2 f, C: e- h( v: d// Add the BOM structure.
! J* O, s& S6 r7 C" K: X4 QItem bomItem = this.newItem("Part BOM","get"); 7 a/ ?# s/ U6 l$ A: ]) \
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); , w# W9 ~+ t: C
qryItem.addRelationship(bomItem); 9 k( W, s8 h# u0 J1 C
8 h0 O* F7 V" `' b8 I// Perform the query.
: ]: @1 i# U, l$ zItem results = qryItem.apply(); / f3 G/ m* O" U6 Z7 i
. F8 z3 V4 L3 @% }/ W) O8 S// Test for an error. 6 R2 Q* N2 ^+ Z. }- C1 @
if (results.isError()) { - U5 D/ c4 n0 @4 A4 s
return innovator.newError("Item not found: " + results.getErrorDetail());
3 t$ ~! m: q6 L$ b! `5 t' ~} ; P: }6 [3 u2 P$ w( d* s# Y% i
; p) n* H- h- u+ _5 }( m8 t5 z
// Get a handle to the BOM Items. 3 ?! Q7 {, @) z* P2 S7 |5 f
Item bomItems = results.getRelationships();
, H1 I& B0 t! J7 `: a3 U& ~- B5 kint count = bomItems.getItemCount(); , z9 I$ k+ M5 r/ f7 K
int i;
9 Y9 H1 L Q! B1 {6 W+ Z! J8 k/ d4 L * o* s2 x, f5 Y- W& K
// Create the results content.
7 ]: C6 W3 c2 h% hstring content = "<table border='1'>" +
% j: I& S+ i/ B2 `! m "<tr>" +
* b! @/ \8 L) G# k5 C) K "<td>Part Number</td>" + " H% D" Z# J7 W5 b! Y& Z% ]% R; Q: E
"<td>Description</td>" +
+ h Z) K8 Z, [1 y7 i "<td>Cost</td>" + - T3 D9 y5 C) o4 E
"<td>Quantity</td>" +
& P( e! Q! ^. ?% U9 A6 q "</tr>"; ! l H T/ n6 Q* W/ Y
/ L9 N3 N7 q7 n2 i1 E+ S3 s) i5 o: [// Iterate over the BOM Items. 2 m9 D$ b. |6 l
for (i=0; i<count; ++i) - C4 d, J5 d! o* t
{
: l& [5 Q/ {0 p! p// Get a handle to the relationship Item by index. * }. W1 ]' e5 T+ ~; y+ \9 n
Item bom = bomItems.getItemByIndex(i);
/ I: I' g1 k( f5 U; } M+ Z$ F// Get a handle to the related Item for this relationship Item. 3 H C: x% h% Q. r# u
Item bomPart = bom.getRelatedItem();
$ ]+ r9 H. K1 j J! }9 v) j( N7 t
! @; b1 g/ E$ S( Y* Y. j8 v content += "" + : P# d# N) X/ L S: d, k
"<tr>" +
. k( ?* N; q+ R6 K "<td>" + bomPart.getProperty("item_number") + "</td>" + * g% |5 U$ W8 f' d" m" u+ D
"<td>" + bomPart.getProperty("description") + "</td>" +
" g9 G0 e/ V6 l, k5 c0 F) u+ ? "<td>" + bomPart.getProperty("cost") + "</td>" +
& r( W, U; a5 f7 ?1 B0 K N "<td>" + bom.getProperty("quantity") + "</td>" +
' c- h$ a( o3 w "</tr>"; . @6 z+ N3 E3 \8 T' j. |! i
} 7 v) ~2 t2 F* e/ C& U' J
content += "</table>";
$ j+ m. X+ X2 o1 `" ~ 2 G4 O/ j" Z7 t! ?+ g/ K
return innovator.newResult(content); / U6 ^4 g2 E! p, v( Q
4 l, l t( C8 Q& ~9 T' e, T- m. w$ `9 |' }0 x
/ ?! E7 _( i" f8 L7 _6 W# e' f7 g' ^* j E* D/ {
1 l5 M% H7 ]/ A9 O2 b: F# A9 h5 z4 x5 k
( a l/ D/ r2 M* u! R Page 46
4 \" y/ ?( t; ^: ^4 x7 a % B0 K) R. Z, Y. {7 i7 _7 K: e3 z
Copyright 2007 0 I7 G$ A4 i/ T) Q5 d0 X7 X( Q* s
Aras Corporation.
5 s3 H1 w* W u5 `+ B2 SAll Rights Reserved.
: n0 L h) Z+ _/ ]VB.Net
7 v: N1 ^6 o7 ]. y0 Y x- \Dim innovator As Innovator = Me.newInnovator()
+ o ]5 h, E- {+ P8 j4 ^3 \ 3 K( Y# ^$ w* K7 N/ F* j
' Set up the query Item. # ~/ L; M! b$ J P/ s
Dim qryItem As Item = Me.newItem("Part","get") 3 h8 {2 N+ J5 }9 j8 s" [3 a
qryItem.setAttribute("select","item_number,description,cost")
! }; M& q/ p/ Z; i+ {- vqryItem.setID(myId)
5 q; H- E) g! z, r 9 W4 T- |# x, x+ {: ^
' Add the BOM structure. 8 [7 B# a+ P, z7 t8 k
Dim bomItem As Item = Me.newItem("Part BOM","get") 2 C, x, _! g4 h6 k/ d
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 5 J, x( q2 {% ^) h
qryItem.addRelationship(bomItem) / n- r0 d; b, m( f
9 B% r7 ?9 M: k8 H9 f' Perform the query.
- \. C0 ^& m) _Dim results As Item = qryItem.apply()
8 U8 e8 I! X7 j* j! a2 w
0 R$ o7 \# T- s T' Test for an error. * } b8 K. A; Q. Y/ P$ U
If results.isError() Then
$ o* q+ S& Y* c Return innovator.newError(results.getErrorDetail())
' \9 ?3 F' F2 d8 W) ?- AEnd If
3 m0 g) s) V, Y% g: G8 f$ G$ ]# L5 o F/ m. }0 n, z8 z, ]; Y _" A: s
' Get a handle to the BOM Items. ) i( M3 L" z& \0 b$ h7 w; f
Dim bomItems As Item = results.getRelationships() 8 c+ H" ^# ?% c3 T, [3 z* B
Dim count As Integer = bomItems.getItemCount() 1 l4 I0 S* E" l2 m8 D& g3 H
Dim i As Integer
, c( U B6 }/ P1 [' u" D1 W+ N
6 i5 m" \$ z5 a. a+ Y9 `/ V8 T6 s3 c' Create the results content.
' J' v3 e# F( jDim content As String = "<table border='1'>" + _
! \$ k& g/ O) r, e* F "<tr>" + _
- @: l ?! k, w "<td>Part Number</td>" + _ 0 O* U5 o5 p) Q! m
"<td>Description</td>" + _ , ~& c* v& C) ? c2 V `' ~- N
"<td>Cost</td>" + _
& x5 r y2 r. |# b: ~$ z( N# |& O "<td>Quantity</td>" + _
" ~. I$ q* S$ t# l8 o "</tr>"
! {( L: Y a4 ]: s' s
) f& P. ], e% r2 t' P' Iterate over the BOM Items 9 x& b' l& ~2 E+ E0 Y" H- w
For i = 0 To count - 1
2 N# S+ H7 a, K- Y9 o" S8 A! L' Get a handle to the relationship Item by index.
; G0 D: T' {! a3 e6 C" ` Dim bom As Item = bomItems.getItemByIndex(i)
1 q" Q2 y6 @2 t3 ~3 W
5 p+ H7 B# g# R U' Get a handle to the related Item for this relationship Item. 5 s* t4 B* B2 W( m0 e
Dim bomPart As Item = bom.getRelatedItem()
7 Z# l3 W7 I3 T6 j
* B, c# Q: r$ g; {7 R) z v content += _
6 R- O6 g1 B4 O8 q' L s "<tr>" + _
& A% [5 P$ J5 f" e% D/ o "<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ }0 A- h0 p& d9 X4 G, O" C' R
"<td>" + bomPart.getProperty("description") + "</td>" + _
* `' p6 ?- P8 {# ~: {: c! F" v "<td>" + bomPart.getProperty("cost") + "</td>" + _ $ V" V$ |: g' h0 e! _
"<td>" + bom.getProperty("quantity") + "</td>" + _
, x. I" K2 _6 `/ |4 \; @ "</tr>"
q4 }! @* N5 ]% M0 S# jNext
* x4 }; K" v W- ncontent += "</table>"
" W4 G% R6 P' e+ n% o6 K4 M& M! \
; v/ E6 n5 f7 i( H" W3 aReturn innovator.newResult(content) ( O2 w$ E: C; j, K4 k8 w
; Y: w* M, X! T5 M3 y( |: g/ W
|
|