|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique % N$ E6 J; b' ~3 H; w
To query for an Item and retrieve its structure you build the query as the structure
( `" t9 V6 Z& g0 Q( n0 w. R4 Qyou want returned. Use the IOM methods to add the relationships you want and
1 o1 _7 o7 o5 `7 n$ ybuild the structure in the Item. The server will return the structure that follows the
, m1 A4 ?5 o7 N* [request structure. 5 u( K1 P. M8 R7 `& b( D6 C
This recipe illustrates several related concepts together, which are how to get a set ' P- Z4 V0 d; W( H. i9 R
of Items from an Item and how to iterate over the set, plus how to get the related 9 ~ ~2 r' J) h; g: C/ q# s
Item from the relationship Item.
- ~7 W( z: A; B* S$ rJavaScript
7 K& H$ t/ {2 U# O. x4 N3 cvar innovator = this.newInnovator(); * v6 O0 ~7 T% w. g* l
. ^$ p$ \$ J r$ ^; q! Z
// Set up the query Item.
3 \) W/ A, k Y. ovar qryItem = this.newItem("Part","get");
+ o' M, ^4 t5 O( |! |qryItem.setAttribute("select","item_number,description,cost"); & @- X2 u+ G1 ~- D0 B. V
qryItem.setID(myId); 6 H9 n$ G* O' w6 ]% t0 ~* J+ F3 j
" r- x) Q2 K' k. x* P- J% u
// Add the BOM structure. : d- ~. X& O _; O% N; Q1 q/ t
var bomItem = this.newItem("Part BOM","get"); 4 n2 W" g5 D( k( J2 P
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
2 q' h; Y" j9 E( f) k7 eqryItem.addRelationship(bomItem);
$ K" |7 o1 c" j1 z5 d& Q: _
& t6 ?$ ]2 L8 e) S" s/ g// Perform the query.
9 S! H# F- @8 Z: h, f2 \' j: Bvar results = qryItem.apply();
% i0 P N) U& R2 W) A4 d" { # Z5 g. K/ t# ?8 l2 r8 \% w4 F
// Test for an error. 4 _" z9 x8 e2 E
if (results.isError()) { . A3 Q: ~6 U+ }6 w; B
top.aras.AlertError("Item not found: " + results.getErrorDetail()); ! I- V' l+ H9 a, S, o3 O. F
return; # D) u" U" V N
} / }4 c: R& J F; }) h4 s
$ {1 E+ ` X( p8 S9 B/ S1 A# A
// Get a handle to the BOM Items.
2 p9 P# @8 \4 Mvar bomItems = results.getRelationships();
9 c$ r" P0 f* d- E( hvar count = bomItems.getItemCount();
2 K) G, Q% V1 N. N' V' @ [
1 }5 ]# [0 {/ C! |. ^$ @% W// Create the results content.
6 N! `; L+ W9 Cvar content = "<table border='1'>" + ; ~, S/ s. w5 v! W
"<tr>" + 9 @' t; O( c- D5 d
"<td>Part Number</td>" +
7 g' D( o- V: L) l "<td>Description</td>" + # R2 M, p: I# C% w
"<td>Cost</td>" + ( _0 `8 R) A% a5 s2 D1 s+ O
"<td>Quantity</td>" +
1 B# I: u& G& r* \ "</tr>"; - Z8 N9 [2 T# D" M! w: [2 ]/ R
; M9 B( E: ^" }8 K' I8 z8 }
// Iterate over the BOM Items. 7 B- m- l: e4 Q3 n1 a. {& y
for (var i=0; i<count; ++i) 7 i; h& c" B6 C8 l% ?' z+ f# w+ X
{ , `9 ?; \# d& t: t) G* N- f
// Get a handle to the relationship Item by index.
) o8 t7 O/ N0 e6 T' ?1 N9 ~+ Z& M var bom = bomItems.getItemByIndex(i); 3 ^5 G* y7 J. Q4 L1 v
// Get a handle to the related Item for this relationship Item.
2 \1 P+ r+ \5 G4 x3 M" ^ var bomPart = bom.getRelatedItem();
+ C. B; q7 q' G: J9 O2 y+ o8 e 9 m! v. W5 l( b6 N: H% m
content += "<tr>" +
6 m' L* _: B& u" F( h "<td>" + bomPart.getProperty("item_number") + "</td>" + . Q! w4 f7 g* Y% p. W
"<td>" + bomPart.getProperty("description") + "</td>" +
' e4 ?8 V; [) j" n5 Q, k8 p7 o1 T "<td>" + bomPart.getProperty("cost") + "</td>" +
* m! B+ V! }# j7 o "<td>" + bom.getProperty("quantity") + "</td>" +
9 N! U/ j7 V Y+ e6 h e "</tr>";
6 _ T4 ]; M) n6 |# [$ Q}
$ b6 v" {% k( Q% a9 x3 ~7 {- |return content + "</table>";
( \$ N3 o' I2 j- g) l. {7 T: D( H8 j% t+ a r# K
. t% A( w1 i0 e; g/ r' E7 K
% n! |. g, j4 F( @# T
# q* p& {5 ^& p+ ^ D0 u* v+ ~C# & z# ^- {' Z* K8 Y/ @" h
Innovator innovator = this.newInnovator();
* X4 ^, q- {- h! q# Q
3 A" s4 q) H; @; k2 F// Set up the query Item.
: X! I( ? e+ T& v( @Item qryItem = this.newItem("Part","get"); # j$ |3 Y3 G" U5 d' S, m' p, Q- O5 @# c
qryItem.setAttribute("select","item_number,description,cost"); ; G" Q$ z B' ~, y' [1 [; V
qryItem.setID(myId);
6 @$ q, b7 f4 ]: o9 r ' O+ |9 F1 {8 n& a3 X+ F1 c
// Add the BOM structure.
7 o6 F& F! ]' S$ l0 |Item bomItem = this.newItem("Part BOM","get");
6 _' A7 z& }2 s# r, Q* m$ q" cbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
: u0 @; y; d+ o( u6 A) t3 H; bqryItem.addRelationship(bomItem); + Q. ^+ b0 X5 n/ |" _9 @
6 n' i7 V% f) t4 k! ^5 J2 Q9 W1 Y
// Perform the query.
7 M! w0 ]+ {8 `- Q: n& oItem results = qryItem.apply();
4 A- R' Z! D% y" ?; F
1 k* J7 d5 O* y7 ]8 O// Test for an error. $ @$ e8 w! y: g! B8 g" e* @$ ^' O. @
if (results.isError()) { ) p/ B) Q6 z1 O j+ W! V# x/ K. K
return innovator.newError("Item not found: " + results.getErrorDetail());
& T+ X6 E6 B( s; g- ^7 `- R} " H+ y$ I( g, ?% j* K
6 o. e. i$ H+ h! l9 D! h
// Get a handle to the BOM Items. 8 V" P1 B3 y' ?" H0 Y; N$ S/ `
Item bomItems = results.getRelationships(); 9 X6 x% J _1 q6 J, ?3 W8 L
int count = bomItems.getItemCount(); " \4 A6 M' \1 M3 @ [
int i; - o. k: |/ E! K' T- s+ M7 ]7 j
& E( x7 y) }/ ]1 p6 \
// Create the results content. ( r, p5 V2 M8 g: O X( O# ^
string content = "<table border='1'>" + * D- x, a; a, Q6 B
"<tr>" + ( G/ F: n5 j1 s% Z
"<td>Part Number</td>" + : G- H) x6 @5 F, ] v0 Q" N! R
"<td>Description</td>" +
& R! c# I+ e. u, C "<td>Cost</td>" +
7 u& q& m$ ?# p* ^( Q "<td>Quantity</td>" +
- ^+ V$ j& F4 F- t6 B "</tr>";
+ H- L% s3 }/ x/ r " r3 U; ~: l: T7 r; T+ y
// Iterate over the BOM Items. 8 ~; A, K l v( F( U) M
for (i=0; i<count; ++i) 1 x7 B7 A1 R# g2 o/ o8 H
{ + R; ^0 b. Z* ?8 {, |
// Get a handle to the relationship Item by index.
& ]* S! P" X% d n1 O; J% l" U O Item bom = bomItems.getItemByIndex(i);
/ P; E) g E2 X" v* ?// Get a handle to the related Item for this relationship Item. ' L* {4 S3 n. {$ N7 D B2 ^
Item bomPart = bom.getRelatedItem();
- b( a4 E7 \" D2 ^
* Q1 J) z$ R( y+ r content += "" +
% K; M$ s+ F8 _. X "<tr>" +
$ \- @7 d" Z- V9 S& e) v "<td>" + bomPart.getProperty("item_number") + "</td>" +
! @6 ^3 B/ @: W# j "<td>" + bomPart.getProperty("description") + "</td>" +
t: j: ?) M9 r$ L/ V) Q R "<td>" + bomPart.getProperty("cost") + "</td>" +
- y( Q! ^2 O# Q3 V* s% }. G "<td>" + bom.getProperty("quantity") + "</td>" +
5 E9 y& a% U8 A) O8 h! G "</tr>"; , ?/ x; [8 u+ O3 c% t# z2 X
} 7 e0 {9 u& b" y3 T! Z$ q0 R
content += "</table>";
1 a8 ]" i z. c9 g4 U/ ` % l/ H1 t' \. f7 k* I- e9 Q
return innovator.newResult(content);
$ d* D! G9 X& s) Y8 q' n9 Q4 r. z1 Z, P' D# D% W( t0 @ P( z
7 r# }5 P5 {: W& c- w, y
+ B4 y4 ]; Q3 B8 }
/ m& r+ i9 _+ k+ q
& i3 l" o8 _. G0 I$ T" B+ N* ~+ ^
& R5 T6 j* A9 p0 ? U & b/ Y) G, C7 A% p8 g6 x
Page 46
2 h7 b1 s, k2 H+ U( p
0 `) K2 e! I G! x5 dCopyright 2007
4 U1 k1 l4 H' z9 rAras Corporation. ; M* P# H. n' x: c4 F
All Rights Reserved.
" E! S# [) e' l/ L4 G- B* eVB.Net
% s3 D% L! [/ JDim innovator As Innovator = Me.newInnovator() ) _! y6 r: B, O" b& q
, B: K1 _0 l: c# r9 T/ m' Set up the query Item. # M1 ]: d( z# ~/ W. y H, T1 K) M
Dim qryItem As Item = Me.newItem("Part","get")
$ E' t6 d4 \3 P) w" e6 MqryItem.setAttribute("select","item_number,description,cost")
# a/ c n ]) H/ H3 E0 dqryItem.setID(myId)
* t8 y& b! S9 w+ I, I% [& B
" @/ }! F7 j+ C' Add the BOM structure.
: i5 l( h1 ]9 i8 U" e% mDim bomItem As Item = Me.newItem("Part BOM","get") 8 m/ x9 {1 E5 J: Q! s3 T
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") `! p0 s4 N* B7 u3 K1 U
qryItem.addRelationship(bomItem)
3 [7 n3 C/ o3 K8 W) y, S* I / [) }0 O/ b9 h+ { U6 V7 L( I( a
' Perform the query. 2 G6 ?$ \) S0 m% T! n; k. c
Dim results As Item = qryItem.apply() + I ~( X% Y) G& A9 {# s# T
" }" S+ N s* A( t$ l' Test for an error. ! X$ i2 {' ]% Z. |4 v* J( J. T3 c. O* \$ A
If results.isError() Then / r1 n2 Y6 A$ q) r! ^
Return innovator.newError(results.getErrorDetail()) ! J) @- H4 S2 F+ x! m) A2 n
End If 9 c" N- b6 b0 P( L& ?' X+ p3 M
8 R/ `# {# X. i L( B# J
' Get a handle to the BOM Items.
2 e; K) a; e- R7 s7 LDim bomItems As Item = results.getRelationships()
8 @% C) G3 X& n; [Dim count As Integer = bomItems.getItemCount() , `3 o; X. F5 m2 n$ e* y, |# v' G# w
Dim i As Integer . j' K2 b; D# x' Z/ l* r0 h
% ~4 v- a/ v E' Create the results content.
. ^5 ]7 p$ w |; zDim content As String = "<table border='1'>" + _
6 k% h Y; t, s; P2 [6 x2 o "<tr>" + _
" i2 V; X" D) R* ^ v2 o I* p0 x "<td>Part Number</td>" + _
( F: _5 W: B" S* ], P/ G2 D "<td>Description</td>" + _ / r* E, u5 ?& O2 ?* x& W, O
"<td>Cost</td>" + _ 6 U( S. ]. k2 U, R
"<td>Quantity</td>" + _ ( m8 G! a6 p$ T b8 F% l( r
"</tr>"
1 V7 U) i& o! L9 o% B( U: L
4 K! I: T' L& T, z9 A8 y' Iterate over the BOM Items 5 L$ D. i2 @' z
For i = 0 To count - 1 ' W: C# a- D' y% E0 I5 [3 q) r4 d V
' Get a handle to the relationship Item by index. " L9 M! c% ~% R9 Q
Dim bom As Item = bomItems.getItemByIndex(i)
6 f3 i7 F+ E3 `2 R! [( l' { X J5 |2 V6 i8 r& g
' Get a handle to the related Item for this relationship Item.
; {3 y1 ~" V7 A2 z Dim bomPart As Item = bom.getRelatedItem() 9 V, ?; a; Z1 ]% { L& Y
2 @' H; _( o" C# d% N5 P6 H2 D
content += _ ! ^ o1 f+ n, [ U
"<tr>" + _
7 C9 l3 z0 R( ? "<td>" + bomPart.getProperty("item_number") + "</td>" + _
/ N$ s) j9 R0 Q3 `: Z "<td>" + bomPart.getProperty("description") + "</td>" + _
9 ~0 @& e. D3 D' Q6 G "<td>" + bomPart.getProperty("cost") + "</td>" + _
( R/ d& {. |" C( M "<td>" + bom.getProperty("quantity") + "</td>" + _ / c4 E- a( D! v) U. e# Z+ L6 j
"</tr>"
+ v! h3 \* f; K; _% }) |! F1 QNext ; q, n% q& d. W, v
content += "</table>"
/ } N5 M+ t' {; g& n3 ^ |2 f9 R ! ?/ |- [4 O8 K! Z: ~" A# R; K
Return innovator.newResult(content)
2 X& F& P9 F: M% L8 I1 R; S0 o7 J- G( J
|
|