|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique . J) I4 b4 t3 y! [# z& e
To query for an Item and retrieve its structure you build the query as the structure ; c) {3 }2 N/ ~
you want returned. Use the IOM methods to add the relationships you want and
# g0 {4 A0 ~5 ~2 B# x" Rbuild the structure in the Item. The server will return the structure that follows the ( G) I' Z" r5 N: |' h, G
request structure.
$ @+ T2 U9 t) m/ W% w$ E& m. ^This recipe illustrates several related concepts together, which are how to get a set
+ G' [3 r% M& t$ l' q3 X, `of Items from an Item and how to iterate over the set, plus how to get the related ! C" n7 Z+ @! o1 Z
Item from the relationship Item.
# Q# P5 `8 ?& s+ f ^8 S# \JavaScript % A6 i; w4 U; a: L
var innovator = this.newInnovator();
6 N* B0 b; N2 t$ t; c- F3 e
6 Q* I+ q: h" F& B4 O/ w h" c// Set up the query Item.
- A7 @/ e( s! [3 h3 F( ^7 z# Lvar qryItem = this.newItem("Part","get"); + `; `+ C; R4 b5 {( F. @: Q- C
qryItem.setAttribute("select","item_number,description,cost"); : I( d' U! m/ g* p# g
qryItem.setID(myId); + ?! m! o2 H& e* g8 A
; m8 A0 d0 y& J% G
// Add the BOM structure.
; T1 ]# K5 g% x9 O: vvar bomItem = this.newItem("Part BOM","get"); 9 ^! I- [4 Q4 v/ F4 g
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 6 u3 s1 b% T* b# _; V
qryItem.addRelationship(bomItem); o6 c" q# y- K) G- g
# t, q L* K# J1 h7 { |9 h+ B) w
// Perform the query.
+ l# F! d- m& S; Ovar results = qryItem.apply(); 0 d2 R w6 V* V
8 ` e6 @$ k- n* K c// Test for an error. 1 H* @1 A3 D) k4 B2 a& i9 h6 D
if (results.isError()) { 7 i4 ?! s" _0 k6 ]
top.aras.AlertError("Item not found: " + results.getErrorDetail());
6 m; j/ c; P, e: N return; s: X/ c3 b N/ v* M7 V- ~& t' s
}
$ A2 u! D: e7 _5 O* V9 B
& m6 a+ J+ H3 c9 J" y: h// Get a handle to the BOM Items. / \. `. K, z* P) w$ w2 l6 m: Z# K
var bomItems = results.getRelationships(); 7 f, d- v" V; K
var count = bomItems.getItemCount();
6 d1 P- X4 u- U- P+ e: ?& b 8 T2 |/ j' o7 a7 b: d3 ~. o( @. k q
// Create the results content. 6 n: Y% G5 e" K& \# K
var content = "<table border='1'>" + 1 M# Y4 j6 k, I* L5 i& S5 P! T
"<tr>" +
; J% l2 r5 B# p9 t, W2 l: L8 i "<td>Part Number</td>" + 8 V% u7 @; M4 s$ H% R1 }! Q. G
"<td>Description</td>" + 0 z! a+ H: m+ [- Y7 M6 z- p
"<td>Cost</td>" + $ G3 [" n! X# p! F- P
"<td>Quantity</td>" + 0 [" h% [+ u; E5 o
"</tr>";
! {# Q# O. }3 v( g
( |, T) P& T F// Iterate over the BOM Items.
: c6 ^7 o# m! U6 B8 Z0 c: pfor (var i=0; i<count; ++i) 3 C6 k/ k( z/ `& ^; w/ b
{ + G7 Y1 x- M+ x% Y# H
// Get a handle to the relationship Item by index. ; e2 f+ q- w# Z3 e) ]0 C
var bom = bomItems.getItemByIndex(i); ; {' O" a! e# D N
// Get a handle to the related Item for this relationship Item. + R+ a& p5 q' M. ~3 R) N' x
var bomPart = bom.getRelatedItem();
; G" ]: [2 w) P6 F
. k1 Y$ B' l6 F content += "<tr>" +
% W- e9 u+ n4 d7 D% z% u* x# f* v "<td>" + bomPart.getProperty("item_number") + "</td>" +
* z6 g9 M8 }' O" Q$ j+ y* @ "<td>" + bomPart.getProperty("description") + "</td>" +
. n3 u1 x& v( K "<td>" + bomPart.getProperty("cost") + "</td>" + ' ?6 U9 T) Z1 ]( ?
"<td>" + bom.getProperty("quantity") + "</td>" +
7 a, k$ c! K6 A: }+ Z% A" u "</tr>";
' s3 P% {: P+ C9 @/ j9 h}
0 b: i) \ ?5 h! Rreturn content + "</table>"; W1 r! p, q* S% ? j
; m( P4 D4 |4 A+ \( W. r8 g. q7 D+ y$ D: ^" u, t M0 K
' `6 Z9 R- M) e8 M; A4 H" S
& V& F, L! ]* s; @2 ^6 RC#
0 l8 j! F; [( H; I5 e) EInnovator innovator = this.newInnovator();
% l: i& L- L3 j3 h# W4 k, _ 7 |/ D" P/ a% m+ j8 [9 d) Q, v" X
// Set up the query Item.
/ b2 G! t, S9 RItem qryItem = this.newItem("Part","get"); ) u! q* E, D3 }% x% a8 r# j6 ?
qryItem.setAttribute("select","item_number,description,cost"); 5 _2 T% o$ x' O. a; l
qryItem.setID(myId);
: W5 W" i: ]2 k, S 1 I3 @* \8 k" I
// Add the BOM structure.
a5 l8 I( n! E3 q; w8 F# f/ X `7 rItem bomItem = this.newItem("Part BOM","get"); 3 G1 D4 Z% A- L; C7 L' b5 R
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
$ \- z6 ^. B, R# @ b+ O; ]6 lqryItem.addRelationship(bomItem); ( y/ e5 r9 X3 E6 h; y
4 {6 }" B" u3 [: h2 q. O
// Perform the query.
. K& d! C" M5 ~) O3 S) EItem results = qryItem.apply(); + B' s- p$ W" N. h) H/ j$ J) E
( h& n1 U; ^! Q6 a& B6 e6 B
// Test for an error.
, I" ]9 g) t- m x; h2 {if (results.isError()) {
8 a* z2 s# Z% c8 Y4 V: ]- b return innovator.newError("Item not found: " + results.getErrorDetail()); / t; c; w r4 D5 D* A
}
" l/ E% K+ }5 w* o, D+ y- a8 V: e
* T7 e4 w: Z g/ }$ Y' ]9 ~// Get a handle to the BOM Items. . Q$ k! o8 z0 F$ Q5 J. G
Item bomItems = results.getRelationships(); 7 Q8 H: v' ]5 \2 ~, u K
int count = bomItems.getItemCount(); ( h3 H f7 X; p) `9 ]4 ^9 i
int i;
0 k' c$ |# Q0 d
; R. Y P" c7 z$ e( x" M// Create the results content. / |7 s/ h6 Q+ i- e, g2 R
string content = "<table border='1'>" +
& l% I' A1 F \& w$ ?# U" R, n "<tr>" + : L+ L; w& @6 `8 n' \
"<td>Part Number</td>" + 6 u: m# B1 s) g }
"<td>Description</td>" + 3 w0 b$ A) D3 I' @$ M; ]
"<td>Cost</td>" +
+ f) y6 `2 _/ p( J "<td>Quantity</td>" +
" r0 j5 s: j# \# J5 ~; B- @5 S "</tr>";
7 l; b$ @/ l9 d; n, D( n+ Z 8 Z6 C" G' ]" L6 Z" U1 p* r% W
// Iterate over the BOM Items. " B% A# J) f( [ @2 n
for (i=0; i<count; ++i) ' F/ R( c8 g9 t& e! d6 P
{
6 g( i; ^! T9 G, G6 ]// Get a handle to the relationship Item by index.
$ b, j% l. I, k4 r& ~ Item bom = bomItems.getItemByIndex(i); # I# i1 l# K9 N. y3 j# ]7 p+ A
// Get a handle to the related Item for this relationship Item. 5 m" k6 o( ^. Q2 P' s" f
Item bomPart = bom.getRelatedItem(); 2 P) p0 L$ P# j6 o
# O5 O i, R: m# u3 E
content += "" + $ u- _! r9 d! J
"<tr>" +
) D! I$ e5 V1 {9 B! E; c "<td>" + bomPart.getProperty("item_number") + "</td>" + 7 b9 ~, R9 e( i1 u5 L4 O
"<td>" + bomPart.getProperty("description") + "</td>" +
/ V: p% p$ u8 w4 d+ F8 t Z "<td>" + bomPart.getProperty("cost") + "</td>" + 8 ^8 I0 a' c, f) [+ O
"<td>" + bom.getProperty("quantity") + "</td>" + 6 M- N& p! K# v! Z. i$ l
"</tr>";
; L. v9 t/ N: F) |( h9 {}
' f& ~2 h8 n/ n8 Q: A9 X9 vcontent += "</table>";
& B; [; M6 Y5 {5 o' G3 f
( N9 B+ Q ~) q5 @return innovator.newResult(content); : X1 V4 w) _4 E( [5 ^; s- W1 g
8 Y! }2 w- Q0 s- s
5 L/ ^ `$ \( J9 y1 m. m3 S# |! F5 V6 O8 W ^
" y/ q! w, v& c7 X* g$ A. n
) n, B5 @! {& |+ E# @" _# X s* T
# t" @/ Q$ ]( ?+ }* C - [6 T+ r; v, Q I
Page 46 2 p/ ^$ `; p' W% C% a
$ S$ _- L2 }# ~' G
Copyright 2007 / f$ {. y0 P0 `
Aras Corporation.
4 |5 p" [; _9 W3 z* wAll Rights Reserved. q6 b. S' U0 g2 y6 `
VB.Net 0 _7 V1 f. U3 W. d
Dim innovator As Innovator = Me.newInnovator() / ~" u& F' Q" G# |
3 a: h5 n' Y' v; t; Z' Set up the query Item.
3 N, ?$ x" L. _Dim qryItem As Item = Me.newItem("Part","get")
7 J; l$ ]) k5 D8 R tqryItem.setAttribute("select","item_number,description,cost")
1 A# U3 J, ^" T5 \, {3 r1 MqryItem.setID(myId)
6 i! L" r$ e C8 f2 y) H
6 N# M# ^6 u5 E h; r' Add the BOM structure. $ Z7 C6 B( p$ G9 R
Dim bomItem As Item = Me.newItem("Part BOM","get") . N" v7 M4 Q0 b Y( k4 @' S) J. z4 f
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 8 C% g* q! J0 T/ n0 p
qryItem.addRelationship(bomItem)
2 _8 c$ i, c4 D4 Y! O8 t 2 K; ~* F _! p! M* u
' Perform the query. / C. q" @9 j6 a5 ~- ~* K
Dim results As Item = qryItem.apply()
) F! H( @% k+ W7 W- f4 e5 C8 d. k
& C# Z9 n* |' l+ t9 i' Test for an error.
0 A/ m7 W# ]+ F g( fIf results.isError() Then
( L/ T- k$ {/ ~/ n7 V$ u+ }/ N Return innovator.newError(results.getErrorDetail()) - \# j! B0 E; {! E$ f$ d2 b. p. E# [
End If
+ w( t, A# p2 _* h" m7 I. Q
# W' P: e, h1 _) R' Y" \' S' Get a handle to the BOM Items. 0 O m1 `* H; w' Z% l5 q
Dim bomItems As Item = results.getRelationships()
6 e" B3 _( m2 _Dim count As Integer = bomItems.getItemCount()
6 D: q9 [ {) {) p6 bDim i As Integer + {- x a$ E4 b& H4 C$ ?: k d. B
) }% W! k" r/ J9 |- Q& w
' Create the results content.
& s0 o5 W# @4 B% n1 ^Dim content As String = "<table border='1'>" + _ 5 U1 |. V8 R: i A- t6 W- J
"<tr>" + _
* r9 P+ Y, x$ h5 T: m5 D "<td>Part Number</td>" + _ 1 j& r7 Y6 S5 c2 q1 s8 u! }3 x! m5 z
"<td>Description</td>" + _
4 v6 v" d0 {9 Y, F4 ` "<td>Cost</td>" + _ / F# h1 K$ C: K$ O( b: \
"<td>Quantity</td>" + _
" A/ U% W. C. _: E5 T# h5 c" V "</tr>"
$ w4 L8 c7 }, e- a
+ ~6 ~/ x7 } A N- g. ]# x' Iterate over the BOM Items ) t* R1 A' J6 e( N/ W+ Q
For i = 0 To count - 1
/ G2 Q) e1 z W' Get a handle to the relationship Item by index.
3 p" m; f- ]/ J$ \$ s S, A Dim bom As Item = bomItems.getItemByIndex(i)
4 d$ W; g6 l& s, M |9 m; O
' O% l; e5 T1 ?/ u# X3 T' Get a handle to the related Item for this relationship Item. 3 o+ o- d7 t0 K9 b" a/ f% w- U
Dim bomPart As Item = bom.getRelatedItem() " E* g0 J: C: s7 W9 z/ d0 P# `& W" o
: h/ j4 {! Q/ I
content += _ ; Y7 Z$ N4 k" K" \
"<tr>" + _
# q9 a, z7 a) J. A+ q G "<td>" + bomPart.getProperty("item_number") + "</td>" + _
" x# c+ J t' A$ H0 Q$ m3 K "<td>" + bomPart.getProperty("description") + "</td>" + _
! x8 ~8 v7 c) k% c3 E; w "<td>" + bomPart.getProperty("cost") + "</td>" + _ 7 N2 C3 t( y6 q- N% @! ^! d. f
"<td>" + bom.getProperty("quantity") + "</td>" + _ / b& X3 g# M" f6 [% [0 \, `( r
"</tr>" " Y1 w# B3 N; D( c6 ]. a; O& B
Next
* o& v( c( j" H2 V3 I9 I/ ccontent += "</table>"
" u" Q( v9 f8 x # Y$ v. @4 D7 b. k7 Q/ O& |3 r, x
Return innovator.newResult(content) 8 ?( b" y# n9 e0 n0 p
/ J% B U1 E4 \. z8 K" ], A- y! C- ]" W
|
|