|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique & E- Z3 ]' d; E- m
To query for an Item and retrieve its structure you build the query as the structure
* Q& y! h' S2 C iyou want returned. Use the IOM methods to add the relationships you want and * U& b, @9 ~5 P# p
build the structure in the Item. The server will return the structure that follows the 5 T( ~7 B5 H* T6 y& r% S& S; O
request structure.
4 K. Q/ `/ T) \3 w2 V8 CThis recipe illustrates several related concepts together, which are how to get a set
6 t& M% I. K k+ e/ J2 F( O5 ]of Items from an Item and how to iterate over the set, plus how to get the related ! M: p O1 |7 R5 i* U' }# Y) G+ S
Item from the relationship Item.
8 \) G4 E7 m2 o+ t5 n5 K' JJavaScript
+ Q# B; o& ?8 T3 g7 Nvar innovator = this.newInnovator(); 6 P; s1 S4 v- y. y1 N& E% L' E9 P
: U* r1 x" R% s2 \9 Y9 O2 _
// Set up the query Item.
# ~! J$ S& h7 I' D; lvar qryItem = this.newItem("Part","get");
& a) C: L% v8 S3 Q8 j8 gqryItem.setAttribute("select","item_number,description,cost"); 5 X: j, u( p. [4 i# B9 q0 p
qryItem.setID(myId); $ R0 R1 J! ^1 Q- k8 s
# `, Z4 @ C- ~6 C8 r: P// Add the BOM structure. j( B* [" W# l* |+ P
var bomItem = this.newItem("Part BOM","get"); 7 @/ y* | ~( _: v5 Q( [- k6 U
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); . k% w5 y( ] _6 P
qryItem.addRelationship(bomItem); % R1 t% v C% U# M
; E+ U' i- T6 |1 P0 @/ p// Perform the query.
9 D; e3 Z( a; G- Uvar results = qryItem.apply();
: j: D, m9 f; l5 y( F4 r
5 u( S+ R: z8 Z" Z# Y: N6 B// Test for an error.
% a& B$ l6 h6 d/ r6 `3 u n6 }if (results.isError()) {
; g7 l# n- b4 ~& B% w, U1 p top.aras.AlertError("Item not found: " + results.getErrorDetail()); I7 c' ^" B- U9 F; J
return; " \" X% b4 `. X' H- r
}
/ C* @/ p2 E: H
. v1 H) E" f* k5 }" [' g" k// Get a handle to the BOM Items. " s: k- [1 e9 t: \* J' Z# `
var bomItems = results.getRelationships(); : P+ i5 a# Y3 j; c
var count = bomItems.getItemCount(); & u$ W* q0 A. U. l: h0 T! u4 Z% t
8 M3 N) b' P1 `- R! o" f7 Q! P// Create the results content. % ~ E' @% V( @- G
var content = "<table border='1'>" + ! Z; j+ u7 V$ {' ~
"<tr>" +
( a; }4 |. f" `- a5 E "<td>Part Number</td>" +
3 n' I4 m$ T! u" [ "<td>Description</td>" +
! O" u7 {9 b" z; w6 ] "<td>Cost</td>" +
3 u2 k1 _, Q/ e5 J+ H5 z "<td>Quantity</td>" + " p9 I+ u( o& d& I8 H+ ? T
"</tr>";
3 [8 T5 T8 n( y5 m, Y+ Z$ e0 u 7 O; F, j$ R' Y$ v7 u2 d" V' Z
// Iterate over the BOM Items.
6 z0 l6 I! c7 q+ l6 Ifor (var i=0; i<count; ++i)
$ s& _' g K+ v{ 6 r" r; F) ]' f6 \0 }
// Get a handle to the relationship Item by index. * \6 A+ M5 G4 S
var bom = bomItems.getItemByIndex(i);
( H- p: Y- }. z" u3 ]// Get a handle to the related Item for this relationship Item.
1 C$ b# J/ F1 h- n: D% I, z- ], e var bomPart = bom.getRelatedItem();
, k9 o4 _! z2 P1 r. z , O t- v; ~0 ?
content += "<tr>" + 5 {" [ C8 t# g- K4 b, j
"<td>" + bomPart.getProperty("item_number") + "</td>" + 1 I: U, S& s" _
"<td>" + bomPart.getProperty("description") + "</td>" +
% l" E# I! d- O! I3 b "<td>" + bomPart.getProperty("cost") + "</td>" + % }, h. R4 B, \
"<td>" + bom.getProperty("quantity") + "</td>" + 9 Z; t% p) j* t- Z" p' X5 F$ ?
"</tr>"; 1 d M0 g2 X$ @' [5 H
}
9 W, K1 S; @/ p! vreturn content + "</table>";! ^* F% @4 ]9 B: ~2 G% z8 i$ K' n
: h* q! q3 H2 [
3 `$ N& s2 A4 U; l& ?0 m6 K. z% v, }
) O7 y4 m; t" q5 z/ b5 h4 }' n9 u3 ]
2 E: }; ?- ?% l6 `& J) b; Y, g$ ]C#
, P2 e: S# x) i4 QInnovator innovator = this.newInnovator(); 5 z$ i. X/ V* V! c
( {- H* d3 S5 \, v0 f* r
// Set up the query Item. 8 }0 T! k' e1 [* E- A
Item qryItem = this.newItem("Part","get");
# s# k7 S0 O8 s0 L& D) D) `qryItem.setAttribute("select","item_number,description,cost"); ) _: b" D8 S7 d* P, ^* O5 E; q3 a
qryItem.setID(myId); ) b* A0 U! G/ t: w' u% D4 ]
+ K a) i' v3 W) o) W// Add the BOM structure. 3 ^& [. X- j, d% l$ x D% q+ T
Item bomItem = this.newItem("Part BOM","get"); + h7 |* [1 l5 ]
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
( a* S" Z% E& K9 ~0 hqryItem.addRelationship(bomItem);
) ?' M5 F7 O7 j$ w 9 n8 E8 V0 Y7 Z% S
// Perform the query. / }; R5 o* U% H1 X
Item results = qryItem.apply();
, M% o. M! T) Y$ l: z " y f5 w; [: P4 E3 B
// Test for an error. ' C* u+ t- z% |
if (results.isError()) { 3 Z. K* k( C4 S6 ?* O/ ~
return innovator.newError("Item not found: " + results.getErrorDetail()); ( |0 M' K7 f3 f# _# l
}
3 M) O6 P- u8 x ; J; \- v2 k0 f- H
// Get a handle to the BOM Items.
, `* M# D: }- Z" Y' P& u$ EItem bomItems = results.getRelationships(); 9 n: E" u+ `4 a/ Z) t- U
int count = bomItems.getItemCount(); # e2 r2 [5 o, A7 H, T2 P. ^
int i;
4 q% I4 Q' |. m4 d8 E5 K" K4 g ! ^2 }+ ~6 [* c, S
// Create the results content.
4 @1 f% |6 T# H& i9 O" a2 pstring content = "<table border='1'>" + ! N& q ] a6 u Q/ n. ?" n! f- X
"<tr>" +
( t" ?6 {: D+ r- T/ S, r6 r "<td>Part Number</td>" + 2 w1 S* _( q# H& e1 R1 S
"<td>Description</td>" + 7 b6 ^1 n$ j, n
"<td>Cost</td>" + @3 n- D% g1 J& ~5 @
"<td>Quantity</td>" +
1 m5 H5 }# m$ B- \ "</tr>";
7 i4 M- ~- Q! }7 O5 s 8 Q8 A, ]) P' K' Q3 z4 E3 s# b
// Iterate over the BOM Items. ; h9 d$ ~) p5 m6 k4 A8 T( H
for (i=0; i<count; ++i) ' i% W: O5 O; U. U4 J. f: u4 Y
{
8 a4 i+ j6 _7 a0 _! [2 v// Get a handle to the relationship Item by index.
, `7 G# R; ^% h) o: ?% W; O" ] Item bom = bomItems.getItemByIndex(i); # {% }+ o8 F0 f# e' W; b) V3 j
// Get a handle to the related Item for this relationship Item. & R$ u$ @5 x" |# @) v, Y; t: D" @
Item bomPart = bom.getRelatedItem(); 4 M% |- }9 d9 X5 ^& Z; Z: b: E; t
W$ M! ^' O& U. C; P content += "" +
: V& y+ i; x* B$ R) n "<tr>" + q2 U8 |+ F& }
"<td>" + bomPart.getProperty("item_number") + "</td>" + # r4 R E S9 K
"<td>" + bomPart.getProperty("description") + "</td>" +
_" p6 q! l( Q; X1 H2 P "<td>" + bomPart.getProperty("cost") + "</td>" +
/ F- A0 p! e4 K5 {3 |( V1 M "<td>" + bom.getProperty("quantity") + "</td>" +
w) u( ?3 r$ C, Y) q/ A1 f w$ e "</tr>";
2 {( l: N, e2 v2 G3 Y0 }; a9 c}
$ X/ Q$ j7 z8 x2 t# ~( L; E. v6 Kcontent += "</table>"; ' n8 R" b, v2 n! v! X. G
F0 x; T8 [ rreturn innovator.newResult(content);
! Q1 P: y6 H% r2 n6 E" _) I0 f; `$ I8 q# K. U+ E+ `6 H* i+ {3 t$ x
1 [) i) j/ e# B+ s
: k9 x! m7 t0 f# F/ {; _! ?% K
; d* t5 w% G6 C' t8 ]
; t3 u6 f+ S' Q9 W
8 n/ b+ m, w( w2 `
Page 46 / d! h: ]6 y0 g$ w8 U. W
0 S1 {' Z) |; X# w
Copyright 2007 % P) R5 o+ Y: ? t
Aras Corporation.
; H, s+ ]1 V: X; T- Z5 oAll Rights Reserved.
6 w: W+ b. @) a; z zVB.Net
/ h( I- h4 ~% M+ B' D8 n- |4 VDim innovator As Innovator = Me.newInnovator()
! Q4 m+ r" {3 {
1 r7 ]5 [2 V! d" Q9 ~# U' Set up the query Item. 9 V0 d/ n4 L+ d) U
Dim qryItem As Item = Me.newItem("Part","get")
" Q; l* l# { M( Y& Z: L0 W) ^qryItem.setAttribute("select","item_number,description,cost") - d6 @/ ?0 g6 H/ J
qryItem.setID(myId)
% [, v' _2 M* V7 B* U* X0 n# M 6 q+ H5 k; S9 A4 y& A3 w
' Add the BOM structure. $ s9 p. I$ s8 q, n% a3 T
Dim bomItem As Item = Me.newItem("Part BOM","get") 6 n3 }3 F' d$ u+ f% f8 S8 W. P
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
- Z b) e- _# ZqryItem.addRelationship(bomItem)
; m( P. t. ~( Q' } # n+ F s# G" f+ W$ g. L" U; y
' Perform the query.
1 T0 d6 Y- F/ }3 V7 {Dim results As Item = qryItem.apply() . ]+ b( Z3 R+ Y3 ^- c& r; S0 ^& t
+ ^ s# y2 D, b% G# |% a. l' Test for an error.
; Y r% @! | v$ F& c: ]0 e& UIf results.isError() Then 8 k" y% L$ g1 A0 N
Return innovator.newError(results.getErrorDetail()) % W+ o. s- b6 W+ Q( k2 s, c1 }2 P
End If ( h6 B0 k, W l9 V( g T2 i
8 h8 c% v- n, W* w* U! g# f' Get a handle to the BOM Items.
4 P6 _6 I$ u5 o1 P/ w* B& BDim bomItems As Item = results.getRelationships() . J! j0 w) P: f* M, W
Dim count As Integer = bomItems.getItemCount()
0 p) \3 j. a# @- lDim i As Integer / v1 W* R4 s+ P
2 z. W' S& d( ?5 }$ ]0 U' Create the results content.
4 c+ `# V; a1 I- O. x2 w+ D) ZDim content As String = "<table border='1'>" + _ 7 M; Y- p p2 Y0 ]: W* X) t$ j6 D, g: J
"<tr>" + _ 3 _. m, _7 d( L- L- S
"<td>Part Number</td>" + _ ! Y, E! Q- t; J$ R& x0 N3 r
"<td>Description</td>" + _ % _# I! w& n4 P# Z) k
"<td>Cost</td>" + _ " ^$ ]1 l) l2 O0 q# l7 t
"<td>Quantity</td>" + _
) o) d0 B& c7 C* r6 l "</tr>"
8 W6 g$ x; h, G: q 9 ]% N" C1 F7 s" X+ q5 y
' Iterate over the BOM Items 3 w; `- R' u# o; ^
For i = 0 To count - 1 ! i2 b g5 ^, I7 [4 H8 y
' Get a handle to the relationship Item by index.
s' r' Y, a+ I4 E Dim bom As Item = bomItems.getItemByIndex(i) + Y8 `9 K/ Z* a
I. L5 [: c4 Q# B: k' Get a handle to the related Item for this relationship Item.
9 ]+ _3 T* x& P0 Q Dim bomPart As Item = bom.getRelatedItem()
; @! }' @$ `, N1 `2 R
# g5 C$ i5 }0 U content += _
; y2 G" ]$ {4 q' l4 n2 I) s "<tr>" + _ 0 s* c* ]. A" |' Y9 A* X! y
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
! {0 c/ T. |3 U9 S: M6 J "<td>" + bomPart.getProperty("description") + "</td>" + _
& K3 \. r/ U( |2 M2 F "<td>" + bomPart.getProperty("cost") + "</td>" + _ , U `4 g% u/ j1 S+ }
"<td>" + bom.getProperty("quantity") + "</td>" + _ - p! G# W4 s9 f
"</tr>"
( N8 Q- C2 Y- `0 WNext
* |% u/ n8 k. P6 V1 b2 Wcontent += "</table>" + \2 p2 ?( {! I6 m! d/ U) A$ H
+ |' Z, ~8 ~* u% O
Return innovator.newResult(content) : N2 [% r* n: ?0 _$ M
% l; X- s, B0 B/ G4 V4 |
|
|