|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique * K: A5 r( K$ |; U
To query for an Item and retrieve its structure you build the query as the structure # q: @; y0 M8 H
you want returned. Use the IOM methods to add the relationships you want and ; c3 s- R3 c3 O& u) c0 L |' k
build the structure in the Item. The server will return the structure that follows the
9 g/ n. s5 N, D$ k/ j5 y$ F" jrequest structure.
1 f1 {, w% x$ H8 zThis recipe illustrates several related concepts together, which are how to get a set
3 [( X ]* [0 _9 S1 u' J2 Pof Items from an Item and how to iterate over the set, plus how to get the related " B% y+ N, M" n* B& V
Item from the relationship Item. $ h6 x1 s% ~/ [ I+ E* f0 |" ~4 ^
JavaScript
' C! G) O+ r6 j9 V0 Q+ Nvar innovator = this.newInnovator();
; r0 H" F. j+ H/ P7 C
$ C. x. f6 ?* J' J: T; j// Set up the query Item.
2 w2 K0 }) ^1 |# P- [3 _' Xvar qryItem = this.newItem("Part","get"); " B8 ~, P# F' F1 s7 I6 v' X
qryItem.setAttribute("select","item_number,description,cost");
$ G9 U1 G/ T& D% R+ Q. O& |0 ]qryItem.setID(myId);
# D' t3 D5 q+ |# S8 c2 r! h4 _ 0 w' G% @ y: P" T" u+ u; c
// Add the BOM structure.
W- B s. K/ w# j" hvar bomItem = this.newItem("Part BOM","get");
1 r- C* w4 F! h1 F/ C y( m4 TbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
8 u( {! R/ `9 W8 Y& SqryItem.addRelationship(bomItem);
- b8 r" @ t' E3 x0 [
% e8 f4 d3 G) ^* X// Perform the query. 0 a- `1 V8 o, {2 _1 v' H- L
var results = qryItem.apply();
0 K0 m6 C' N4 E* w 2 }+ n) B& A) t$ j* |2 l# @" p
// Test for an error. $ h. ?! g6 a# I+ ?9 l
if (results.isError()) {
3 c! Z/ Z0 _/ g top.aras.AlertError("Item not found: " + results.getErrorDetail());
# M6 w' m3 P& |. p return; - \6 b& ?% W' U0 b- \
}
& d2 F9 r9 r1 I& i
4 u9 ^9 S3 v8 N" H/ K. A7 |// Get a handle to the BOM Items. & k/ K1 O% M1 p, V. ^8 I8 m
var bomItems = results.getRelationships(); 0 H- l7 U; L: r
var count = bomItems.getItemCount(); ' J) L* |5 K) G7 |7 @
+ o$ a7 |! y7 X- ^
// Create the results content.
5 `2 ]% a$ x1 \( f0 b4 Tvar content = "<table border='1'>" +
+ h5 P& y( ?; o) l6 D "<tr>" +
( I- s8 I0 \ s4 F "<td>Part Number</td>" +
/ J' Z+ O' `! K$ Z "<td>Description</td>" +
; f7 p: u9 i# u y9 j2 g: J "<td>Cost</td>" + - f+ g# c. J3 R
"<td>Quantity</td>" +
& j$ g) W1 @4 Y9 _2 _, { "</tr>"; ' ~& v& z1 Y4 \6 `& w, m
8 [' G. |9 l8 F# N+ w3 {1 g4 r
// Iterate over the BOM Items. ; G( N9 r' h8 g; e- a
for (var i=0; i<count; ++i) & W" t( @: [. y/ W4 ]* q. f& C
{
; f( F, Z! Y- Y- b/ W* n0 R// Get a handle to the relationship Item by index. # M7 h# F1 c" \2 J2 u8 c' x
var bom = bomItems.getItemByIndex(i);
+ ~0 q; \, f- F; m// Get a handle to the related Item for this relationship Item. 0 b: B$ P' T0 Y2 M% x
var bomPart = bom.getRelatedItem(); * t/ O4 f7 H) D6 m. q7 q
1 C1 {( n4 g; N2 D' s& m. ~ content += "<tr>" +
( j7 ~7 f% m# Q$ W5 }5 n "<td>" + bomPart.getProperty("item_number") + "</td>" + " `( |) N# g! E( `7 y6 }3 Q9 z4 o
"<td>" + bomPart.getProperty("description") + "</td>" +
8 k/ o0 R# k _% M "<td>" + bomPart.getProperty("cost") + "</td>" + 8 x7 g, w' g0 H
"<td>" + bom.getProperty("quantity") + "</td>" +
' Z( H5 w6 U+ b$ X/ s; D# H "</tr>";
6 _# @# F8 O1 p6 c} - H0 }# m4 m. w2 _/ J+ |) b/ p
return content + "</table>";& A' {" j% ]- c- M3 ?3 _
1 q$ @8 C1 ?3 }/ w
* V: u- q/ w* g4 N" r
! j3 h- z# h. t: W
3 [0 p2 M$ H7 [, X& A- p3 h d8 ~' HC# 7 A' t4 L5 B; m) I; x+ f1 r
Innovator innovator = this.newInnovator(); ' z( g, Y) G* ~+ _2 n& L' }* e
* k( h# s: E3 F7 B
// Set up the query Item.
# ^- B; ^- v8 {9 P5 R- b' e& F8 tItem qryItem = this.newItem("Part","get"); , C9 e1 x) o' P5 p7 w) \: I( d$ @
qryItem.setAttribute("select","item_number,description,cost");
+ J. z; d- w2 }) g% I. v: C) R, b' O% AqryItem.setID(myId); / C: h& O$ T- Z* J( E# E
# M3 M) G, T% k4 R3 n& t
// Add the BOM structure. ; r4 S+ }7 o( x9 e! h4 `
Item bomItem = this.newItem("Part BOM","get");
. c& i1 ~) b0 [4 @bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
$ ~& l5 D. G& u* |, n9 iqryItem.addRelationship(bomItem);
# ]6 i& s O6 X" M/ X" K1 ]4 V ( `0 T0 h1 h8 @: r; I _1 ^
// Perform the query. 2 w+ m. R. T) y" d0 t2 x: j2 I
Item results = qryItem.apply(); 7 p: r: S8 P) v4 a) T' c
, i: v5 x' p! ^
// Test for an error.
! L& j2 L2 _7 Pif (results.isError()) { 5 a2 K. Q9 _% p
return innovator.newError("Item not found: " + results.getErrorDetail());
$ u- F) w0 h7 H! }. C} & w$ @. V H8 k+ w
( K) |1 Z2 s' x4 r* P7 @// Get a handle to the BOM Items.
. w3 _4 [7 A2 m w' HItem bomItems = results.getRelationships();
8 ?/ ]% _4 ]# i* aint count = bomItems.getItemCount();
6 I# l- u. j8 H# r/ j- e- Qint i;
) d' t; {$ W5 B! o" G 0 h" i) m: F& j' B) r# s7 z% _7 X
// Create the results content. 6 Q/ d& e( |+ {0 `. x4 Z) U
string content = "<table border='1'>" +
( _7 Y8 b4 C5 b9 S8 E "<tr>" + , ?5 V2 @) S) q( a, Q
"<td>Part Number</td>" +
) `5 b. D% g5 X$ |! z' O) @ "<td>Description</td>" +
* c+ w$ S6 \/ E* B "<td>Cost</td>" +
( i' ?- }9 i& |. Z* n7 T3 H' n "<td>Quantity</td>" + , Z/ J! o1 J( J' W. P; G- b
"</tr>";
5 C& D3 f' n, ]$ n# ~" c
& ^7 I/ ?' n( A' Q+ x// Iterate over the BOM Items. : k5 f$ U( R, ~* Y
for (i=0; i<count; ++i) ) u2 U8 `2 z1 {* y+ Q: H# _
{
3 |% w; B$ x# b5 w# Y// Get a handle to the relationship Item by index. 5 z! v6 b8 l& M3 j6 t* n! U
Item bom = bomItems.getItemByIndex(i);
. C0 F+ C( t$ u' c3 F// Get a handle to the related Item for this relationship Item.
, v' z" f0 B& B8 t0 m. n Item bomPart = bom.getRelatedItem(); 1 o9 s" @) u; v. N
3 q3 C6 G( n6 D. G1 h$ z
content += "" +
; t- e+ }, E2 o+ f0 L$ Q "<tr>" +
, p6 o5 a& d' @) d "<td>" + bomPart.getProperty("item_number") + "</td>" + + ], u, L! G; J% }7 v& A$ e+ D
"<td>" + bomPart.getProperty("description") + "</td>" + , [" J. \0 g; b- }6 k: x+ O) T& z+ K
"<td>" + bomPart.getProperty("cost") + "</td>" +
r. z* B' @8 |% u5 g9 f "<td>" + bom.getProperty("quantity") + "</td>" + . x% V4 P2 b3 \0 i+ M& M
"</tr>";
A+ |# a: c/ d4 m} ; @$ y' a5 o/ I$ |+ J L
content += "</table>";
' \' R1 F( ?9 x( v4 `& z. G ) L5 Y3 ~3 o, M9 X3 ?
return innovator.newResult(content);
( R$ \0 P2 {( M7 D& G
3 f; }" \, T( k8 Z: h; Z+ c
& s- b; b5 Q8 |* u+ u. T
: `: W8 @7 s C# T& ~4 M( D* ?& A, F1 r# ~; ]5 C2 v3 c6 {, y/ F% _
% r# g- {0 a* p# j: _1 `
( o7 i' K6 X2 V# ^$ ^& |, N
8 a1 g( n0 k* ^3 D# _
Page 46 & K8 g* s. V; ~: G6 U
& H. s: g3 k4 }- Y- RCopyright 2007 ( p$ U' Q3 L0 K
Aras Corporation.
n6 @# y/ K- n% aAll Rights Reserved.
# Z- F, q" ~' f5 ]2 QVB.Net 4 E2 T2 s1 ?. ]. u6 R% R8 ~, x) B
Dim innovator As Innovator = Me.newInnovator() / y6 s) |) k: u4 v7 J" n, t9 K
4 h8 J3 X3 h! ?2 k' Set up the query Item. , w$ r/ a* H8 \- r$ D G* [$ p
Dim qryItem As Item = Me.newItem("Part","get") & M( Q9 ^' _& L1 z
qryItem.setAttribute("select","item_number,description,cost") 4 s2 R+ ^. T3 p# Y& ~
qryItem.setID(myId)
. ?0 c5 f8 E1 y5 ?( ~
9 Z- S! \& i% k7 g' Add the BOM structure.
+ g4 V% [5 i! [$ M" v# k, g J$ `6 JDim bomItem As Item = Me.newItem("Part BOM","get") 3 V+ j2 L- W6 @ `1 |. a
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
3 G* c9 _# w2 G% X" ?. }/ JqryItem.addRelationship(bomItem) % F( y8 Y3 Z9 z* B
- Y( s: x- R6 E$ Q% }
' Perform the query.
" ~+ z- K, @. _" C! K( W0 wDim results As Item = qryItem.apply() ) S/ A, `+ t# k
; G+ t K9 _* o; _( D. d' Test for an error.
# g: X3 Y7 ^/ A% ^$ y9 IIf results.isError() Then
0 i6 R, g: [( C/ h5 E3 F# a Return innovator.newError(results.getErrorDetail())
$ a9 o( f/ S: m9 U8 Y( {# L% s, dEnd If 7 L* |1 E& P$ w X" A# m# m0 @
3 L4 E$ `- e0 Q6 K' Get a handle to the BOM Items. ' a# q& K6 r3 }7 O+ ?- P
Dim bomItems As Item = results.getRelationships() 1 D( U1 u. \: F1 S+ o
Dim count As Integer = bomItems.getItemCount() 7 m, U& i5 ^7 F8 j
Dim i As Integer
9 t4 a6 G( \1 i! @$ x) X |6 e* L; k4 t
' Create the results content.
9 m. T' {9 G$ oDim content As String = "<table border='1'>" + _
$ s* [" D% q, M- h6 P' a "<tr>" + _
) L8 {% F0 J/ v% y "<td>Part Number</td>" + _
8 h$ @- t2 a. L( N1 m "<td>Description</td>" + _
; X: f. t7 \: C* \+ x+ K "<td>Cost</td>" + _
; D/ M# i# y* k "<td>Quantity</td>" + _ & W/ p, @3 j( i
"</tr>" ) s" T8 D1 w- L* q
! f5 @! j8 D- ]/ _% e' u
' Iterate over the BOM Items
! x! \6 m. p3 a3 OFor i = 0 To count - 1 ) H% V& p+ l! T- F/ k3 a- u1 G0 j
' Get a handle to the relationship Item by index.
/ s# L! \* f* F' v% l, V& A Dim bom As Item = bomItems.getItemByIndex(i)
( N8 e! i. n' G6 F, |
' Y% s8 w9 F7 t; F' Get a handle to the related Item for this relationship Item.
# U9 b) E3 h& c0 u Dim bomPart As Item = bom.getRelatedItem()
- e# s+ V+ s0 N" V/ @
' |% B' \ u0 j0 X# R: C content += _
/ P3 K) V# E9 v+ U9 A* P "<tr>" + _
, ]& L" L* U5 i f1 K "<td>" + bomPart.getProperty("item_number") + "</td>" + _ * k. D1 m" a3 n& Y8 D4 y' v, M8 n
"<td>" + bomPart.getProperty("description") + "</td>" + _ + }- {% U- n9 Y$ M) u! x9 E" s
"<td>" + bomPart.getProperty("cost") + "</td>" + _
, q8 C! {$ F) p, D- e0 | "<td>" + bom.getProperty("quantity") + "</td>" + _
( p) W' T' D. o. P "</tr>"
4 C( Z" Z0 g" ~Next , z6 @' e" ]+ \2 q8 H) C3 u* N
content += "</table>"
R, f4 u5 U1 h6 n 6 f/ s- c: V1 j9 m% _
Return innovator.newResult(content)
% A3 g6 W! a9 I8 y+ f/ E3 G4 _/ ~$ C! r# ~+ E; K1 `
|
|