|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 6 n4 e7 N$ K* J; T i' ?- q
To query for an Item and retrieve its structure you build the query as the structure ' T& R- n$ N$ W) t
you want returned. Use the IOM methods to add the relationships you want and . {# M o, Z: ^! ?7 i: E3 l/ [" e
build the structure in the Item. The server will return the structure that follows the
( l; N/ i8 A# ?% v* S1 w4 Rrequest structure.
+ ~0 b7 [' X+ [) U$ S- DThis recipe illustrates several related concepts together, which are how to get a set
3 i+ s) L/ R% p. X9 `. Tof Items from an Item and how to iterate over the set, plus how to get the related
: e1 _3 |+ @8 v8 Q7 b: Y0 v0 uItem from the relationship Item.
: P& R! \& Q( `! b( VJavaScript ' x* ^. A3 I8 D7 `( ]6 A; O
var innovator = this.newInnovator();
3 \- {, d0 V1 s, g6 m( [" R6 G
5 \' N4 K0 Y9 D! c" E, r4 O// Set up the query Item.
1 W8 d. b4 q5 n4 z0 y+ qvar qryItem = this.newItem("Part","get");
% s h; G/ F+ N- d) ^ _& wqryItem.setAttribute("select","item_number,description,cost"); " q/ ^8 w' z" ]1 j5 S/ x
qryItem.setID(myId);
& N% N7 P. ?( r7 I# u- n 2 a$ K; i7 j. Y: Y# t
// Add the BOM structure. # b( r j, }3 K: t1 x
var bomItem = this.newItem("Part BOM","get"); {) j. g4 F# l. @: N8 A! B
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); * e# `$ v) P7 Y
qryItem.addRelationship(bomItem);
! @/ S/ m" K* C3 m5 U, A- E3 H
: _/ l3 v, E* M// Perform the query.
+ p. H2 |0 H& gvar results = qryItem.apply();
; t8 {! g* S! [2 X3 O" I/ Q
+ T$ G& O# ~2 Q% c. S; t// Test for an error. 2 }3 P5 P0 y, Z8 |; z( ^
if (results.isError()) {
4 N3 n5 f" P3 |' p0 }" r top.aras.AlertError("Item not found: " + results.getErrorDetail()); a i, }1 w5 }8 N4 A/ d* E$ B
return;
$ o, W+ W" M' c% W' Q( U9 J}
5 c% Y8 P! B, K u , z8 t- L0 u4 H N
// Get a handle to the BOM Items. / C7 c! d) y$ \9 i
var bomItems = results.getRelationships();
* T* n5 Y* b2 j9 v! U9 Y- F, qvar count = bomItems.getItemCount();
# t: c8 O: Y) e3 l v6 ]
" V* f8 @9 u, k+ X1 R) M6 }3 K' A// Create the results content.
- K& B& j* J% f5 |6 W2 Yvar content = "<table border='1'>" + 4 G1 w- r4 e8 U, {) S/ \4 f
"<tr>" + 4 J& g9 a8 x f
"<td>Part Number</td>" +
/ a5 _0 c# l& z8 U0 D" A; P5 w "<td>Description</td>" +
. X, Q# b$ I# _( m$ b0 ~ "<td>Cost</td>" +
' I. K6 i0 i1 [5 _7 ~3 F% o "<td>Quantity</td>" +
4 J* b. r+ r* e# m+ ? "</tr>"; \9 ]8 @+ R9 `6 s
$ n2 }; Z* m- F: X" z) C8 P
// Iterate over the BOM Items.
. v. P$ d5 r( P$ @9 hfor (var i=0; i<count; ++i) ) K4 A9 D+ Y0 ~+ u2 k8 I
{
9 ?7 y, @3 o' c// Get a handle to the relationship Item by index.
/ n3 N: S3 L' S$ { ~1 R/ q- A var bom = bomItems.getItemByIndex(i);
) ~7 g* r# ?$ c8 F* O// Get a handle to the related Item for this relationship Item.
D, U/ r" {5 s3 S/ Z( Z+ `9 w var bomPart = bom.getRelatedItem(); ! b5 X- R8 K* _+ `+ G
3 \" L4 G% w5 ~ content += "<tr>" +
# Y5 c* H; r9 e/ @ "<td>" + bomPart.getProperty("item_number") + "</td>" + ( { H: h7 \+ e1 t! ]' P
"<td>" + bomPart.getProperty("description") + "</td>" +
7 P) {& ]9 i# \- V% Q0 f5 ` "<td>" + bomPart.getProperty("cost") + "</td>" +
9 J$ s+ l5 ]4 ?4 J "<td>" + bom.getProperty("quantity") + "</td>" + 7 `% l! E% P* P0 U J
"</tr>";
$ F8 P* Y# C3 z3 K- F}
6 M# f( e4 A$ h3 b1 P! n" i6 {: F+ hreturn content + "</table>";& w- u! v7 v3 f0 f- Y
! E6 R, k, {; P/ j1 }
) R' y: T$ S2 U; k% l6 `; W4 S' q2 z f3 ]& g3 a) K% \* s! }
' ?/ P2 ~* T- p4 L$ \0 X$ m
C# * _8 A3 ~1 X& T; G7 W+ m4 u
Innovator innovator = this.newInnovator();
. i3 t6 ^9 A+ M/ w6 I $ \5 `5 z Y& b
// Set up the query Item. / }$ Y2 n1 j0 L
Item qryItem = this.newItem("Part","get"); 9 X& G9 E0 H6 F
qryItem.setAttribute("select","item_number,description,cost"); 3 ^& E& J3 {% s6 v% Z
qryItem.setID(myId); 5 R2 u/ Z3 U: J% J- B( J. ~5 x
; Z3 r4 \1 n( [4 b8 J// Add the BOM structure. - m- n8 w7 B$ p V0 V
Item bomItem = this.newItem("Part BOM","get");
/ [3 m, H* M7 v+ w; ?2 B" c% m$ dbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
9 T, [& t; F" O" q0 YqryItem.addRelationship(bomItem); 7 w6 M+ _( X, n% P% F( z( O2 v) K7 c
4 Q. I4 {9 k- [5 t; b' ~7 O M- O
// Perform the query. ) Z+ W* p1 A; [* {1 g9 _3 u/ o
Item results = qryItem.apply(); 8 V N/ @0 X2 d. b
$ K* g6 l- T }2 I8 |6 C9 _: Q
// Test for an error.
$ N) \# ?! q1 `" x- k: q' aif (results.isError()) {
1 O4 f- ^. O' U |1 c return innovator.newError("Item not found: " + results.getErrorDetail());
! c3 ] a4 e4 @, J} ( V* Y" o" U# M$ S: Q
# e" v7 d4 O2 L) B; d
// Get a handle to the BOM Items. ) r, L# P( B& u4 s" ?% X6 \
Item bomItems = results.getRelationships(); ; J( y8 y" J8 Z0 F
int count = bomItems.getItemCount();
4 H* b% Q# j1 @3 Z. G/ |; u! S2 lint i; ; ~$ R$ r) c% S9 J) K Z L
( V4 W" J; H5 d9 R' }; w( U// Create the results content. # {% K; ?# v( M7 r* N8 l& s: f
string content = "<table border='1'>" + 7 z! r: n3 g7 o+ W
"<tr>" +
; ]1 Z2 ?3 x' t* ?" }( e "<td>Part Number</td>" + $ P/ X, Z/ B5 j+ s8 C
"<td>Description</td>" + 3 N# s4 w1 K4 P t: g
"<td>Cost</td>" +
0 e+ I- D. f4 z8 L+ ~ "<td>Quantity</td>" + 8 I$ U) f* z# L" z
"</tr>"; 3 W |6 s! |4 S9 P1 {* l
+ F1 F6 _1 X) S; L' _
// Iterate over the BOM Items. ; O1 ]3 {' a# X9 G/ M! O' |
for (i=0; i<count; ++i)
$ x/ G' K' R0 }* @{ ! R P; ~+ ~& D. T7 p1 V2 e
// Get a handle to the relationship Item by index. 7 e* U# \9 j! c( `9 E! J
Item bom = bomItems.getItemByIndex(i);
& H: e) k" z" q ~// Get a handle to the related Item for this relationship Item.
2 c' |6 y# z( F% P Item bomPart = bom.getRelatedItem(); - }: H- I8 m' G6 V& U: A8 z
$ S. P8 Z% Z" j2 ~: `4 N
content += "" + ; o/ K+ S7 {5 \
"<tr>" + 9 [, f, q& x* l r, ~# S! ^2 W
"<td>" + bomPart.getProperty("item_number") + "</td>" +
- l5 ]: w( n" P t& y" W. u "<td>" + bomPart.getProperty("description") + "</td>" + 1 ]. ~; M' ^/ S7 h% R M
"<td>" + bomPart.getProperty("cost") + "</td>" +
! _5 R" b, Q) N/ @ "<td>" + bom.getProperty("quantity") + "</td>" +
9 b" G |7 m; v3 ?" X! x4 c "</tr>";
0 o y; o2 I$ w" \/ f+ V. a4 ?}
8 ]+ q, Y5 k0 O, @* }# d, acontent += "</table>"; * H* ^/ S4 t' i
" G8 c' D/ w- T9 zreturn innovator.newResult(content);
" k3 S; b* q; K3 r4 M- Q
: Z7 h+ Y+ T7 e5 D+ Z: K/ q s* o: O/ Z) t0 g
; }% o2 e4 h+ F7 w2 X; q0 w. k
" S0 U9 Y/ `2 Z0 G. J8 a
, B8 M8 ^& w- S5 B' k# Z* }6 t/ e8 n8 ]; A' b
) O- x. J" d5 g Page 46
9 i4 s( h. m0 d7 p" |
, i- {: p6 ?7 c% s6 n! S, |Copyright 2007 9 |- g3 a4 {" Z0 i& ?
Aras Corporation. 4 L' q' r3 w8 j4 {" A5 G* X0 A' u
All Rights Reserved.
% Q, s8 q0 O4 m1 m8 f* dVB.Net
$ a% W( q% ?+ R/ D- CDim innovator As Innovator = Me.newInnovator()
0 ^, p3 R* Z! n9 B+ d0 x# y. F$ s + L5 i/ l) X: E" b- }
' Set up the query Item. # p4 K7 \, T, b7 Z* I! i' D- A
Dim qryItem As Item = Me.newItem("Part","get") ) I( r$ i; \* g0 {/ n
qryItem.setAttribute("select","item_number,description,cost")
$ ]6 `) [2 \* S/ L/ k$ AqryItem.setID(myId) / k2 u" o5 S3 x3 C9 u
% {7 C1 {, Y/ Q; |1 r7 x
' Add the BOM structure.
# H, f5 u2 L9 S( Z: Q( x9 oDim bomItem As Item = Me.newItem("Part BOM","get") . l' f* @/ d9 @# I+ x
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 6 ~: O, o; R7 \* ^) j3 Y j
qryItem.addRelationship(bomItem)
& Q H0 m: {1 ?$ y ' X; w8 p6 V }; w& } M
' Perform the query.
" U/ t' ^, w, c3 C# }- zDim results As Item = qryItem.apply()
5 v* O& J, y7 y$ ]0 ]
: o4 \$ u3 y3 n3 W. `' Test for an error. : W- _! A5 _: o( S$ o+ y/ F, I
If results.isError() Then 4 p4 E, E6 S8 [8 ?
Return innovator.newError(results.getErrorDetail()) - i; F. C9 x# L+ V( b4 c
End If 9 _5 x: V) \; s& U4 I8 f
* k- [4 {! C. t5 J& `
' Get a handle to the BOM Items.
% ]2 C g. y% mDim bomItems As Item = results.getRelationships()
5 U' r( m) l; J# r2 G1 }& a+ `Dim count As Integer = bomItems.getItemCount()
5 O9 S3 ?+ a+ ~) SDim i As Integer
6 Z. X, U- N6 p& u0 g
1 ?; T+ L5 {. T9 A$ z' Create the results content. + M, J& X4 M; f
Dim content As String = "<table border='1'>" + _
+ T4 J; A7 L# @# F9 @+ Z+ T "<tr>" + _
: _- V, `! y4 P, o; r( n "<td>Part Number</td>" + _ + i7 t: t/ U" r( }. q( l4 }
"<td>Description</td>" + _
& }, \3 }& ^# \ "<td>Cost</td>" + _
' o# k3 D/ Q. ?- V+ d3 M% w "<td>Quantity</td>" + _
; D$ Q G( i6 }* b, ]' _6 h: H "</tr>"
% K2 N; W! P Z7 {7 s4 P0 @2 f. p" W
# ?. Q; k8 [8 G8 y" W9 g( F- F' Iterate over the BOM Items
; N% F4 [$ z5 D% t" f/ ?, [For i = 0 To count - 1 , v& H7 q: G7 }$ d% m8 @" d' m* o
' Get a handle to the relationship Item by index.
4 P1 T$ s& s; Y y: @! U/ h Dim bom As Item = bomItems.getItemByIndex(i)
4 o: |4 x8 h' ?, q
+ ]+ m/ s7 G7 [; p' Get a handle to the related Item for this relationship Item. * {1 m2 Z/ I( _+ W& K- R
Dim bomPart As Item = bom.getRelatedItem()
6 f& k8 ]6 P: ]7 x
- h2 a3 w, l) L( D% p5 L) v+ y content += _ ( A5 ^1 @* R0 L6 M
"<tr>" + _ ! F% X7 ?, g& f3 V0 Z/ ]& [
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
2 L" V0 B; F& }% E) L7 n) Y! _# I "<td>" + bomPart.getProperty("description") + "</td>" + _ , x/ {2 h1 s& d' d. d" \. D
"<td>" + bomPart.getProperty("cost") + "</td>" + _
: q; B1 l6 \8 `- S, I "<td>" + bom.getProperty("quantity") + "</td>" + _
3 h% z* R* c, n "</tr>" 6 M' _4 B- K1 r2 ]1 N
Next N/ j) A. U. { N! \, j0 O
content += "</table>"
6 Z2 l* [% e3 z0 U " Z* j, K, L q$ z3 \
Return innovator.newResult(content)
1 u, Y% `0 i5 @9 \ W T9 {) {9 Z# h% v7 x- ]
|
|