|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ' @' P: U7 C' D9 A0 B5 B: S. F& m
To query for an Item and retrieve its structure you build the query as the structure 9 ^# q6 @6 P, k9 Q! m& H( _
you want returned. Use the IOM methods to add the relationships you want and
! @* g4 _4 \6 a, G) u3 qbuild the structure in the Item. The server will return the structure that follows the ! I+ i- p# y) B- D0 \& E
request structure.
& d3 L- U# `" pThis recipe illustrates several related concepts together, which are how to get a set 4 y+ M: s: V3 h; u/ b) _& c8 M; d
of Items from an Item and how to iterate over the set, plus how to get the related
& @7 `; X& k; d2 y' I6 P; e. {. fItem from the relationship Item. 4 g3 g7 N$ J" b; B0 S/ K( @/ t
JavaScript
0 i7 p+ R$ Q7 I. evar innovator = this.newInnovator(); 2 x- `0 U6 X' Y! u
& s/ R# `; v9 ]& F' U! R// Set up the query Item.
, z2 X, h$ w* evar qryItem = this.newItem("Part","get");
6 B; |- N; g# gqryItem.setAttribute("select","item_number,description,cost");
* W. F2 z% ]' a9 hqryItem.setID(myId); * W( n$ S) E9 B# E! _8 s
# |+ X+ u' ^5 }1 w- e% w// Add the BOM structure. 4 p2 K7 L% H! ]
var bomItem = this.newItem("Part BOM","get");
1 w- i E3 X) tbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 1 I! w' [8 k# Z \
qryItem.addRelationship(bomItem); 9 I1 ^+ P3 l; m7 x1 r
# k0 E4 ^: {6 a# z, ^' E8 Q* }// Perform the query.
) ^+ X8 i7 R" e* ^1 Tvar results = qryItem.apply();
, D: B) k, |* `% K9 o / f2 O$ u, S! |' l
// Test for an error. , J9 }' F" H9 s! @) t4 c. R+ O
if (results.isError()) { 6 T& T( H$ R8 D/ ~6 S# D! B$ Q
top.aras.AlertError("Item not found: " + results.getErrorDetail()); $ c7 W+ `- v) b/ H$ O) u1 o
return; - @ q! i3 r+ d, Y
}
+ p7 ?+ q- w% }
- a( D, M. @) i1 i/ E// Get a handle to the BOM Items. V0 |+ q9 C2 c9 a8 B. A9 C V3 \/ |
var bomItems = results.getRelationships();
V2 H8 H2 w) `( u3 M2 O+ Kvar count = bomItems.getItemCount();
* y5 K1 c5 N- |8 \/ v( | ! R4 F3 p5 \" h R% z- q9 @. y* r
// Create the results content. . @3 X- C* j" _6 q5 P" z
var content = "<table border='1'>" + 4 F) K- l# `8 q1 v5 S* I! e
"<tr>" + 0 b& K( u7 h" a1 F8 a" a! c2 `# p3 H
"<td>Part Number</td>" +
$ t# a6 M/ ~" X0 @ "<td>Description</td>" + ! y: n" X1 D6 ?. S: j
"<td>Cost</td>" +
4 o4 x; W+ v& Q. B6 T' \7 C "<td>Quantity</td>" +
! P7 M: L2 N# x% ] "</tr>";
# C( m( s- F4 P$ g$ o. I0 v2 l
3 I5 m# o& `% @ j1 w9 y# [# h// Iterate over the BOM Items.
* U, s6 p2 P; [8 G: G" d6 m C2 bfor (var i=0; i<count; ++i)
" } i/ }: R: T9 _4 X9 y{
% S; M' A7 V6 n" O7 h& I" P4 w// Get a handle to the relationship Item by index. ' u- M3 K# p, s3 A' v& q4 }3 x E6 d5 J
var bom = bomItems.getItemByIndex(i); ; B0 O8 E6 }% L
// Get a handle to the related Item for this relationship Item. ; d4 n1 m! v% N7 y7 u$ N4 Y
var bomPart = bom.getRelatedItem(); 5 v; w4 M5 Y$ i( l
6 x- |, ~4 d q/ D( y! m
content += "<tr>" + 7 ~) h/ F5 b7 m0 N+ K' v" T
"<td>" + bomPart.getProperty("item_number") + "</td>" +
6 u+ A, P5 g" z "<td>" + bomPart.getProperty("description") + "</td>" +
. t" p/ W0 O) @4 D6 E "<td>" + bomPart.getProperty("cost") + "</td>" + 7 n( `% c9 Z e- b4 m+ l# s
"<td>" + bom.getProperty("quantity") + "</td>" +
" h8 W% A9 e. Z8 V' c! S+ F "</tr>"; 4 i( |$ W$ n& P0 X. X
}
1 @. a$ }) Y* f) j treturn content + "</table>";7 p0 R9 L" S1 X( D
! m7 r! B/ Y V( g4 m `/ B
# _% i7 `3 Z3 S0 _. G
, U" c! i0 R' s) {" U
' O" }3 J* k; R5 SC# $ X( w4 O) f7 T
Innovator innovator = this.newInnovator(); 3 Q5 Q; C* T; W/ p0 b1 h3 z
2 C; b3 f9 G: z" L) r
// Set up the query Item. ! k6 w( V7 o. P
Item qryItem = this.newItem("Part","get");
' J( E! u8 H7 e7 x) ]qryItem.setAttribute("select","item_number,description,cost");
5 S: m0 K/ K) E9 Z8 TqryItem.setID(myId);
3 a. a8 A& Z# o0 e) K2 d9 Y
1 l& b- K! D# F/ m0 }// Add the BOM structure. 1 c2 J/ W! C- N
Item bomItem = this.newItem("Part BOM","get"); 1 F" X' G; z& P5 r
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); " W& p9 p& F/ Y9 ~9 \3 q
qryItem.addRelationship(bomItem); 3 r% Z% c( p1 z$ f- U. }' ^9 E1 n9 {
; J: }3 E; I( s
// Perform the query.
' n. G- N# e# m$ X" r* yItem results = qryItem.apply();
" W* C7 t: T3 Y# [, B% D1 a, @
- U" V$ ~# s/ N; w// Test for an error.
* s |4 C7 [% `. n+ K! }8 T7 l0 Aif (results.isError()) { 3 C7 f4 V( w- a9 T9 J7 }3 Y
return innovator.newError("Item not found: " + results.getErrorDetail()); * @" V; }1 w% C; Z
}
' _5 E# ?- z2 O( s$ N- ^6 R( H
. @: p! q, s% I% {" j// Get a handle to the BOM Items. 8 H7 P/ D Z6 E- r8 D+ j
Item bomItems = results.getRelationships(); 3 }6 }. o- e" ]
int count = bomItems.getItemCount(); * D! H% f! N1 k6 Y; V: k) m
int i; , M3 @# Z: v9 J
. a" i2 D2 O% {/ G3 } h// Create the results content.
/ f* K: k, S$ w$ i1 E {string content = "<table border='1'>" +
) ]( U- Z( j. [: ^- k "<tr>" + , i) Y! C) I% z+ I
"<td>Part Number</td>" + . X0 s7 m; k7 D+ Q* F' x
"<td>Description</td>" +
, f8 x' a7 a4 T1 x, W6 i9 A5 ]3 L1 F# a "<td>Cost</td>" +
, c4 n2 y5 I( \+ \1 a "<td>Quantity</td>" + . l* Y3 J ]6 A
"</tr>";
( Z5 c. ~. x( A# S/ |
( q3 m) `. Q4 {/ V( }// Iterate over the BOM Items.
3 q3 X- h) h3 r" S# X! Z, ~' t- X# Sfor (i=0; i<count; ++i)
' B" J( ]: s. F& `) E{
& |) _3 L) B, W; @( o// Get a handle to the relationship Item by index. _! l$ o- y+ e) H, b& w8 `
Item bom = bomItems.getItemByIndex(i); ) Q6 N8 r% t( P3 h8 m
// Get a handle to the related Item for this relationship Item. $ I/ L) }# l) Q' P5 | x' f
Item bomPart = bom.getRelatedItem(); 9 S3 l9 T4 W4 ]
2 t/ P, b0 F3 y3 C; Q. H
content += "" +
& y* T6 b' g& J+ C1 Y "<tr>" +
3 \% m9 T1 N/ H1 Y "<td>" + bomPart.getProperty("item_number") + "</td>" + ( A3 t6 U6 s0 z. S0 X( m4 Y6 S) a
"<td>" + bomPart.getProperty("description") + "</td>" + a2 e. a) z8 ~5 N8 ?& C c5 x. W& w
"<td>" + bomPart.getProperty("cost") + "</td>" + & Q1 t0 m5 b2 H B2 e# L
"<td>" + bom.getProperty("quantity") + "</td>" + . B8 Y: V5 Y8 o- n: d9 @' Y& M# Y
"</tr>"; + D" M7 `3 Y, K0 `8 V
}
" @1 t% c+ I* T6 s" U! U, ]1 tcontent += "</table>";
2 \/ _- i% n4 r. }; |9 \2 p' C ; J: j9 |& l) I; a
return innovator.newResult(content);
' r8 ~3 ]" |8 Y5 R. U+ x
* a! r. t9 I9 Q' e a, `, [: e
4 j. I! G' q0 s4 N! \! u
. V3 H. j& z1 x f+ `* ^/ m& X" t4 A! u0 f0 q5 v7 H3 P
1 S: v2 Y# {5 }
6 Y9 g1 }7 p7 G9 S& V9 p / j1 h8 m0 U: F- \
Page 46
7 D7 V" [6 A N! t |6 l& F8 b % S+ _" B7 X- ~" ^) \; r6 e( D
Copyright 2007
4 A7 E8 ?1 W/ y' lAras Corporation. + Y$ R6 Z8 m/ P1 g. N
All Rights Reserved.
* c9 y# N/ ~1 _5 r% F6 _VB.Net
" D" V( t3 g( w7 e% H6 XDim innovator As Innovator = Me.newInnovator()
) C. b* Y) z- @% \
$ U/ D( W6 _% L0 P) {' Set up the query Item.
0 k2 N4 E& O" V( {Dim qryItem As Item = Me.newItem("Part","get") ) A0 s0 @0 w- [
qryItem.setAttribute("select","item_number,description,cost") + T( ~1 ]+ x6 _9 |
qryItem.setID(myId)
0 h/ O. U: i7 h 5 S( ?# U% ^2 }( n1 G" x# i
' Add the BOM structure.
) d3 D" Y' n/ EDim bomItem As Item = Me.newItem("Part BOM","get")
) {! A* a$ A9 FbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
) W+ m+ D; L9 o9 j* y* K) J0 \qryItem.addRelationship(bomItem) ) `, @1 r% C- W) e% Y
; L4 u( E$ t2 Q' }8 c3 \5 X
' Perform the query.
% T. R! b' B; C0 L7 y6 sDim results As Item = qryItem.apply() # u; u7 C; g$ ~2 }
- y' K0 n! e S0 f' o& T. K+ L" j' Test for an error. 4 I2 v" X- u* O6 p
If results.isError() Then
% c A/ C* B% a4 q, s Return innovator.newError(results.getErrorDetail())
+ S H p5 [3 |. l+ }8 aEnd If
; s) Z2 S2 E( ] # F$ \- T5 @, k5 j
' Get a handle to the BOM Items. ' D! I, D4 n) _* ^2 C, ^5 B
Dim bomItems As Item = results.getRelationships() % _3 l( i- g& O7 T; d( I
Dim count As Integer = bomItems.getItemCount()
7 n7 ]9 i9 F8 ODim i As Integer
" {" U1 t; I3 ]5 v
8 A f% x. J: c+ g- M' Create the results content. 5 K- c! ?( D" {2 o
Dim content As String = "<table border='1'>" + _
6 }0 i) t. h! ~) j$ X1 T7 J7 R "<tr>" + _ 6 A, S8 X- q! z9 t* y
"<td>Part Number</td>" + _ " ?+ J. M% \2 D: q
"<td>Description</td>" + _ 1 P" q8 t% m2 ]
"<td>Cost</td>" + _ * R. f3 V0 i6 T% x2 Z- Z
"<td>Quantity</td>" + _
5 v0 u8 t7 E' t5 F6 a/ ~6 I& ? "</tr>" . }0 f+ z) D& y# l% l$ J9 k
9 G i5 F' l4 m2 E* x5 u6 B' B4 _" W% G
' Iterate over the BOM Items
0 P- |4 y. H; q4 h) bFor i = 0 To count - 1 2 L1 ~) b7 \6 l' J- r: D4 |
' Get a handle to the relationship Item by index.
" h3 v5 C9 ?. x( a$ _ Dim bom As Item = bomItems.getItemByIndex(i)
( n0 L! x+ d4 B# Y( U# M. c1 q & h" U1 j2 @4 ^) Z( W$ F
' Get a handle to the related Item for this relationship Item. 8 f c5 `) L5 l7 |
Dim bomPart As Item = bom.getRelatedItem() ( P: q, ^; y5 D
2 @( Q3 v( C7 N4 I& J" {6 x
content += _
: h2 v9 h3 S* K* N "<tr>" + _ $ Y1 Q, Z6 A0 q9 r2 D% H G. {
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 C0 x) }" c& ?# X6 @( c' k
"<td>" + bomPart.getProperty("description") + "</td>" + _ ' N1 N8 T) R- @) |+ k1 \
"<td>" + bomPart.getProperty("cost") + "</td>" + _
! W$ h8 n* H* }4 v2 r, j o "<td>" + bom.getProperty("quantity") + "</td>" + _ ' o0 X: t! d( c5 Z$ U( J
"</tr>"
4 s v4 M/ D/ R( `* ]3 i& |Next . A+ Z- `% c D
content += "</table>" / }2 S* }2 E% h9 W( r
3 b+ X6 A- n* T1 c: @1 H! |
Return innovator.newResult(content)
; S$ |- ]. r/ q, U$ l
# A5 E; _5 e& L( H |
|