|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
S! X4 Q" V- r; qTo query for an Item and retrieve its structure you build the query as the structure 7 b" b7 i: A9 j, y- Q; O4 W
you want returned. Use the IOM methods to add the relationships you want and
/ S+ C# ~# j; |# jbuild the structure in the Item. The server will return the structure that follows the & f9 o. M: h. K* h
request structure. 8 P( x- y* r4 S. `5 u, \5 z) b
This recipe illustrates several related concepts together, which are how to get a set / ^% C4 d9 F7 K# s9 e7 u5 r. \8 b T( U
of Items from an Item and how to iterate over the set, plus how to get the related 9 y9 v; V; P0 o) P9 X: W* {
Item from the relationship Item.
8 b! @ ]; F6 r# R% L; b% V: aJavaScript I* f+ `- M" G* H9 Y
var innovator = this.newInnovator();
( F! ^' s5 B: b# b, m/ u
x9 D- T8 H1 J* z// Set up the query Item. / f) t4 S' ?' b
var qryItem = this.newItem("Part","get");
Z4 G! I0 B6 Z$ U# fqryItem.setAttribute("select","item_number,description,cost"); 5 ^! n0 K1 h& h
qryItem.setID(myId); 4 w4 Q* f2 W" e9 _! u
# \1 [" {2 T- G1 v
// Add the BOM structure.
7 ^# Q6 {/ T0 ^var bomItem = this.newItem("Part BOM","get"); / X. k# ]! A$ d c( j
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
3 V& h' c. l* W; P: w; qqryItem.addRelationship(bomItem);
9 }0 c4 d" P! z8 c $ i- u( ?: n1 \2 _) _+ B( ~
// Perform the query.
2 Q. I( z* O; G$ j D) Kvar results = qryItem.apply();
' T+ B# H+ `+ k3 }
) R+ L) b/ H" T! X// Test for an error.
; U) u: Q- l1 J8 V) O; nif (results.isError()) {
( X9 v) M* p; t+ h' f9 N0 {: o top.aras.AlertError("Item not found: " + results.getErrorDetail()); ( Z, x0 W% g8 E( {6 t; E
return; ! Z: b9 I9 ^3 P! }
} 6 o4 q+ Q) |9 k8 C5 A
) j- I: k' |$ K
// Get a handle to the BOM Items.
* j! E L: H; Q4 i% f3 zvar bomItems = results.getRelationships(); 6 ~: H+ B3 g+ |& O
var count = bomItems.getItemCount(); 7 X( [: B$ J1 w& R
( G, t2 C0 g( i3 q// Create the results content. 7 p6 @1 k/ R3 p: }
var content = "<table border='1'>" + & Q6 C7 z, C) K/ p- n3 a
"<tr>" + . k* E- y) l& ^6 t& E
"<td>Part Number</td>" + ' t2 N5 i* M0 W( K A' t
"<td>Description</td>" + 9 ^! i9 H6 }/ J; b/ O
"<td>Cost</td>" +
/ p1 f. P6 |' }7 E( n "<td>Quantity</td>" +
) g- s) U3 }/ ]& t, O "</tr>"; t8 y! G v, u9 E& S/ I2 }5 Y: l
# O b9 T! o. c( C
// Iterate over the BOM Items. 2 v% ?1 ~4 p5 E: }6 o7 e
for (var i=0; i<count; ++i) - | b4 @9 H) f; S* B( S" {8 U* i
{
0 U5 u/ p7 P3 f/ K3 q/ Y) {4 }, r8 N// Get a handle to the relationship Item by index.
7 q4 z$ n% S$ g7 \ var bom = bomItems.getItemByIndex(i);
. E* ?/ y0 T; b+ s. @; Z0 m// Get a handle to the related Item for this relationship Item.
. `* D' I' x& E& @- _# W# r4 K var bomPart = bom.getRelatedItem(); + G0 e( b0 d" I+ E
% f5 T/ T" E! m! k$ v' C" G content += "<tr>" + $ A) a) b& U5 i$ f
"<td>" + bomPart.getProperty("item_number") + "</td>" +
9 J6 v$ L) }& x, B r' I; B "<td>" + bomPart.getProperty("description") + "</td>" + * `( @- K: Z9 Z
"<td>" + bomPart.getProperty("cost") + "</td>" +
$ G( ~, p2 F7 g: v) Y "<td>" + bom.getProperty("quantity") + "</td>" + 8 d% ]+ Z* ^) `
"</tr>";
0 q! ]0 D! W$ k' [0 t& i, f; a$ o}
" x0 z2 {* p+ }' g7 O, f; Oreturn content + "</table>";# ^2 _6 z; w4 L+ O. c
7 b0 t2 y! H5 O9 V% l
0 x) e0 @ T5 l9 y1 X$ R( [. R. ^
( f7 L5 K( |/ R
# y. J" [" Z4 r3 W1 gC# 1 N- S) r, M# d
Innovator innovator = this.newInnovator();
* p& v9 u4 X. v- q
o; N y3 p* M# w1 Y// Set up the query Item. * E+ F6 ?! @2 A% S$ Z$ b
Item qryItem = this.newItem("Part","get"); 8 T/ d7 ~. \4 c: x+ p. u, j4 G& V
qryItem.setAttribute("select","item_number,description,cost");
; S$ l* P1 N8 j% V9 [" x/ AqryItem.setID(myId);
" b9 s2 M3 g( A5 A) a! Z 7 \" `% \4 q S
// Add the BOM structure.
! ^7 u1 M$ O6 s" P# a h. N4 tItem bomItem = this.newItem("Part BOM","get");
+ W" |: s4 Z N$ TbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); $ u: q* r0 l) F
qryItem.addRelationship(bomItem);
. o p6 m( Z' T& h* a, G
# X8 ]0 w; Z# T. D, D \// Perform the query. " X3 l) w4 W: H' \( q7 P) h
Item results = qryItem.apply(); ) H" x5 M" c# a5 }9 L+ _
& R- B/ ?; T+ |, \5 T. v// Test for an error.
' p! l# W( n6 d( Q1 C! y7 a, Cif (results.isError()) {
% L. ]9 _: _- `+ F return innovator.newError("Item not found: " + results.getErrorDetail());
/ ~* u* I( U9 ?* y5 H+ _4 a} 9 ^; Z9 B f5 R
8 y+ ^- X: f9 J# ~ {, W! I3 {
// Get a handle to the BOM Items.
: ]7 p2 m( j# D5 ] N4 ]4 K# fItem bomItems = results.getRelationships(); ' P! F* y% I: H0 T8 u0 S, E& l1 r
int count = bomItems.getItemCount();
, Y0 T1 p2 [! v; Kint i;
" X6 T6 T' f# x8 I u \' b; O ( U- m; \5 l7 ^; W/ P
// Create the results content. & n3 M4 n3 x* c* i8 [/ [
string content = "<table border='1'>" + ! \% v6 q- Q# t) ]4 ^7 P
"<tr>" +
: s5 i- ?: K! r& z# l" Q* F3 L "<td>Part Number</td>" +
. C j7 {! O$ X6 s/ `( ~0 E: O8 A: E "<td>Description</td>" + 6 m- P2 K% Z7 n8 k I& i
"<td>Cost</td>" + # z$ C& a) ? V+ `. }5 L+ U @
"<td>Quantity</td>" +
3 n: U" v) R& L/ ]1 C$ Z5 { "</tr>"; G& z* U, f4 o7 C
: T# _9 \2 ]" M4 Z! r- U" V
// Iterate over the BOM Items. ! o) C4 {, c2 h' `9 X9 K
for (i=0; i<count; ++i)
: G" ~$ k3 j' c& R* l{
& v Y1 r2 k1 } g! d+ M1 \" n// Get a handle to the relationship Item by index.
0 n8 ~4 b. Y, L! R- L+ y2 T [ Item bom = bomItems.getItemByIndex(i); " i8 ]* O0 z- J( ~, E& D
// Get a handle to the related Item for this relationship Item.
& c" Z, |5 @5 ^, J3 f Item bomPart = bom.getRelatedItem();
& _+ T) r" N9 S, r/ E% d
* l5 v$ ]0 y: @! y8 b4 m* ] content += "" + ( S* k, K4 Z8 y2 U8 Q' j: r! ~5 q3 C2 q
"<tr>" + 2 B" `7 a" }2 ?
"<td>" + bomPart.getProperty("item_number") + "</td>" + 5 v& P7 r' E" s, F" t# l1 \
"<td>" + bomPart.getProperty("description") + "</td>" + ( i' ?, h; L9 c) w. X+ x
"<td>" + bomPart.getProperty("cost") + "</td>" + 1 y: H. J5 ^& I
"<td>" + bom.getProperty("quantity") + "</td>" + ' L) Z$ ]2 }0 u0 u7 V: S& @& k
"</tr>";
( p- s9 Z% S* b- ]} : I9 g8 E4 k3 ~0 k
content += "</table>"; 2 H4 [3 v0 Z& o" H6 c
" \( h1 l6 U: C# S
return innovator.newResult(content); % c; W; G9 b/ Q0 k* r+ s
) m, T0 o/ K9 u
& Y5 V5 L3 Q% t" S6 I1 {
; O$ l$ @" j, h. h8 q
E4 z' ]' b( o( ?
, }" K3 `# B8 c8 p# @ R) { c j7 G
- O( r" j& c0 J
Page 46 + Z! \2 k$ }% A) M: b- C% e
+ Q, q: S! e5 b {4 U: G. A
Copyright 2007
/ h; C, ?( V E! {8 r! ?: HAras Corporation. - l6 v) e8 L J9 c2 T) j
All Rights Reserved. 3 f% _% _5 W1 {4 J. \+ O! B3 g
VB.Net
) m/ s/ l, P& N8 x8 _# }4 f4 pDim innovator As Innovator = Me.newInnovator() % T% [( P/ a: K4 N0 l
. v9 g, t7 ~9 m# |+ {! W/ e; [8 U' Set up the query Item.
8 H( i% x, V% [2 i& C& N A; O8 b3 G1 k4 LDim qryItem As Item = Me.newItem("Part","get")
1 _2 H( E4 z6 W- R' j! P$ n4 GqryItem.setAttribute("select","item_number,description,cost")
9 ~9 U# K1 j/ G1 MqryItem.setID(myId)
6 i5 c z6 Z# `; ]9 O l
+ r# |; @; s0 Y1 X' B/ i' Add the BOM structure. . \8 g6 ^4 t- @+ O$ ~
Dim bomItem As Item = Me.newItem("Part BOM","get")
. D( H! P1 ?- b x+ J; BbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ) \# J; P! E" L. J& W! b. I" I
qryItem.addRelationship(bomItem)
3 O5 K$ o% g$ `- a; V. f% h$ K , F& m ~$ ]6 } I, V- o5 r& E0 T0 c
' Perform the query.
I6 x9 u# M* e; X; h v/ \Dim results As Item = qryItem.apply()
+ ^+ R: S; c' ]( e# j T 1 ~4 j8 Y0 a: A' B) Q
' Test for an error. + e8 ]& u% g0 {* R
If results.isError() Then
/ V, X( w9 c/ G$ N; {5 } Return innovator.newError(results.getErrorDetail())
! b7 s! Q% [8 |% p- K2 g8 i5 GEnd If
$ r @8 ~3 d J, n
$ M {# R& z7 b% g' [# _' Get a handle to the BOM Items. - I/ L/ a4 P* Z4 B( J
Dim bomItems As Item = results.getRelationships() . ?6 O }4 t& E/ n, @+ S3 B# z
Dim count As Integer = bomItems.getItemCount()
8 Y6 W6 A3 h3 h) A1 Z4 I. jDim i As Integer " Z( Y0 e* U: J( v) @2 [
( g# @, t# w1 m7 L' Create the results content.
! r5 b' a! S7 HDim content As String = "<table border='1'>" + _
" I! l8 I' N8 K: f2 a "<tr>" + _
0 q' x8 U! D8 X$ u7 ~ "<td>Part Number</td>" + _ - @9 K, ?+ j {
"<td>Description</td>" + _ 6 z/ N. a b+ M& o' Y
"<td>Cost</td>" + _
6 F/ D, g6 o: h% N4 U "<td>Quantity</td>" + _
+ m3 g, q: `" i/ b5 d3 X& k "</tr>"
5 q$ R$ H- a# [* S6 z: } 0 ?! o# G/ G. }8 K
' Iterate over the BOM Items 9 D. @4 c: v3 N/ s7 d7 L5 T& l
For i = 0 To count - 1 ; w1 \( w E. K) M
' Get a handle to the relationship Item by index. ; N9 u6 h1 N7 v3 n7 w" }* e$ W
Dim bom As Item = bomItems.getItemByIndex(i) 2 E9 `* l. x H, A3 z; E
6 ]' `1 x2 _8 k4 m3 d# a0 t# M( ]' Get a handle to the related Item for this relationship Item.
X3 r1 \) h5 X/ x5 J Dim bomPart As Item = bom.getRelatedItem() . T% a3 O% S- o/ r
2 i0 k; D- h" E& U content += _ . f* S7 I; e4 Z3 Y1 ]( _
"<tr>" + _ 7 l8 M- s4 }) y& _' e
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 _8 h/ ^& V/ ~! ~( O/ G+ @2 U r
"<td>" + bomPart.getProperty("description") + "</td>" + _
( N3 k8 G2 p! F8 c- s1 H "<td>" + bomPart.getProperty("cost") + "</td>" + _
6 a, C6 a7 z/ ~# z "<td>" + bom.getProperty("quantity") + "</td>" + _
K) [; q- [. P/ ^ "</tr>" : f; r3 _, o. i* z; c8 Z( [- q* `
Next ( T! o1 q. M& a
content += "</table>"
6 q' h( f7 Q. ?0 y2 w - e9 H# y( ]# H; R
Return innovator.newResult(content)
$ _" V3 T, G& t
' R3 l A' f2 a" h7 w4 w7 ] |
|