|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 1 {2 K3 w% l" S; [0 j# Z
To query for an Item and retrieve its structure you build the query as the structure
, c* Q( M/ m' Cyou want returned. Use the IOM methods to add the relationships you want and
7 ]$ S( y- T& L% g4 s, nbuild the structure in the Item. The server will return the structure that follows the 3 V8 \9 V& X( @$ X7 H3 [ ]
request structure. ( o: H6 ^. J; j- f5 m) K* P
This recipe illustrates several related concepts together, which are how to get a set 7 \, D- l! _- K5 U' D7 N
of Items from an Item and how to iterate over the set, plus how to get the related
' [0 e R: s/ B, VItem from the relationship Item.
' j# `# _6 u6 z; V, `# l+ OJavaScript 5 g% [9 ]# s3 y \( _! N- W* X
var innovator = this.newInnovator(); . x: F+ @( t5 B4 A% Q
: s0 U! n* A8 ^; F: \+ R, P6 s// Set up the query Item. 3 N1 y' U( U- U3 N; v, N/ P
var qryItem = this.newItem("Part","get"); . S/ l+ R b7 ~$ X
qryItem.setAttribute("select","item_number,description,cost");
, R' k; U5 n: e- hqryItem.setID(myId);
$ c: F4 ?0 f) I& N; c 9 l4 d* | L* c2 U# C
// Add the BOM structure.
3 i) w% }! p Z3 j, g/ |var bomItem = this.newItem("Part BOM","get"); 3 {$ m/ x3 ^; f
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
p+ X, ?" x( ?! SqryItem.addRelationship(bomItem);
: D4 A6 J/ t; i
" k% y- _; s4 ^; o' k1 Q9 {// Perform the query. - S# X) B& Z6 w+ M' X
var results = qryItem.apply();
2 `- K S* o+ y 4 w$ I- P4 z0 C J
// Test for an error.
( D7 Z6 [8 b) wif (results.isError()) { . p+ S! W4 x, u
top.aras.AlertError("Item not found: " + results.getErrorDetail());
/ W1 h6 v. m5 e* g5 _ return;
; {$ J! E" B' {/ N4 i, ^, j}
! r* A* Q' x6 P3 E. \& u+ B % l' s' f9 Z) D, C% u; V# T7 t- m
// Get a handle to the BOM Items.
# \, |, a2 u; T- e/ Kvar bomItems = results.getRelationships();
$ g, o$ e; x8 n6 l" Jvar count = bomItems.getItemCount(); " r( M" F8 f1 |" U0 P& P- i2 u
7 `6 ^3 u+ q6 w! W// Create the results content. $ p' I, M. B2 P3 g! \# M1 G) c
var content = "<table border='1'>" +
/ a9 a" N( P2 [: M; ~% C "<tr>" + # l' ~! \" X4 X8 c) ]/ N8 E
"<td>Part Number</td>" +
# c) \2 s1 }; r: `- y "<td>Description</td>" +
7 { k2 a4 u4 s/ n) Q" [) L0 M "<td>Cost</td>" + * ~4 ~. Y, G( {! i) f
"<td>Quantity</td>" + $ J+ a! _) z+ Y8 O
"</tr>";
3 e1 ~- i# N( x q2 m t' S E- N
- z1 n$ n# o& p: v: _3 D+ Q2 {// Iterate over the BOM Items.
. F( _: z! P7 E1 V( Hfor (var i=0; i<count; ++i) 1 `0 s8 ?* k8 i3 b5 U
{ 4 Z2 p2 x% i# `
// Get a handle to the relationship Item by index.
: x& e# i$ c7 i1 |3 e var bom = bomItems.getItemByIndex(i);
* ?+ W0 `3 }+ i6 m& ]2 f* g// Get a handle to the related Item for this relationship Item.
/ P* l: Q* f, s, | var bomPart = bom.getRelatedItem(); + B( g- o! q' W
) O1 W1 C6 d, {9 J
content += "<tr>" + & A* s$ @# o4 t. F% d* _4 c
"<td>" + bomPart.getProperty("item_number") + "</td>" +
0 ]. i1 [( N" G3 a2 ^ "<td>" + bomPart.getProperty("description") + "</td>" + 4 c: u4 @5 I' |( E; q
"<td>" + bomPart.getProperty("cost") + "</td>" + - J) m4 c& Z- t- W# U) F1 K
"<td>" + bom.getProperty("quantity") + "</td>" +
+ H7 D2 ]* L3 X0 R2 V. P "</tr>"; a; m- \$ U$ k6 v
}
& x$ i8 R5 q: P& T) vreturn content + "</table>";
: W1 P$ i/ q! l; x) Z+ c& T$ {4 H6 J I& k
8 F3 X7 E5 V0 y
$ A$ G- m8 @* _7 H
" @% l0 b9 D7 Z7 SC#
. G- K6 z, ?. wInnovator innovator = this.newInnovator();
& R4 L0 [6 F% D2 Q* T 8 E: s: ?6 s3 H
// Set up the query Item. * Y/ w, q) ^& G. k4 d; R
Item qryItem = this.newItem("Part","get"); + j6 x6 J7 {8 _" o! ~5 i; d- C- r4 h
qryItem.setAttribute("select","item_number,description,cost"); ( v0 L+ A7 ]0 ^- i) l0 M& }
qryItem.setID(myId); : e+ i/ e8 a6 c
/ c" |5 `" o! r
// Add the BOM structure. & I+ w- m' }6 d
Item bomItem = this.newItem("Part BOM","get"); 7 S0 `7 N ?" D. Y
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); , f. H9 u/ r+ x5 P3 j
qryItem.addRelationship(bomItem);
' f( H2 [# ^; c8 I 1 [. l8 F @6 Z) J* F% a! s: f1 d
// Perform the query. * x/ d7 L" \: q$ Y/ O! X) Q* w' w* U" m
Item results = qryItem.apply(); 4 n: v) q1 M% F$ h3 |# C9 L, U8 k
+ G5 W3 x0 k: G
// Test for an error. ' R7 b% p9 U' f4 P) c
if (results.isError()) { + S/ z B0 j5 C; X8 A9 s6 e
return innovator.newError("Item not found: " + results.getErrorDetail()); 1 H6 j. e* T7 K+ K0 ]
} ' d; a+ i! w5 L
; p4 l% a3 i! U/ H% ~; X
// Get a handle to the BOM Items.
, k) e+ ~; O/ |$ ]9 {% ZItem bomItems = results.getRelationships(); ! L3 r3 n# k" Y E. \% k
int count = bomItems.getItemCount(); : Y8 z$ r i' ~9 G: `" k$ a& t. f
int i; ) P; h) U) z: m& y2 h
! t" z0 x/ L* b" J
// Create the results content.
1 I$ h5 r) w7 m7 Y! y4 K5 w: F- R& gstring content = "<table border='1'>" + 6 ^& ?2 f+ Q3 G
"<tr>" + $ E: T* ]4 L: ?# ]" E' ?
"<td>Part Number</td>" + / |! l1 J8 r0 m6 F
"<td>Description</td>" +
0 T0 t) A8 z) E4 d "<td>Cost</td>" + - z3 p! |; E8 L; o0 ~
"<td>Quantity</td>" + 6 a. Q* Q* l2 [3 Q+ v8 \; b/ e
"</tr>"; , c" M$ v9 E* V0 o: Y
- p& ]0 N I6 _, W {1 r% M// Iterate over the BOM Items.
* H* K& o$ M" l' Xfor (i=0; i<count; ++i)
6 q0 x7 ?+ \- m2 h1 ?{
3 Q0 ]+ }& O' o! T// Get a handle to the relationship Item by index.
& g* {+ P" v$ e! }; m+ V Item bom = bomItems.getItemByIndex(i);
9 @# @3 P/ w$ n' h' W% {// Get a handle to the related Item for this relationship Item.
% X( G3 f1 ?, j* D- g Item bomPart = bom.getRelatedItem(); & H% a0 c y& ^; `) o8 D
& t* v# @- w& [; m5 ~ u% d E
content += "" + 7 O r7 I4 ^' v9 K2 o8 y; p# j
"<tr>" +
8 r9 u* n4 C ]: d5 j* [& n "<td>" + bomPart.getProperty("item_number") + "</td>" + ; A. [' {6 X, m) I
"<td>" + bomPart.getProperty("description") + "</td>" +
1 k0 f8 C* \, b8 o "<td>" + bomPart.getProperty("cost") + "</td>" +
# {" e, \. `+ u9 ~3 y4 x) _# p- [ "<td>" + bom.getProperty("quantity") + "</td>" +
/ b& q L* U1 B' Z" W+ o6 c "</tr>";
$ h7 b9 P0 j- T# Q4 B+ P} 2 ~- C( w) j1 h7 q: a- i- z7 N- k
content += "</table>"; 5 _, O% Y' G U# H' i) _% @6 y% u
h2 ] Y; n2 U
return innovator.newResult(content);
; H- d# ~6 m' N q. t2 u+ {
& T+ b+ K' h7 I" w( u, x" {( v& g- w
$ Z! o- @% ]3 f' h# q9 M2 H( M% G0 G6 G6 X3 J/ G3 ^3 R ?2 q# A5 n
{0 |6 d( ?+ A& k' a9 N
/ ]0 k2 w1 D3 N' Y3 g
7 E- M' m. E z8 O2 n9 l Page 46 % S2 m- d& j% |+ `. c
) H" G: n9 k; @% j5 {3 R8 vCopyright 2007
$ B; r$ `" H* j" @/ eAras Corporation. x! @1 } w# x0 N# p0 h# n. R
All Rights Reserved.
+ @( H7 i3 l+ _+ h* x- ]7 N* oVB.Net 2 z$ m$ F" p* g% l. j% g) z
Dim innovator As Innovator = Me.newInnovator()
$ l2 X* T* A% ?5 k( W0 p7 N. |- U 9 X/ D3 }- _$ @' _( R
' Set up the query Item.
6 R) P% Q2 h. ]2 i! ]' W7 e0 XDim qryItem As Item = Me.newItem("Part","get") 1 {( j1 X. }3 _5 O( H/ q* x# A: [$ F
qryItem.setAttribute("select","item_number,description,cost") ' u0 @' F' o/ j3 `& k7 P
qryItem.setID(myId)
# W' [9 A, \, u$ x* z9 {6 A ( M* K, u/ `5 E, K1 V
' Add the BOM structure. . N6 A: e. v* P6 ]
Dim bomItem As Item = Me.newItem("Part BOM","get") ) B" s3 b5 `, O$ d4 e5 q3 H
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
5 q3 u: J8 S# DqryItem.addRelationship(bomItem) , H# h( V4 u" |0 u* V* o
$ r, J" g. j8 \
' Perform the query.
# E- X( n4 E% w5 ]Dim results As Item = qryItem.apply()
! {) C) _+ ~. W( I: }( U 5 K+ R# V, ]+ }% g1 f) _8 Y
' Test for an error.
, @2 u, R( M3 U% k0 p) Y8 WIf results.isError() Then ! G7 b. |2 T. c5 H% v( Q R
Return innovator.newError(results.getErrorDetail()) ) [9 ?$ t' o: Z0 Q3 B5 P
End If ( w( M$ P7 n4 M
8 T7 |) X9 }8 M; a/ b' Get a handle to the BOM Items.
# G$ O, j/ p& L2 F* o' `/ U, ODim bomItems As Item = results.getRelationships()
" j# g7 }2 d q: W8 t& {Dim count As Integer = bomItems.getItemCount() $ u# R$ `' {# ?( U) x8 V8 q% M
Dim i As Integer
/ i/ y4 u9 [8 Q # p3 w2 ^8 P1 W& J% T1 `+ Q. A
' Create the results content.
6 X; w/ c) j6 CDim content As String = "<table border='1'>" + _
/ Q" n4 Z9 A+ s7 P# E6 A" q1 Q8 Y "<tr>" + _
- ^& V D3 @5 h "<td>Part Number</td>" + _
) c1 W/ s, u3 A0 u' j, A# | "<td>Description</td>" + _
2 r+ q8 H2 ^; w4 y5 n "<td>Cost</td>" + _
" i" D n5 H1 |' w& } [ "<td>Quantity</td>" + _ " P1 t4 r2 V' j+ A. u# `; _: s% c, |
"</tr>" 8 S# ^0 {" b5 i3 T# L
" x2 N' U+ M9 J) U% O# t% z
' Iterate over the BOM Items 1 A0 O7 U3 ]3 g, a5 y
For i = 0 To count - 1
7 `3 r! W& f' D6 s3 V, t( `& u0 ~' U' Get a handle to the relationship Item by index. ; C& H) @4 w3 C
Dim bom As Item = bomItems.getItemByIndex(i) * I- B7 t, I# m5 ]! I0 {" @
( P4 K- J* F" }' Get a handle to the related Item for this relationship Item.
6 Y* ], C6 A, V q/ q8 |6 U; e Dim bomPart As Item = bom.getRelatedItem() " J3 |7 \- i1 @. {/ t
) C/ e) F- `( }# P K content += _
D( Q* |. R, |' i2 R2 ~ "<tr>" + _
' A0 w) v7 y$ }) t% D4 Z2 Q( M "<td>" + bomPart.getProperty("item_number") + "</td>" + _
" ~% }. G6 H2 a& U- I9 j ^ "<td>" + bomPart.getProperty("description") + "</td>" + _ : o( q7 I) T" m( z
"<td>" + bomPart.getProperty("cost") + "</td>" + _
7 F& i& g9 i6 {6 c "<td>" + bom.getProperty("quantity") + "</td>" + _ ) h) u4 r, l2 Z$ P3 ~" I6 J4 \& ?. [
"</tr>" d5 \( K, C+ G9 }+ G+ j) V2 N
Next O/ X5 }- y! E- d; I: T
content += "</table>"
9 ^7 Y, r! e5 L# @* [/ x
}6 m% q" `( AReturn innovator.newResult(content)
+ w4 b& A) S9 Z: }
- b, B9 P" _/ i7 n- Q |
|