|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
Technique 3 i% X z& i) r, O U9 Q
To query for an Item and retrieve its structure you build the query as the structure 2 i8 @7 r/ N. u; s+ Q9 y' P
you want returned. Use the IOM methods to add the relationships you want and
8 n, C2 W, k9 ]) U' T4 |( I3 qbuild the structure in the Item. The server will return the structure that follows the 2 U3 Y8 Y3 E- N9 R
request structure. 8 c4 L, S! i6 c( z6 T8 k$ D
This recipe illustrates several related concepts together, which are how to get a set
; w- K+ ~7 s8 n4 \! z+ Q' [8 m1 Eof Items from an Item and how to iterate over the set, plus how to get the related & W7 \, o4 o) G; n& x- R" M& U
Item from the relationship Item.
3 w6 Z9 O6 T5 K0 g" g6 |# ZJavaScript # n! F$ q% F4 j- F( ]2 ?7 j
var innovator = this.newInnovator(); 8 R+ K5 E' K3 [4 ^( @1 H. C
4 P" X1 E) z; ?/ j! [" O// Set up the query Item. * U2 S- J; a! c4 |! x1 P
var qryItem = this.newItem("Part","get"); 4 K7 `! ?( T# I h q: }6 x
qryItem.setAttribute("select","item_number,description,cost");
& d' v/ b7 ]( p, _qryItem.setID(myId); 2 J$ _& t4 f# P+ q# M
; }2 Y5 O& D; D; I// Add the BOM structure.
) E+ e d0 g5 O9 {var bomItem = this.newItem("Part BOM","get"); ' ? K* U( y. y& P* V
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 4 S1 z" O3 o2 H" {2 p6 ~
qryItem.addRelationship(bomItem); / t" w" \. A0 k' j" e2 X' x
, n( H! N9 L% Y8 N& |// Perform the query. ( O+ ~+ k+ \7 N' S2 @
var results = qryItem.apply(); ! Q# G( {# A; H/ C) H
- j6 M! ^/ X4 C! O1 G// Test for an error. % n3 d x( w# { z2 m, [
if (results.isError()) {
, |7 p6 d5 E1 M top.aras.AlertError("Item not found: " + results.getErrorDetail());
2 J; H2 j+ y5 S8 P: m; @ return;
" D0 X* S6 h* M) N7 `5 X} , N8 H+ c" {0 Z% H% N7 A7 b+ p
0 |3 F3 q1 V" }, b8 y1 U( F
// Get a handle to the BOM Items.
2 h, e; V& y' ]: P nvar bomItems = results.getRelationships();
" w% x, Q; m2 }4 u# M( zvar count = bomItems.getItemCount(); ! b7 V1 }- }" U$ p( q) J
9 P$ s# {% K7 \5 R& C// Create the results content.
5 C+ [% D4 r$ ]! P/ R2 v- e# nvar content = "<table border='1'>" + % x% `- h; R1 {2 i3 e( ^* B! c1 _
"<tr>" + - j8 F6 b8 {! b1 T/ ~$ [8 o( i, B
"<td>Part Number</td>" + + m8 T( ~- K' U9 D1 A
"<td>Description</td>" +
0 N# h2 W; j, \, g# V' l "<td>Cost</td>" +
2 V7 [7 c3 D, g/ V6 L "<td>Quantity</td>" + # J0 k* D5 }2 x) G5 z
"</tr>"; ( d) g: t' e0 q1 k' j9 i
& Y; q* n3 ^" ]: p
// Iterate over the BOM Items.
3 g6 w/ m/ Q5 v( b+ k/ R: Z9 L, Sfor (var i=0; i<count; ++i) ; [% u" i3 `' b% a @% M
{
: B' V# S6 D6 s) j5 ~$ d// Get a handle to the relationship Item by index. 2 m/ E) ~) Y! a3 |; ^
var bom = bomItems.getItemByIndex(i);
8 T t Y4 U$ O1 o; z/ M// Get a handle to the related Item for this relationship Item. " x# y$ \. f. }1 t' H# D. e
var bomPart = bom.getRelatedItem();
- a$ D) v5 o4 X0 H! ^
" X2 M1 x7 H+ ]* A% t content += "<tr>" +
; ?# @# Y c$ o8 O "<td>" + bomPart.getProperty("item_number") + "</td>" +
( G3 _4 {, h3 M/ f3 s "<td>" + bomPart.getProperty("description") + "</td>" +
$ d9 ]! ?" ]; P, @/ ~ "<td>" + bomPart.getProperty("cost") + "</td>" +
3 d9 U X4 D, y* U9 [ "<td>" + bom.getProperty("quantity") + "</td>" +
' C# e, ^5 e ^: f# ~ "</tr>"; & F1 g3 y+ r$ K1 @2 \* ]; O
}
" m& {: X* s; W) R! `( [return content + "</table>";& ^4 f% @( S! }+ a( @
) q" `. T7 n3 M& d0 c6 f; j- k) U; F/ a( U
8 n" g' S! ~0 \0 ?) ?( G2 w+ d$ E8 o' b" }: s) c
C# + Y/ m% u( L; J7 b' @5 @
Innovator innovator = this.newInnovator();
# {5 i1 {; |; J; E& _1 k. C( F
- f9 C7 _ h" D" W& w2 M7 v// Set up the query Item.
- c# v0 e% u3 W' V, j1 y& FItem qryItem = this.newItem("Part","get"); % ^; I' H t# {+ J: O4 w8 v( _
qryItem.setAttribute("select","item_number,description,cost"); 2 S# U( Q; n2 ]5 C* j7 g
qryItem.setID(myId); ' g" e' F1 S8 q |+ } @
$ k7 s- H( ~+ N& Y0 N// Add the BOM structure. 4 g6 N7 Z# F% i
Item bomItem = this.newItem("Part BOM","get"); 7 J5 S5 n) @4 s( V+ N5 x
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
$ U. h' W! f3 t4 @4 CqryItem.addRelationship(bomItem); # X! H) _0 a$ Y# ^$ Z
% J6 d" ~8 F. [! U9 I/ r' n1 K// Perform the query.
8 H$ C* L: }0 f# }+ xItem results = qryItem.apply(); 1 I% c6 J. Q( x) ?
]/ w) j# |; s
// Test for an error. 7 S) [3 t) I2 l9 E8 E5 ~# r
if (results.isError()) { 3 U. C) C+ Q, m j8 Y% ]& h
return innovator.newError("Item not found: " + results.getErrorDetail());
3 M0 L6 L G1 x}
7 b' y+ m% y* K: N" h( ^ 1 h M3 T) G: E m# s1 j6 `
// Get a handle to the BOM Items.
1 z+ ~ D d( }4 s! G2 sItem bomItems = results.getRelationships(); - n2 a0 U7 n- v; ^) X4 } T
int count = bomItems.getItemCount(); H2 S \( N- B% Z6 h
int i; + S K( j# ?7 U W2 W0 K
* p8 U! z7 R7 d& x, x) ?/ B// Create the results content.
/ a0 A+ M, }4 c+ pstring content = "<table border='1'>" + * l4 |, H% o4 p+ L
"<tr>" +
6 y# U; `0 D% z& o "<td>Part Number</td>" + ' y2 `0 _* i" N$ B
"<td>Description</td>" +
- E8 b8 g9 E) a5 G. T3 D& s "<td>Cost</td>" + 8 t6 l: l3 k8 ^, ~" j
"<td>Quantity</td>" +
: b) b$ x/ Y- B "</tr>"; 8 S6 V+ ^/ R# r+ W& b' {
+ J' X0 u8 y( A3 K
// Iterate over the BOM Items.
: ?3 E+ a. d. X! bfor (i=0; i<count; ++i)
* K& I, P4 I+ O2 ]/ r; f{
' | B1 u/ N* m2 i& x// Get a handle to the relationship Item by index. ; t6 E: q; O' N" Y
Item bom = bomItems.getItemByIndex(i); ; q0 m7 p+ d- j0 u6 f" }
// Get a handle to the related Item for this relationship Item. 7 d3 |+ _' g9 e+ t
Item bomPart = bom.getRelatedItem();
$ O2 f S& y% \; k + r' R+ ^9 c. ^0 T8 N9 G }7 H
content += "" +
1 K( D+ {5 t7 |+ D3 Z* U "<tr>" +
. Y. d: O) |5 v: d J v5 X* ] "<td>" + bomPart.getProperty("item_number") + "</td>" +
% }+ R/ a" [6 I' ], A; d& _ "<td>" + bomPart.getProperty("description") + "</td>" +
7 E+ V6 r# d) |+ N( | "<td>" + bomPart.getProperty("cost") + "</td>" + 5 f% X4 C8 e* c5 ]+ i: g- K: k; J
"<td>" + bom.getProperty("quantity") + "</td>" +
1 |) P# d, D7 T7 R+ a "</tr>"; " Z$ H8 e" `1 N% Y0 y n" Y( ^
} 3 w* c4 r; L# I* W5 V/ N: g
content += "</table>"; 9 R5 ^- `! f1 ]) o% @
$ ^! B2 K+ |! z- x( \return innovator.newResult(content);
9 Z1 B- P6 j) N9 F& X6 s
: v0 ^9 p6 z! l4 o$ L. }
# w3 @% B8 K& t, x X3 F# w
) F j$ I3 h7 E9 Q# h4 N
" \2 l* j D9 q# g: b" u% V$ l
* O4 d8 {1 _& E6 O; U
+ |) D9 C. Q( @1 S9 `8 `/ Y
) i2 E" U' h# b/ A& @ o/ q Page 46
# @" V8 ]3 ?, [. z- ^1 n8 ^
s! C8 {: S4 f. y8 f- fCopyright 2007 - I. o, ] y7 U2 z* |( _- K/ F \
Aras Corporation.
/ H# K7 T' r; Z) }* \: ^All Rights Reserved. 3 ]4 e* A! @+ ]4 e ~
VB.Net
8 ~/ [# V1 _: N+ d" _0 N5 ^Dim innovator As Innovator = Me.newInnovator()
: g4 `3 ^2 U3 Q" W: A( ]% S( J& Z % J& f" ~( G1 q
' Set up the query Item.
' s9 L( _, e; f, F9 D! _' k/ m zDim qryItem As Item = Me.newItem("Part","get")
+ F, x3 F* l+ A/ K" E' j9 `qryItem.setAttribute("select","item_number,description,cost") & L0 |0 Q6 k( s" I& C) e
qryItem.setID(myId) 7 q) Q% e' e2 m% e1 \" z% e3 P
& D4 r3 {" t5 l; x4 i7 G/ Q: n, ~/ \- M' Add the BOM structure. 8 y1 T- Z, D9 S. ?
Dim bomItem As Item = Me.newItem("Part BOM","get")
C X, Z, S% W$ X) RbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
( v# }" M$ m, X+ d% j) N' VqryItem.addRelationship(bomItem) " `: [3 I% M! A: \. A. v3 x5 O3 a
' d. J3 ?( M& `1 r8 C- `/ |' Perform the query.
6 O, L: _8 Y$ P0 N. h8 C8 V; GDim results As Item = qryItem.apply() 6 N" H B! L( l" o
1 O& d+ @6 I( `$ J5 O% B' Test for an error. 6 m3 {! A2 X3 g' k1 B4 Q1 Q+ Z1 z
If results.isError() Then
5 R+ X5 r+ G7 P. d- l" A8 u Return innovator.newError(results.getErrorDetail())
/ S p) ]% l* d) W5 t) [4 i3 xEnd If ; x5 k; |1 V0 [
7 o9 }( W3 Y+ h9 E5 s7 Q/ F# h
' Get a handle to the BOM Items. - o( k+ k" X$ Z/ Z* E# ^% L
Dim bomItems As Item = results.getRelationships() ' o8 g) ?, \+ I& L$ l. i
Dim count As Integer = bomItems.getItemCount() ! d( C" K# Y1 A; ?
Dim i As Integer ' Y' n8 E% w$ ^ _( Z
- g) U+ D3 j9 k2 O# l/ x
' Create the results content.
7 X( @! f& `) \( ?3 y7 |Dim content As String = "<table border='1'>" + _
% |6 \6 o; V: M2 L( _ "<tr>" + _ + y' c! H0 F* t
"<td>Part Number</td>" + _ . v( K0 P7 I, v8 Y/ M
"<td>Description</td>" + _
8 v$ h; u! P( G2 |/ {' Q "<td>Cost</td>" + _
' F2 A8 j2 I: J0 t "<td>Quantity</td>" + _ 9 E O- D' i l
"</tr>" 0 q, p7 T' b+ T1 k G
) ^+ Z9 I4 ]3 b/ f$ ]/ K9 v' Iterate over the BOM Items
, u; j) k) S, L! m0 {$ _For i = 0 To count - 1
+ M5 j0 k6 |8 ^! d: X; V/ m' Get a handle to the relationship Item by index.
4 K' S w1 _$ p: |/ ~ Dim bom As Item = bomItems.getItemByIndex(i)
9 i6 O+ U8 C2 g' |$ q
* M/ D$ L8 ^ {! C3 U5 V( a5 E; ~% ?' Get a handle to the related Item for this relationship Item.
1 ~" [9 K- a2 r Dim bomPart As Item = bom.getRelatedItem() . O" L. o0 A; ^& N$ N: D" a
. P& u% N( U0 P
content += _ & ^( ~" t7 b! L/ W7 b2 d
"<tr>" + _ 2 U9 ~6 C$ |( i' o, _
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 1 p" ^. `+ J" p" I/ r6 G' Z- L
"<td>" + bomPart.getProperty("description") + "</td>" + _ ) }3 f3 G5 U# ~* R2 q
"<td>" + bomPart.getProperty("cost") + "</td>" + _
; t( Q/ a* Z5 O$ T, y4 Y "<td>" + bom.getProperty("quantity") + "</td>" + _
# s3 f0 A. b# @" t8 G1 ]6 G* l "</tr>" * E B- D- f3 o8 G- G/ ^
Next $ e5 G! T: W$ K# }
content += "</table>" 2 Y+ S3 A" J: j2 ]2 A
6 ^* H$ H# X, _* Y p
Return innovator.newResult(content)
N( a' P9 i' ~3 k ~3 E* y7 r4 g- F( s8 y
|
|