|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique % _0 s6 Q) ]/ h5 b, j x) @) j6 _% E) Z
To query for an Item and retrieve its structure you build the query as the structure - S7 v1 Y* V3 O
you want returned. Use the IOM methods to add the relationships you want and 9 z _% Z8 U2 M
build the structure in the Item. The server will return the structure that follows the 6 x- L" g% \0 T4 }1 g
request structure. ( T7 T" n2 O7 Q( w4 F f3 ` V
This recipe illustrates several related concepts together, which are how to get a set
6 |/ y: i# k. N- Kof Items from an Item and how to iterate over the set, plus how to get the related
5 e C2 B3 X0 M8 Y. [ x1 YItem from the relationship Item. 7 O* Q3 E* Y |/ ~" R( H5 G
JavaScript
' ?3 Y$ Q+ g) w. ]var innovator = this.newInnovator();
% M9 i/ u* f6 L8 J; x7 V ; _: Y$ s# o: i4 ?
// Set up the query Item.
- b+ a: F9 W( ^9 Z5 |8 svar qryItem = this.newItem("Part","get"); ' U4 O: k9 r6 g$ n7 T$ x1 M R1 v
qryItem.setAttribute("select","item_number,description,cost");
' u2 s# g6 e: F: t) u; PqryItem.setID(myId); ; a! _- x1 I; u1 a8 Y" {
. H; T i* p& {9 c// Add the BOM structure. 5 J) O' O$ l2 v7 u# h
var bomItem = this.newItem("Part BOM","get"); - ^+ C% H& U; F% x, ]
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
. x" _7 B# l9 g7 j+ E% M4 Q9 k, FqryItem.addRelationship(bomItem); 5 m2 C' m, V8 u
* r. ~) Q% Y. v! q// Perform the query. 9 c& y) _) C' {6 h
var results = qryItem.apply(); 4 W8 M& w+ H3 t7 q/ n C& V
5 ^! Y1 p* [( C5 Y) Z// Test for an error. # ^! j: X- l/ w* O9 j
if (results.isError()) { e1 |/ r+ F# W, t. V0 L. \
top.aras.AlertError("Item not found: " + results.getErrorDetail());
' a- I9 P2 P2 j& v: r! C return; - f$ x! Q. ^# t3 ]
} , m( f2 K) U" u
- e! T; b9 q4 n7 j7 s: o. g4 A6 I// Get a handle to the BOM Items.
8 r. m) v* ]# Y2 |9 z4 [var bomItems = results.getRelationships(); 1 v2 @, _8 l. @$ U
var count = bomItems.getItemCount(); 1 S; Z, I) C7 }/ }
& l* c U3 @1 j; V2 A* H9 h* `# \+ M4 q// Create the results content.
, @; B: |7 @ v3 [0 |var content = "<table border='1'>" + 3 G4 D* ?- o9 }2 H
"<tr>" +
N3 ~! T( E L% J3 O7 ]5 S+ n4 A "<td>Part Number</td>" +
9 R, j. ~; q. }+ i5 r "<td>Description</td>" + & C4 N6 m8 l p J
"<td>Cost</td>" +
5 w5 f0 }/ a) |7 g2 x. n "<td>Quantity</td>" + ! `. U( \! F# o' h& ^4 g! J7 T
"</tr>"; / c9 o N2 D% u" k
% f; L' s: F, _+ Q// Iterate over the BOM Items.
( K! i7 ^; d, f- N. l' f/ `5 yfor (var i=0; i<count; ++i) % ?+ g- i5 w" }
{
) N2 D/ |: b+ n, k9 @// Get a handle to the relationship Item by index. % q" h/ H. J; m5 I ~- ^3 \
var bom = bomItems.getItemByIndex(i);
" Q9 e+ G) s2 I7 Y O4 v// Get a handle to the related Item for this relationship Item. ! f) V7 G# t$ f; l# H' i6 y
var bomPart = bom.getRelatedItem(); : v8 {$ ?" G2 J8 q- j' A# N
4 j4 @4 q! R! }9 e
content += "<tr>" +
8 S& J( y1 U5 L1 {. H. N8 K8 a( F: m "<td>" + bomPart.getProperty("item_number") + "</td>" +
) _& q+ h4 m9 _ "<td>" + bomPart.getProperty("description") + "</td>" +
4 f- I9 v4 R- A5 o "<td>" + bomPart.getProperty("cost") + "</td>" + # C# `, x& Z+ y
"<td>" + bom.getProperty("quantity") + "</td>" + 4 B7 L0 m* }1 l! G, k, P9 V
"</tr>"; 3 D' n3 T4 I& c8 |4 `8 U
}
2 b5 n9 d: }7 a. p! [1 a+ \ Breturn content + "</table>";
7 b% B! b, h2 Y) X o6 o7 N6 X2 k0 A. C; \' U5 ~: N, ^
" Y9 |3 z6 S" V# [5 n5 d0 p3 K$ i+ x3 D" M3 a, @
* d6 r; C0 {6 I5 N' n6 ^
C# ! t) ]! K$ Q5 S! R o! |& S {
Innovator innovator = this.newInnovator(); 1 E: t/ G% m6 @+ }5 R! _3 {
% C3 D4 z! m/ ^3 q1 T1 I
// Set up the query Item.
' H% M+ M g, z$ UItem qryItem = this.newItem("Part","get"); & X% y: Z& U) i N" L3 P
qryItem.setAttribute("select","item_number,description,cost"); # _( _- [* Y+ h: m3 f* K- U9 U
qryItem.setID(myId);
7 g" e0 H1 R4 ?3 ]! V 1 M3 D( Z% F4 ^
// Add the BOM structure. & {# T% Q9 a% j* K
Item bomItem = this.newItem("Part BOM","get"); 4 ?0 V; B6 U* Y8 r
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 8 o- e6 \5 l, }6 k
qryItem.addRelationship(bomItem);
' r z2 V& }3 L E 2 t+ z/ }7 ]2 }; @' v2 W6 s
// Perform the query.
2 f5 I. s `( iItem results = qryItem.apply(); 9 u" i$ C8 U$ T0 n
+ Y6 {6 x( y0 {+ \ w8 ~, M# K
// Test for an error.
. j0 L- i# Z( V" p; vif (results.isError()) {
1 L$ c, _, q1 `. }- O+ _# T return innovator.newError("Item not found: " + results.getErrorDetail()); - e1 `, p/ S6 n" ^ Y8 s9 t1 J
}
, S" v) C! Q( L , [, |, ~, N4 v& B; a( Q1 f* \7 X
// Get a handle to the BOM Items.
* D9 o# M; c1 Y. z: HItem bomItems = results.getRelationships();
/ v* {; i1 D! s; I9 [int count = bomItems.getItemCount();
. `# o* O' f# N* f, r! i* m6 V. uint i;
, p) C! ?8 q' X8 {
4 x3 b6 ~( l& z! K4 ]# }// Create the results content. w+ |1 T1 u8 u4 @0 z( |1 `
string content = "<table border='1'>" + 4 m' P6 H) o7 a, O( G1 P
"<tr>" + 9 F% {+ C9 f9 l \, p
"<td>Part Number</td>" + " r1 H, [" @. E% Z4 z: b+ G' h
"<td>Description</td>" + ' J1 A8 f) o0 y: b& b% y0 f
"<td>Cost</td>" + ; m% O6 T4 ]$ v6 S) w3 ~
"<td>Quantity</td>" +
h) b \2 U+ X+ A" b5 I- o "</tr>";
: K" w+ f. p/ d7 @7 D1 G
; o1 R8 k/ a; d, i// Iterate over the BOM Items.
( \7 B1 Q" Q3 p. c+ F$ qfor (i=0; i<count; ++i)
4 H; [: W$ o9 a( u. D{ 6 N8 t1 J8 M2 Q7 F( L
// Get a handle to the relationship Item by index. u' { l0 }3 L! S; s
Item bom = bomItems.getItemByIndex(i);
: T1 P8 F: }. O% L+ v// Get a handle to the related Item for this relationship Item.
9 W G, [/ c2 c2 V5 I; X+ z Item bomPart = bom.getRelatedItem();
3 m! v) u7 k5 Y8 g - O2 Y5 `: N$ z- Z
content += "" + ! T, l2 ], ?4 N( p6 e- o! T
"<tr>" +
4 M! C( a9 s; \* T5 x" X4 U "<td>" + bomPart.getProperty("item_number") + "</td>" +
' U0 O+ @4 }8 n0 C0 }4 R6 N) X8 Z+ }& S9 i "<td>" + bomPart.getProperty("description") + "</td>" +
" F2 s3 c! y/ g+ m- D" K, O "<td>" + bomPart.getProperty("cost") + "</td>" +
: W' W* J$ n5 G( O: h "<td>" + bom.getProperty("quantity") + "</td>" +
+ H6 Z5 k5 |" q: {# i "</tr>";
+ j7 x. |6 _$ ]& L8 x2 d}
( z; S+ ^" W' p S, g- F S: ~content += "</table>"; 9 B* M" A+ v& ^* u9 G& D: u( {! a0 d
! p. n. T- q; p$ I0 r
return innovator.newResult(content); % ]: k4 w( ?7 K/ Z
; N8 S/ ~3 g3 j1 A# K, N8 ~, r& L4 Z9 ]- U* u' Q% |) M6 {
; g( E. v3 M$ D2 f5 w: s) k) ?5 k5 _$ I& l1 S. Z
: c& y4 `) h, C; q
& `. k! R% @: `3 |( q, X % E) b$ U4 @( }5 G" v6 m
Page 46 2 @1 ?3 Z+ N) m, G. D1 R
" T6 T( u/ h: ]. RCopyright 2007 / K2 k. t( S0 Z6 \
Aras Corporation.
$ v# V, |" n8 `+ z) E: w) IAll Rights Reserved. 5 ^% X3 j& s X: G1 f) i& E, T! ]
VB.Net : M0 r# U" S+ a& l9 M a
Dim innovator As Innovator = Me.newInnovator()
3 W) M& u2 g' L( Z% |7 \7 ?/ r3 ~
* {" a- y, L1 T) P' Set up the query Item. : k) B) C2 ~1 T7 W# Q. ]0 g" K
Dim qryItem As Item = Me.newItem("Part","get")
@1 b2 i; P6 l4 t" q* q0 d" YqryItem.setAttribute("select","item_number,description,cost") 3 [1 B# L# u+ T9 ]
qryItem.setID(myId)
3 o; T! r8 ]3 Y2 \ d6 p3 K ( k' {$ M( [% E, O
' Add the BOM structure. 4 K: t) m! P, N. f) Q6 W; z! X6 W
Dim bomItem As Item = Me.newItem("Part BOM","get") 6 q# [) ~) o3 ?! S: K
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
5 F- A4 K' T* D$ E9 HqryItem.addRelationship(bomItem) / l/ j% L$ Q0 {3 O
! |) w( c+ o8 r
' Perform the query.
- \( k, ~3 C3 n" n3 ADim results As Item = qryItem.apply() h0 \ m2 Q7 Z0 H" @' F) \
9 e* w- G, k/ Z4 `9 b+ \, Q, P! j' Test for an error.
, v/ C, V9 U( g6 p( E' ~. UIf results.isError() Then
8 c" m* K+ X/ a& D6 W6 S# j Return innovator.newError(results.getErrorDetail()) 3 U6 E& p& T2 [8 V
End If ! v( ?9 h; Y7 b; l* m8 n
- [; U0 C y- u7 D/ O
' Get a handle to the BOM Items. ' ], j( t- J0 ], E) V( W
Dim bomItems As Item = results.getRelationships()
$ f6 e0 N$ w( O+ i6 v8 bDim count As Integer = bomItems.getItemCount() 1 r9 b7 G x0 M* j9 p0 s5 I
Dim i As Integer
: \& D& }6 p# y( z8 R5 F # _* z" r) t+ ~; S* o( L6 l. P( w9 c0 o
' Create the results content. ' E' ]/ |' g% P
Dim content As String = "<table border='1'>" + _
9 e" j; S* E* I, z: K "<tr>" + _
1 n0 y: f/ U) n1 l7 ?# }- P "<td>Part Number</td>" + _
! i, t3 d" H& N "<td>Description</td>" + _ : G2 V' p. u9 R4 y" }' _2 p8 \
"<td>Cost</td>" + _
' L9 h! t# B+ Z J "<td>Quantity</td>" + _ " d7 d: w. ?, R) x' {5 N
"</tr>"
$ i4 [- k% |3 @1 H- k
$ c; @' P& ^2 I; I/ Y9 U- ?' Iterate over the BOM Items
3 B1 { D6 B5 Z: UFor i = 0 To count - 1 4 \" T6 z7 H0 {; [2 M
' Get a handle to the relationship Item by index.
7 t) h& H5 d/ r* S Dim bom As Item = bomItems.getItemByIndex(i)
/ i) L; C6 G/ ^5 Y9 e/ J . h) o/ I7 G* z% [ q
' Get a handle to the related Item for this relationship Item.
5 f' K c8 M g9 C" o3 L; C Dim bomPart As Item = bom.getRelatedItem()
6 Q: Y! b8 a2 ^4 ?! r$ h( D, H& G9 Z
) H6 r2 \; i! P7 S2 d6 }' ]+ G content += _
' s1 {: r6 W( ?/ v" E, f6 m/ C "<tr>" + _
. l# I8 G! B+ p, N- h, @2 y "<td>" + bomPart.getProperty("item_number") + "</td>" + _
: Y' n" k( l4 H7 Q2 ~ "<td>" + bomPart.getProperty("description") + "</td>" + _ ' J! r0 [* R7 u/ q2 y) e* X# O
"<td>" + bomPart.getProperty("cost") + "</td>" + _ , P6 W2 [9 V+ u
"<td>" + bom.getProperty("quantity") + "</td>" + _ ( h/ O) w' w/ \" W) e( j0 b) V
"</tr>" ' r. B5 q' A J2 n7 ?8 |: |' {
Next 1 g$ Y: R% G5 E0 Y; F7 z
content += "</table>"
& L8 S: f* a+ w' g6 b A: i + T6 D4 _- O( x0 p L# F
Return innovator.newResult(content) : f% W/ n0 K7 J& ~3 I# A
, J$ T! `) s9 h( O |
|