|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
Technique - n( w* ?3 G. I$ y2 h& R& ~
To query for an Item and retrieve its structure you build the query as the structure 6 J+ }/ B1 Q( k7 I- ?
you want returned. Use the IOM methods to add the relationships you want and
+ P7 g0 Q0 _5 L5 Ibuild the structure in the Item. The server will return the structure that follows the 3 O+ |. o6 ]) Z! ]/ V; ^- v
request structure. - O- @" w( N! D$ w6 L7 }
This recipe illustrates several related concepts together, which are how to get a set 6 B& f2 q' x% P
of Items from an Item and how to iterate over the set, plus how to get the related
& @. ?3 C# K' y( JItem from the relationship Item. ( Y! L3 M5 M$ h0 t. d; ]0 T
JavaScript
7 W( M6 |; Z$ d& nvar innovator = this.newInnovator(); 3 U- m, h$ D8 A' P+ f
' z9 K1 B. B: Y: w// Set up the query Item. , |1 ?$ Y# s+ X3 ?
var qryItem = this.newItem("Part","get"); _# Q/ n: t2 W; V
qryItem.setAttribute("select","item_number,description,cost");
' k9 E- z" ?" @/ s0 F+ D% n$ UqryItem.setID(myId); : @# \* K( r: M$ c5 o" w. j; Y
$ W- y* v" G. V2 X// Add the BOM structure.
' B* u- Q) `5 _* P- ivar bomItem = this.newItem("Part BOM","get"); $ _# T$ E. c! w; B
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); . O" C5 g" } [0 K
qryItem.addRelationship(bomItem); + P3 Z) Q. ?! C1 O
' c+ S8 O0 w5 O* t// Perform the query.
6 g/ U$ a6 ]8 F% K) e7 \3 h; xvar results = qryItem.apply(); " v' L* }. E( t4 p/ F6 J0 K* Y2 M
) a! V. R# p, C% `3 b// Test for an error.
; H" J3 M" q8 Q! t% qif (results.isError()) { : ]( U) t/ R J1 k/ o4 k
top.aras.AlertError("Item not found: " + results.getErrorDetail()); * _9 J9 m! w* a! ?0 [. H
return;
4 g4 \0 n+ A& j}
% \8 f$ j% }" D$ o; f5 i5 @
5 X% Z, h* W5 u0 a, P7 @7 w// Get a handle to the BOM Items.
0 s, L0 J4 ?1 x5 bvar bomItems = results.getRelationships(); . F* X$ |$ Z1 x- k' w$ g
var count = bomItems.getItemCount();
! N1 N. ]( {- `* K! E7 C1 d3 w " K& V# [) v- U- ]8 A
// Create the results content.
- A% X4 P- m% j( lvar content = "<table border='1'>" + + I' v6 ~" L0 y& U, m& u+ O
"<tr>" +
) m q) M( Q# T( ?+ M: x8 }" l "<td>Part Number</td>" +
, g. Y( m) `6 a- g, E; f" m "<td>Description</td>" +
: H: U8 R0 V* \" C* u! S "<td>Cost</td>" +
9 M: [( n& |" ^/ P3 p "<td>Quantity</td>" + # P9 Z# ^8 [/ }4 F E& n8 x
"</tr>"; : \6 Y: j7 n, X: l4 M8 J' e
: d" v# Z5 a- |# ]/ V1 [" m// Iterate over the BOM Items. 7 G3 J8 C W* K. Z% \6 N" p( d
for (var i=0; i<count; ++i) 7 ?5 N6 P+ o% s% c& b; C" j
{
1 e( ] Q5 H1 q; Q( Y// Get a handle to the relationship Item by index.
* B! F$ b+ ?1 U5 F q9 ]: D8 k var bom = bomItems.getItemByIndex(i); 5 c3 `0 F0 ? k; c! r
// Get a handle to the related Item for this relationship Item. 9 T0 ?8 }5 ?; O, ?# Q$ c2 w8 v1 V* o
var bomPart = bom.getRelatedItem();
0 H. g2 }5 G h' _/ ^! z/ u
# ]+ K3 _2 @& b. V# O5 H content += "<tr>" + # E9 t. b" P2 X, V: [) X
"<td>" + bomPart.getProperty("item_number") + "</td>" + ; O( L2 V4 g- _* ~8 @! M
"<td>" + bomPart.getProperty("description") + "</td>" +
2 S* X. Q& Q- C) n/ k& T "<td>" + bomPart.getProperty("cost") + "</td>" + 9 S3 l+ q# ]3 T0 n) w# B, b
"<td>" + bom.getProperty("quantity") + "</td>" +
0 G8 |/ S- Y3 t! m "</tr>"; - G# U4 o, ?2 {$ x2 Y( m6 ?' m x
} % H: B6 j' B+ v: L2 M! `
return content + "</table>";
6 c8 a. i, c2 u3 \4 {' c7 l1 P& h& C' F
; p. [, |/ {. B
* M* p, }$ b0 U K' E
1 O% ~$ b3 b+ m. p* H& c7 m @C# 6 [5 k; M" o1 N& g; R# F r
Innovator innovator = this.newInnovator();
7 ^2 b3 O/ m+ j
& [% }# ^! q& d4 f3 Z// Set up the query Item. * v; P0 I7 F6 v, ^4 l
Item qryItem = this.newItem("Part","get"); 4 A2 H1 a+ v- S. O7 `0 q2 |
qryItem.setAttribute("select","item_number,description,cost");
" b& o& T* |# C2 P( e' yqryItem.setID(myId); 4 @' ?* Z1 g' i2 S. y
! X5 S6 E6 |7 {: X4 k. P
// Add the BOM structure. 8 ~3 Q- R0 Q4 H" B/ }
Item bomItem = this.newItem("Part BOM","get");
4 ~/ W+ |8 i% Q& u+ [, ]bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
7 z+ @& q: o0 N9 wqryItem.addRelationship(bomItem);
1 ]0 ~6 d/ w" [( o9 a7 c* j4 r ) L# U9 _" F$ k. K7 @
// Perform the query. 2 c A9 R, o! |5 z5 T0 u+ |
Item results = qryItem.apply(); 6 x O8 C8 W4 b2 t/ v/ V& }/ T
; o" ~# u ^, H5 f
// Test for an error.
9 `- V8 r3 w& `% Z: M7 pif (results.isError()) { . L1 W. h! |! L1 J
return innovator.newError("Item not found: " + results.getErrorDetail()); / e4 K, }5 g/ j
} # F0 B+ A8 a7 Y: q& d
6 W* e+ C% K. M- v# X* c' t0 ~// Get a handle to the BOM Items. 9 h& U, a1 k0 h- [
Item bomItems = results.getRelationships(); + |+ T3 ?9 |4 K# m+ W
int count = bomItems.getItemCount();
* C, F# C& n3 n; G( w2 F5 Yint i;
( n8 e9 y; w$ M, P. M: c
, V9 {9 b+ j- Y6 H& l* \2 h// Create the results content. & [; h2 D) ^; Z2 ?; z
string content = "<table border='1'>" +
3 B. p( R; g @: _% q! b n "<tr>" + . M5 p9 T- b0 I* `1 O% i& R+ I
"<td>Part Number</td>" + w( e. z& C* i- J
"<td>Description</td>" + $ `9 v& Y% G$ V; S7 S) H5 T
"<td>Cost</td>" +
0 a4 i: |, f; } ?9 @! [ "<td>Quantity</td>" + * K* z* J/ i4 y$ @4 U
"</tr>"; : Q0 ]) z% [0 B% ?. L
2 ^. q# H, |2 y8 G9 n% r// Iterate over the BOM Items.
/ E% b" y- }6 n6 c$ N1 E$ U2 @/ }for (i=0; i<count; ++i)
$ |8 {5 I# ?/ R6 X3 ?" v0 y, r8 J{ 3 b$ T ]' U6 ]! f! @2 Y: P
// Get a handle to the relationship Item by index. 4 V4 F( _+ i( R2 e. W. {
Item bom = bomItems.getItemByIndex(i);
0 p) V N _9 V b- x// Get a handle to the related Item for this relationship Item.
" |/ i& b6 N6 k2 {# x9 {6 V Item bomPart = bom.getRelatedItem();
$ K2 U- ^, b' x! g " A" R J V2 _( `& o8 U" H% s
content += "" +
0 {! _1 K4 i# P0 j2 ~9 ] "<tr>" +
& e+ p/ @, J0 \3 e( c; G5 |3 q/ ] "<td>" + bomPart.getProperty("item_number") + "</td>" +
1 a9 U4 |+ i0 h "<td>" + bomPart.getProperty("description") + "</td>" +
" j5 n. Q, U% D" u& Y6 K' E) f "<td>" + bomPart.getProperty("cost") + "</td>" + 6 @+ z' s& [9 q* L
"<td>" + bom.getProperty("quantity") + "</td>" +
: {) c; e* N% d- b" x "</tr>";
. b0 \2 g2 D, t} 8 ^* q9 Y, _$ x) V2 e, U C
content += "</table>"; 2 Y$ e+ t$ e: I8 C1 [
9 ] N9 o1 g" a H' i( f+ U$ F
return innovator.newResult(content); , B% {1 Y8 G5 j
! k: n* k8 S+ i5 R4 y. y
% `" R# R2 M. Y* a% a
. z. `4 C& u! q; U" A/ L
. w7 r& K) S- {( `! a
0 y; h& ^4 g% v4 ?4 W) Y
7 V1 ]/ @2 V: ?6 w2 S& ] - t6 \$ j f% O6 U' S; q" S0 E }
Page 46 & k) p) F/ E& j6 a9 J
1 t- D: d8 V- ]* P" L7 VCopyright 2007 " w0 r f; S7 O
Aras Corporation. , h; T _" u: Z" S& q
All Rights Reserved. 1 T; E+ q' z- F' B
VB.Net
6 \/ x, w7 H! ^+ Z5 s6 i; dDim innovator As Innovator = Me.newInnovator() ! p! t# a3 g5 \" A. E
2 j+ L" g ?& F: ]
' Set up the query Item. 7 q. J' v9 t6 F2 b
Dim qryItem As Item = Me.newItem("Part","get")
: t. r& g( G, Y! {6 PqryItem.setAttribute("select","item_number,description,cost") 3 ~2 |7 k* r# b4 b$ _7 {% [
qryItem.setID(myId) ^/ |$ f6 p: x3 z7 s8 h5 S
6 ~, z" m% J ~8 ~. d
' Add the BOM structure.
, W9 b1 T5 \! B7 GDim bomItem As Item = Me.newItem("Part BOM","get") 4 i8 K: z( B5 y; i" V, [3 q% j
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
; q$ j/ z; V' Z7 s5 s7 ]7 ZqryItem.addRelationship(bomItem)
% f2 R. M* Q. V" p/ b8 s * N) d7 E' R; p/ o5 R, M4 G0 U+ ?8 _
' Perform the query.
, a `4 O N! ]+ r4 v) PDim results As Item = qryItem.apply()
+ s( }3 e9 q. i- h : O4 w, m! A$ U6 E$ F& J
' Test for an error.
! d+ M7 ?# L5 a; f/ l+ k) uIf results.isError() Then . B0 L7 G9 |' A
Return innovator.newError(results.getErrorDetail()) 7 l0 P3 X- k6 I7 S. R
End If $ h1 c$ T; S# R; Y
+ r* @5 Y* q3 F! f" P0 B
' Get a handle to the BOM Items.
3 U, W0 ]) A& }% V* |- tDim bomItems As Item = results.getRelationships() + `6 T- o- Y8 U9 Q1 N
Dim count As Integer = bomItems.getItemCount() " C3 }( ~: V9 w
Dim i As Integer 5 t" D1 |+ R0 T8 K7 k# r2 G
2 V+ }- A/ a' H8 B1 w; H a
' Create the results content. " n9 j# b% ^$ O& F' X- O# Q! a
Dim content As String = "<table border='1'>" + _
~8 K% m* f8 E "<tr>" + _
* q9 N5 T/ X9 p) ^4 r "<td>Part Number</td>" + _
9 u& {; w/ L1 Z1 ]1 _ "<td>Description</td>" + _
6 e7 I( M# m) ]; A6 G1 J "<td>Cost</td>" + _ " ]0 v9 G! o- k
"<td>Quantity</td>" + _
* D- Y& ?, q- W5 O "</tr>"
6 y P: _/ r& M" W2 l( F h . X5 @* P! X! b+ }" _/ N
' Iterate over the BOM Items
; o' x8 Z b6 N( n' c, @6 OFor i = 0 To count - 1 0 V+ r9 k% U& F) `$ n8 s: x2 u
' Get a handle to the relationship Item by index. % N' y w. q5 d6 v8 e9 [
Dim bom As Item = bomItems.getItemByIndex(i) ' R4 c' X" `) k; q, Y
- C) G8 e$ _" K; ]' Get a handle to the related Item for this relationship Item. ; U2 L- _+ o2 j9 F$ r
Dim bomPart As Item = bom.getRelatedItem() 5 e6 w4 G0 e' N! h, y2 _
+ ^- ?' ^3 D9 R- C- J
content += _
. k4 l$ |$ d* v. n" d "<tr>" + _ * h# d% [4 j" r
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
% R ]8 [' {3 N+ j6 q5 Q6 M "<td>" + bomPart.getProperty("description") + "</td>" + _
9 K* s! j4 T) p w# x, R "<td>" + bomPart.getProperty("cost") + "</td>" + _ q8 N- l! m3 h( K
"<td>" + bom.getProperty("quantity") + "</td>" + _ 5 y4 J0 Z8 _! c0 |- K/ S
"</tr>" # Y% z( O! b0 @6 E2 v
Next
" h, N3 g. E3 e" Qcontent += "</table>"
% i; s$ n d0 U: U% Z- m, O) u
0 S" \, J. M! u/ W7 T- ~" X! k' P: nReturn innovator.newResult(content) " `- z( x# A3 b; Q
! ^0 e w: P. Z- s
|
|