|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
0 o. d# _7 O6 m8 R5 t2 s2 mTo query for an Item and retrieve its structure you build the query as the structure
/ z. y3 M- H3 S; A; `) \/ O2 zyou want returned. Use the IOM methods to add the relationships you want and
2 u/ Q6 [ E. D" C1 Pbuild the structure in the Item. The server will return the structure that follows the $ C/ {7 C! ^5 O; s2 f0 @3 \( E A2 w, v; L
request structure. ; m: k$ q" S. t( Q6 T# c0 f- B
This recipe illustrates several related concepts together, which are how to get a set : C9 u( H2 b, Y L2 g6 d/ [
of Items from an Item and how to iterate over the set, plus how to get the related
" i1 o/ Z6 g+ W l# G+ ~Item from the relationship Item.
. Q' G& q9 Z' y. H: ?( l) O% U; M" NJavaScript ' W$ I" v0 b& S4 A; U; j6 [+ o, _
var innovator = this.newInnovator();
2 i& q+ {* @6 H; V& T4 `0 ^ . D' _ H& m/ D( y7 \
// Set up the query Item.
+ L1 W) J1 o3 e" ]3 X* u3 uvar qryItem = this.newItem("Part","get"); 8 a8 _1 H8 V0 R. e
qryItem.setAttribute("select","item_number,description,cost"); . `/ U7 u5 R, s- y- K( |
qryItem.setID(myId); - P' U" \# E7 L5 a: Q* N' S4 u8 E4 i
, l4 [! f) o0 ?2 A' Z1 l// Add the BOM structure. 2 Y6 y0 j1 D$ B. S: M) e
var bomItem = this.newItem("Part BOM","get");
+ U n: [# E9 z5 Z f. FbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); % B. N6 Q/ a b3 q
qryItem.addRelationship(bomItem);
9 S' R" |5 C" B8 r2 y1 ~( ?( P
+ r2 ?9 p: S& `6 A// Perform the query. 8 Y; C3 F0 c% x) T/ u5 z. G0 P" k
var results = qryItem.apply();
1 W% f% c$ B, v" W) y: L$ m
/ |" r( ]; x5 z// Test for an error.
5 E( w/ ]$ E9 Vif (results.isError()) { 6 \+ Q$ G- D: k* M6 X4 U
top.aras.AlertError("Item not found: " + results.getErrorDetail());
% ^. D2 W7 J* E8 W4 F% K& ~7 `. o return; ; `7 |; [+ E; \7 C
}
4 s* V1 h3 x0 @) C+ O 9 g- M: H0 v0 W
// Get a handle to the BOM Items. + N# I3 I4 G7 s' |% T
var bomItems = results.getRelationships(); 1 E: D* \2 F+ H! y5 Y9 G: q
var count = bomItems.getItemCount();
$ L! c+ J% n- m$ G " Q1 V! V: v5 }+ R9 @7 ?' s6 c: O0 T
// Create the results content. $ m4 c1 S$ _' ^% f: z
var content = "<table border='1'>" + 4 L# G! s @ M8 U8 z5 {% L# N4 L% L
"<tr>" +
+ {8 L. L8 k) Y. K0 D5 L2 u "<td>Part Number</td>" +
9 r* I2 E r$ n "<td>Description</td>" + % T" A# |4 E0 Q) P
"<td>Cost</td>" +
1 {3 \ p2 X- L- w8 i! _. z' x "<td>Quantity</td>" + 6 q' D. T, a3 V
"</tr>";
& A% ^ _. G' s* a7 ]8 { 8 n, c, l* m* t2 K0 T; c
// Iterate over the BOM Items. / A/ ~5 I2 n/ V* Q. p+ b4 I( a! l Y" B: K
for (var i=0; i<count; ++i) ; M, f! A% A9 a6 F
{
! e; g0 d2 v' a" y1 q( Q: e// Get a handle to the relationship Item by index.
8 Y* ^5 v: ?+ o+ r+ S var bom = bomItems.getItemByIndex(i);
' ?3 s- V: U; i+ [/ Q// Get a handle to the related Item for this relationship Item.
. b: S X; L0 z/ _ var bomPart = bom.getRelatedItem(); ' x8 M1 y/ V- H# F4 q
5 h( t2 `# f0 E: `& N. e1 A6 F r content += "<tr>" +
; s, U4 X+ `( X# m- J4 ^: [ "<td>" + bomPart.getProperty("item_number") + "</td>" + % a+ k. n+ Z' ]+ ?
"<td>" + bomPart.getProperty("description") + "</td>" + ; \1 w6 o6 D$ H% Q
"<td>" + bomPart.getProperty("cost") + "</td>" +
/ A- E9 S# X1 o! } "<td>" + bom.getProperty("quantity") + "</td>" + & y- D2 @1 L& H; }$ B
"</tr>"; ( p C6 E% D+ ]; k3 C; g' N r3 Q
} 3 E) A( W8 E/ A. a
return content + "</table>";4 \/ H" {4 ^+ ]) r1 S. y. e; R6 d
3 p h# u" d2 ]/ F/ e8 S
. J" j* w6 w9 f
* ]' d) o: H( ?
% C; J' t" E. \' P$ |2 rC#
3 V7 k3 o7 L, HInnovator innovator = this.newInnovator(); 3 s+ }$ w) z, l- Q$ ^' G
6 Y, \+ O$ ~$ L3 A0 A2 g
// Set up the query Item. ' U; i0 A( t' Y* H3 ^; o
Item qryItem = this.newItem("Part","get");
1 C9 r6 W+ B' Z' R& R) PqryItem.setAttribute("select","item_number,description,cost");
; e/ C6 O1 w* ^& p* ^# V9 Q# NqryItem.setID(myId); ' f' d3 r& j, X
! ^" ?, z* E- L7 O
// Add the BOM structure. 7 q, P/ Y/ }8 z+ C% W& p
Item bomItem = this.newItem("Part BOM","get"); ! z8 k# z, V/ J1 I8 w$ O* \: W9 K
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
& h" N! n$ d3 h# sqryItem.addRelationship(bomItem); ' [- L( o9 I1 ]1 y$ ~
' d9 k0 L8 P- ^// Perform the query. ! Z6 w& I, z; V
Item results = qryItem.apply(); + s" k& E# r/ ~( d, \! _1 N
( n" o% i0 A4 Y. o" `6 Y( n2 j5 I// Test for an error.
/ Y6 [& F; D4 o: A& N1 Bif (results.isError()) {
9 H, K. t$ T% g; v- V return innovator.newError("Item not found: " + results.getErrorDetail());
+ D4 t* D! x1 h% m$ l} 2 G6 \# S% s8 l# z6 n6 R
. M: K" ~9 e3 ]- T* G: ?2 R5 h
// Get a handle to the BOM Items. % s( l4 n. |3 S6 S" w+ f
Item bomItems = results.getRelationships();
6 E! }6 u8 B3 v8 _% Fint count = bomItems.getItemCount(); 9 n5 N9 _$ U8 J/ i/ l- O4 B
int i;
7 c" O$ l' X- ? 4 ^ c, R$ r7 A7 ]/ A
// Create the results content. . ?! `2 V# j* |7 _* ?7 R
string content = "<table border='1'>" +
1 o6 ?# ]- H4 S1 s8 |# `. K "<tr>" + - d" j n# W, P5 S& o3 `
"<td>Part Number</td>" +
: Z; d* j7 T9 |5 Q' i% N "<td>Description</td>" + 9 }' q" l3 w1 X" R, G8 z
"<td>Cost</td>" +
. @6 |. f1 ^5 T' ` "<td>Quantity</td>" +
" u- b3 f9 h5 K% M( b "</tr>";
* x$ S" ~1 \: K" ]
( G e0 Y, z J' l) P& O7 n// Iterate over the BOM Items. ; R4 s. T& k# ^0 a
for (i=0; i<count; ++i) " S2 P! @& H% J! [! E5 H1 d+ X2 y6 E
{
- U% `2 B9 _; a0 q, p8 B* X' u( T8 e// Get a handle to the relationship Item by index.
% B) l% C3 U6 v% r, [1 V Item bom = bomItems.getItemByIndex(i);
9 P O9 a8 m* d9 K9 p// Get a handle to the related Item for this relationship Item.
' {/ f( m8 T6 l* ^ Item bomPart = bom.getRelatedItem();
% m, r7 u' i ~. @$ K , k( ~; |; M2 o5 A
content += "" + 2 A3 ~( `) v. d, M
"<tr>" +
) o8 a; M# ?' B9 A/ Y9 U "<td>" + bomPart.getProperty("item_number") + "</td>" +
: M* `* f$ {9 { u "<td>" + bomPart.getProperty("description") + "</td>" +
) f p' e6 ~# M" N S6 l! G0 i "<td>" + bomPart.getProperty("cost") + "</td>" +
" C6 P# g1 [* \6 t6 P "<td>" + bom.getProperty("quantity") + "</td>" +
7 C1 @$ J: }2 H3 ?" w* b "</tr>"; ; h8 n1 g; q$ f/ ~) k( g/ T' ^
}
' }3 m+ Y% j- R6 o* b3 a& ccontent += "</table>"; 7 q0 Q. l5 B' ^7 j& f
`) d/ h6 Y* {9 K& v, Ureturn innovator.newResult(content);
0 p7 @0 l' W- h6 m" F! O* x5 N& b. k2 D# j7 P# `
: v- j6 F) A7 u1 j. a! W9 z
4 m$ h- ^. p6 F) I5 K8 p8 t; k9 K1 ^! q4 |6 V: h
" g V2 L" q& B: z* n
: p, x6 V# |$ v8 r
9 X: U7 r6 B* H) G( L# I2 I
Page 46 + N+ m7 k7 y2 |- g& i. X* X
) s' J& X- L; V4 F2 oCopyright 2007
, x0 w+ T6 K! d! c2 v" |Aras Corporation. 7 G" d8 @3 W. k
All Rights Reserved. ) B( z) e0 [' d5 O5 W0 _+ ?
VB.Net " ~! V& Y) @$ |# L/ v
Dim innovator As Innovator = Me.newInnovator() - B! q4 x2 H! H
( M( D0 u) w2 H) u/ o! |
' Set up the query Item. & w1 R4 h; V5 U. V7 |0 h' c
Dim qryItem As Item = Me.newItem("Part","get")
6 F J+ T9 A+ i9 L& |( I2 O4 AqryItem.setAttribute("select","item_number,description,cost") 8 j6 r c) n+ e: d$ f8 d
qryItem.setID(myId)
* r: z7 L8 f4 V( L% V
7 b0 \6 u$ g( v& n' Add the BOM structure.
8 n( E: ~ F l- b w9 C0 V4 [Dim bomItem As Item = Me.newItem("Part BOM","get")
2 j3 b' ?# Z' i: N$ ?, ibomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
/ q5 U" @0 `- h* z/ H, O. L/ jqryItem.addRelationship(bomItem)
# z+ c$ p! l h6 P' C- \7 S. t
' e+ y6 ^; W$ z2 L' Perform the query.
% o' q0 F7 G- ?5 YDim results As Item = qryItem.apply()
$ O8 y2 |& t$ Q4 l) h ! J& f: K6 q! h) T. T
' Test for an error. & K* K. ?* z# H/ }+ w
If results.isError() Then
9 v* c' q( M; y( H( K Return innovator.newError(results.getErrorDetail())
9 d8 K; P- |) s, X$ VEnd If $ @* k5 ^% g/ d) D% N2 k
' ~ P c% z4 i' Get a handle to the BOM Items.
6 M% | \2 N+ y+ j( X5 hDim bomItems As Item = results.getRelationships() / s7 R- G& b9 `% h/ m
Dim count As Integer = bomItems.getItemCount()
! P0 ^+ C0 s) BDim i As Integer
& N1 q& X. J. q) D: j) H% f7 A" ?
' w( A7 I+ Q" g- b, j5 P' Create the results content. . I2 x9 i) F Q H
Dim content As String = "<table border='1'>" + _
2 {/ Y0 z$ v% B; a D5 M6 u4 j "<tr>" + _
; v; a& Q; s5 A+ p "<td>Part Number</td>" + _ * @# E7 q! b$ p9 a& Y; F
"<td>Description</td>" + _
# m/ `& f* L% e; j& D% C "<td>Cost</td>" + _
4 e6 o: k# G, d! u; j3 p, b& m "<td>Quantity</td>" + _ & C, A1 l3 F9 ^0 Q" @$ z
"</tr>" 6 a: p7 f6 ?7 u! O3 }+ n
2 K: j' r3 C1 K/ A! A& P3 p/ g' Iterate over the BOM Items
2 p; Q5 w9 ` }, p. FFor i = 0 To count - 1 3 _5 ^( m2 n, Q* D% k$ J7 c( l8 T% x
' Get a handle to the relationship Item by index.
* s5 g8 @% ?+ J- Y2 \) k Dim bom As Item = bomItems.getItemByIndex(i) % m q/ T* K9 K8 x8 M1 a7 i" w
( L* q5 W1 H0 ~. f. U' Get a handle to the related Item for this relationship Item. . x+ c) D/ n/ i3 z
Dim bomPart As Item = bom.getRelatedItem()
E1 n( {! h9 Z {! i
% n; M: V' U+ P2 [$ J4 l content += _ 0 v a Q# u0 _ ~
"<tr>" + _
5 G$ R; ?/ ?. K) U/ e* a. s, X9 I "<td>" + bomPart.getProperty("item_number") + "</td>" + _
. e# A' a3 H3 J& O "<td>" + bomPart.getProperty("description") + "</td>" + _
" m6 O( V, c9 X+ G4 }& @ "<td>" + bomPart.getProperty("cost") + "</td>" + _
0 E, C/ N6 F+ D! n/ `7 {, L% s5 R% P "<td>" + bom.getProperty("quantity") + "</td>" + _ 8 Q7 V" l) J* m$ k. E. }6 D
"</tr>" 3 @& n5 W# Z0 E* U
Next
6 |3 j1 l# l0 r4 D4 Ccontent += "</table>"
+ ]2 g& \/ y$ h7 s1 F
* O K& |0 a0 V: N) u1 FReturn innovator.newResult(content)
1 A: Y9 Q; n* C" e- _' @$ d4 Y5 c2 z! e& E. i; P' f3 s* g0 I! c
|
|