|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
' S0 Y" J. z+ I3 `& e( [To query for an Item and retrieve its structure you build the query as the structure
, x! `! Q$ I$ v7 [; f! s+ O, yyou want returned. Use the IOM methods to add the relationships you want and 0 V5 P8 K0 u3 Q0 Q7 N+ |/ w, r. o
build the structure in the Item. The server will return the structure that follows the
1 y% M1 _% {, J5 nrequest structure. ! c i% {( i, T2 d5 R* [4 y4 o
This recipe illustrates several related concepts together, which are how to get a set
0 t& p! m3 L* @$ Yof Items from an Item and how to iterate over the set, plus how to get the related
8 C+ l) z6 P1 K2 m0 lItem from the relationship Item.
8 k; A; {4 U8 A7 r* r/ |- RJavaScript # S7 }7 K1 g6 v
var innovator = this.newInnovator(); 3 |: @& B9 |0 c; `
4 O1 r5 T; B8 M, G: v( H7 R// Set up the query Item. 7 M5 J# [6 M/ z' x' |
var qryItem = this.newItem("Part","get");
" {- q" v: p. Z$ a& AqryItem.setAttribute("select","item_number,description,cost");
/ j, e$ A7 o5 m1 }" N) d) SqryItem.setID(myId); 5 Y8 l/ a* M+ s% y4 ?7 {; E
+ ]- Q, a* `7 E3 @, W
// Add the BOM structure. 9 E" s+ }. a; J" Z4 a* f
var bomItem = this.newItem("Part BOM","get");
4 x% h& e+ S# B* g- EbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
7 z+ s ^$ b, Q+ q' ]qryItem.addRelationship(bomItem); , M5 O7 D& r Y" J
8 {! L; }( k9 `" i. m$ L5 z- p& }// Perform the query.
- J. n$ D, b6 N: T$ s9 ~5 Fvar results = qryItem.apply(); : }! @1 `, B* U. [* |; w: ^
1 O$ r$ ^* D8 F4 @! ]1 A
// Test for an error. " g& \: v; L: j" T
if (results.isError()) { & u6 {7 x/ \7 V: A# u$ y
top.aras.AlertError("Item not found: " + results.getErrorDetail()); ! v* J( i! n. C
return;
# P8 g0 X O, R* f1 _} ) p0 _/ a9 p+ B/ C' z5 d" D
0 y7 W* ~* I! c6 }$ m
// Get a handle to the BOM Items.
& e" \9 A& ?* kvar bomItems = results.getRelationships();
' f- C- r( B' \4 L% W4 {! jvar count = bomItems.getItemCount(); % a6 U0 R- }) a s- b ~
9 U9 G H5 v& O; H4 E, V4 D" [
// Create the results content.
, C$ B. R4 S6 G/ A- nvar content = "<table border='1'>" +
3 o9 I; j7 e K; C0 u "<tr>" +
& B3 T. D. k+ n' L' d) w# p. w "<td>Part Number</td>" +
1 e/ f2 U, e5 z1 a+ b "<td>Description</td>" +
\& }' P' A! G* p "<td>Cost</td>" + ' \' a5 o: J3 ?% ]6 u
"<td>Quantity</td>" +
; C- m# c% A$ K5 J. ]. x "</tr>";
- g$ T+ W. t4 c- q- S
; l9 ]8 W Z/ w// Iterate over the BOM Items.
" q2 A- G+ J: S/ U! \for (var i=0; i<count; ++i)
# U. U! b5 ^: M: g2 v/ P" \6 Z( _# Z{
0 ?1 o6 c V2 Q3 M/ t8 l// Get a handle to the relationship Item by index. , Q8 p: c3 Z; u, y: R2 @
var bom = bomItems.getItemByIndex(i); 1 _$ e% @# S+ T- k( m( g: K
// Get a handle to the related Item for this relationship Item. 2 Y7 c2 {2 G( ]: d; P% V
var bomPart = bom.getRelatedItem(); $ w( y Q8 P" `2 y
9 {& r# j5 Y8 r: T content += "<tr>" + 8 C2 y/ d& _7 b C$ s; I+ m
"<td>" + bomPart.getProperty("item_number") + "</td>" +
6 u2 O: ^' u) j; l; U* |" l "<td>" + bomPart.getProperty("description") + "</td>" + $ |* Y+ s8 ~1 ?) \; t9 z3 ~
"<td>" + bomPart.getProperty("cost") + "</td>" +
# `7 s) v* V2 x "<td>" + bom.getProperty("quantity") + "</td>" +
. z% k8 ~3 ~ d( `; b8 d+ G "</tr>"; ; L0 v& g6 i, f$ I
} ) v# H. U- P+ V# |5 O9 t7 F: ^
return content + "</table>";
0 j6 w% Z0 R- X4 K4 b9 Y! A- K* G u* J( k7 Q b- r
~! c% X* Q- Y1 j# T/ X
[$ o! A. {2 O* N6 E9 @ O- _
5 ^0 Z p7 B: @& A# H4 aC#
' _, J, \9 B" @# A* H" J: MInnovator innovator = this.newInnovator(); 1 m8 s) V# P& x2 j9 ]
& l8 Y8 V" ~, c1 _+ A// Set up the query Item. $ y; F+ y" [% H9 k9 Q& E( \+ j
Item qryItem = this.newItem("Part","get");
: E6 z! {0 k) e8 R0 R! @! @( s1 HqryItem.setAttribute("select","item_number,description,cost");
5 u6 Z7 _8 j9 S, Y: OqryItem.setID(myId); " H" K% Y* D$ [. e% O; k
! K t+ }# E0 O" f7 i* @% f* j// Add the BOM structure. 6 X) y ]* Y d( ~5 ~+ [7 j
Item bomItem = this.newItem("Part BOM","get");
& ]9 v% d- [6 vbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 9 ]2 k' V; k, D, m! e# `
qryItem.addRelationship(bomItem);
* V2 _' A2 D/ ~; d: P/ B/ ^, W 7 U8 I& h/ t8 p- X( Y0 @& ?
// Perform the query. 9 h3 g4 T6 @3 q
Item results = qryItem.apply(); - B) Q, z1 U/ Q. ^9 F% I
" r# G! v9 @/ ?9 S+ B P. o
// Test for an error.
* ]1 b7 s/ Y' [; \3 \if (results.isError()) { " k' E: E4 S6 I1 c
return innovator.newError("Item not found: " + results.getErrorDetail()); $ U, M# a) O/ Z5 Q+ i) |- L; i
}
% N; z; _7 g1 O2 f2 C
1 r/ P/ V* f. q& I4 z) `// Get a handle to the BOM Items.
+ z: G' y8 O ^; J- e! F: FItem bomItems = results.getRelationships();
, [4 M8 x0 M# z: S6 n: y8 Y) g& tint count = bomItems.getItemCount(); % b8 i- h* y6 }
int i;
2 c- z8 _3 f A2 U" f( V
' o! X2 I: d$ Y& O* ~( t! _// Create the results content. " c9 m. l5 d" y/ H2 L7 b: B( a
string content = "<table border='1'>" + ( C- e, f3 x) z, a2 w" ]% z
"<tr>" +
# Q% C' w" o- C: a' j9 E3 q! u "<td>Part Number</td>" + + C6 @" K1 l% x' u/ g* b
"<td>Description</td>" + 6 f* x: c& \" X
"<td>Cost</td>" + 0 a3 Y$ R$ s8 p4 S1 E" H5 e
"<td>Quantity</td>" + % I4 `$ y4 z9 d" @
"</tr>";
F& k8 C1 o, h- ~ 7 t9 \7 V7 `* R- I5 P5 J
// Iterate over the BOM Items. % W6 W* h3 t( d8 z9 A3 m
for (i=0; i<count; ++i) ! P1 A7 a& @( z
{
5 X% O% f5 d+ C |5 i( y8 P& K// Get a handle to the relationship Item by index.
5 Y5 `) e% Z5 w9 N. p Item bom = bomItems.getItemByIndex(i);
# ^% z4 J" a# |% H: y// Get a handle to the related Item for this relationship Item. 4 O' |0 b5 o, ~- k& h
Item bomPart = bom.getRelatedItem();
3 m1 m, J, D. v, a
6 ]0 X3 @/ M, f' @9 l content += "" + : e3 o1 X% [; C1 U
"<tr>" + " l0 P }& F3 v$ D& i" G5 y# W
"<td>" + bomPart.getProperty("item_number") + "</td>" +
9 S% I/ S1 d) F/ { "<td>" + bomPart.getProperty("description") + "</td>" +
$ Q# b1 T |2 J" C% l, C) }+ a9 \5 e5 R "<td>" + bomPart.getProperty("cost") + "</td>" +
S o7 c) u+ V$ p' P "<td>" + bom.getProperty("quantity") + "</td>" +
J# J5 f, f! D; o9 m* C/ j "</tr>";
1 X& {7 e3 h0 ~# ^, X% H( `} j3 E7 C6 E) v, G4 d9 Y
content += "</table>"; 6 u4 x+ n0 L1 r% D( G, L& P
" m* k' j4 K" {; ?# A& e& t6 @
return innovator.newResult(content);
3 }. K' f, P; s6 v) X. }, o0 t4 d7 k0 ]2 M; q
A- l$ d$ z$ h1 y& P
- Y: S G9 U8 X, [: W8 r7 {
9 e1 D; e! y* E& z. s3 L
, l' x9 t$ E9 F+ W; b) p2 P& q+ |2 t1 ~( S
5 {% c* {# ~% M" `) j% \& @/ v
Page 46 - i) E% {+ X9 n a, z
$ e! K$ i- ~% |+ f4 Z) l% O
Copyright 2007
$ M6 J, i) c% I9 c' S. MAras Corporation.
E- m& `( J8 e: b4 f# i( iAll Rights Reserved.
" x& p2 C* ]" {4 j; E n) I1 AVB.Net 6 s' r$ q- r& }5 C8 ^ P* h* o
Dim innovator As Innovator = Me.newInnovator()
0 B2 e0 t, C7 t+ t3 m3 S. j * c4 H, o/ a- O
' Set up the query Item. # [/ o$ a: h' A- s* Z0 S
Dim qryItem As Item = Me.newItem("Part","get")
+ f/ P( g1 `6 D, }' d# {* EqryItem.setAttribute("select","item_number,description,cost")
% K7 L5 y+ g! T6 ^qryItem.setID(myId)
8 [2 p+ \ ]2 O * \! w( ^0 ~! e g- ? {
' Add the BOM structure.
( C0 y2 K. u" @: F W' zDim bomItem As Item = Me.newItem("Part BOM","get")
) N" W/ i) [1 d/ X0 hbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
; E+ N; V) C! M/ y$ H: qqryItem.addRelationship(bomItem)
7 Y. h0 E# B& q; r3 b
3 |/ `0 b0 f- o- y1 L& u' Perform the query. 2 m/ L- U/ N% i6 H+ W2 P
Dim results As Item = qryItem.apply() + V2 w k! R3 l: O' Q$ E7 D
! w& F9 [5 g! _, ^' i' J
' Test for an error.
; b/ H1 {; ^# L5 rIf results.isError() Then ! s4 @% H! ]/ c7 Y, I
Return innovator.newError(results.getErrorDetail())
5 u2 y0 Y( J4 I- l( NEnd If ) |1 d" P3 t/ m7 U) a
- n3 ]/ j4 c {: F3 g' Get a handle to the BOM Items.
( t+ d2 e( w& c: m1 J/ u3 TDim bomItems As Item = results.getRelationships() 1 ]4 k" y9 F) t2 m- o
Dim count As Integer = bomItems.getItemCount() 5 t( R+ d. s8 o; H# I
Dim i As Integer
& {8 b7 g4 l7 _! h- d$ v8 a
7 ?, s1 J. R" x* W' Create the results content.
: O' L4 j8 U$ s# x' z$ n# J& VDim content As String = "<table border='1'>" + _
- r( Y' e# ?! P! E# g "<tr>" + _
- t/ v h6 j+ y "<td>Part Number</td>" + _ $ e2 _0 l7 Q7 o6 T+ U
"<td>Description</td>" + _
& X: O& A- v( K9 U$ w) M p- _ "<td>Cost</td>" + _
: }6 u$ A4 S' N3 M' n "<td>Quantity</td>" + _ + J/ e1 }* o, ^9 t/ q- n
"</tr>"
/ h$ L- o( n' Z
% c1 N8 x- ?4 w! x/ e+ z' Iterate over the BOM Items
/ P4 G7 M1 G: f, @ v) F" [- NFor i = 0 To count - 1
/ j. j# q8 |' C" t7 ?4 }' Get a handle to the relationship Item by index.
& L- B; ]9 }6 O# d' @: g Dim bom As Item = bomItems.getItemByIndex(i)
' c7 z5 e( I `# W" k O# Z. ^* f! U5 e
' Get a handle to the related Item for this relationship Item. 4 B: j+ b8 P5 r7 G' ^( V1 @
Dim bomPart As Item = bom.getRelatedItem()
) O/ I) g" v! F
5 V* {6 c7 m2 a8 I4 P8 ?# k content += _ 4 I, U$ k z! J6 b, g
"<tr>" + _ + i* Y; z5 S! S
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ ; G+ {6 n% J6 |6 Y
"<td>" + bomPart.getProperty("description") + "</td>" + _
; | _6 ~* U8 E/ W; Q "<td>" + bomPart.getProperty("cost") + "</td>" + _
1 V: l, n8 y, b0 k2 \* R "<td>" + bom.getProperty("quantity") + "</td>" + _ 4 Y/ g+ |: i( F' `/ \
"</tr>"
& ^1 R1 P1 e- H; [; h9 j8 FNext
/ b: R0 t7 X$ ~" f1 B8 u6 }content += "</table>" ' X$ q7 x v) C( ~7 l% p# o' a
+ y5 G' {1 ^5 ~2 mReturn innovator.newResult(content)
, t6 v7 |; j. K: I" d7 `, d# ^8 u6 {$ L% @* D
|
|