|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
# I/ I" ^) h" ZTo query for an Item and retrieve its structure you build the query as the structure , a Z3 N7 l, W& s. j9 q( `5 t
you want returned. Use the IOM methods to add the relationships you want and
Y2 G5 @- _6 f" E' sbuild the structure in the Item. The server will return the structure that follows the
9 ~5 m( ?! ^/ x; t6 m- x/ rrequest structure. $ m3 I# L+ U- N& T6 _1 V
This recipe illustrates several related concepts together, which are how to get a set 3 d0 w9 M. q9 O! v
of Items from an Item and how to iterate over the set, plus how to get the related
5 U& x% p4 { qItem from the relationship Item. 7 M) N+ q" I; `$ `
JavaScript 6 _" b" O( J) O+ {
var innovator = this.newInnovator();
6 N* h1 \% f' I& ~8 O& ]4 X
7 h; H8 ^5 ` x9 J; J3 S// Set up the query Item. 7 f( D1 E) ?# s6 ?; V5 Q
var qryItem = this.newItem("Part","get");
2 \. S1 O7 n8 T @/ b. W3 n( FqryItem.setAttribute("select","item_number,description,cost");
. Q1 V: Q0 y% j# bqryItem.setID(myId); 5 P/ @% E( `, y, {* Y
/ Y8 ?/ E8 z* i6 u7 H8 g( }! v- P2 {// Add the BOM structure.
4 B6 s" f& E: x5 b$ N7 l6 Dvar bomItem = this.newItem("Part BOM","get"); . ?1 l2 j$ B1 V; `* Z1 @: U
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); / G, k2 W5 C9 K: j' c
qryItem.addRelationship(bomItem);
V" F% g7 z' z8 z6 W
, T0 Q" Q, d j, e/ i// Perform the query. - u' P; {/ c0 U7 v
var results = qryItem.apply(); ' A/ b5 `7 ?9 @% u/ u
* M5 H" N5 \! B7 _4 I: L
// Test for an error.
2 y/ ]- B9 e4 A( k1 y" E+ Eif (results.isError()) {
, [" s5 A6 `8 _- O0 A0 E- ? top.aras.AlertError("Item not found: " + results.getErrorDetail());
& E% Z, o% `% ^ return; 6 x6 b& u: a, M9 S U. i
}
8 Y9 B/ [% ]- }8 n* c2 \: ^; @ # W5 K, D4 e& M7 B+ X. Y
// Get a handle to the BOM Items.
& H! A2 S, N4 M8 kvar bomItems = results.getRelationships();
0 }. v4 F2 n4 E% P& fvar count = bomItems.getItemCount(); * \* Z. o8 T& e4 l3 N6 R+ W
0 }( `( }- K+ e. ^3 d; M6 v+ e
// Create the results content. " Y/ K; r: \! K/ y# k% ]
var content = "<table border='1'>" +
2 x3 B+ y2 G9 O9 J3 N "<tr>" + # n7 A: r2 v( c0 S' X
"<td>Part Number</td>" +
$ t( O5 F- Z4 h8 F# M! `5 D "<td>Description</td>" +
: u/ [( y* J; E# p3 N "<td>Cost</td>" +
' v* c2 V1 v: P# W; [5 T "<td>Quantity</td>" + 3 N; V7 G8 |2 d) k* v1 M
"</tr>"; 7 d) u, P. r0 m' t1 A
0 r- F4 V, T! `* s5 v% ^$ n// Iterate over the BOM Items.
# D! i# N/ d2 p: g! Dfor (var i=0; i<count; ++i) 6 D# u7 E, C! F+ r% @6 ~. e
{
6 n6 _" Z; p' G* m+ }2 }, }// Get a handle to the relationship Item by index.
2 L: j* _- v) b6 A var bom = bomItems.getItemByIndex(i); ; r& \1 K( C5 o1 v
// Get a handle to the related Item for this relationship Item. $ e2 c' {% P; ?5 Y6 }) K
var bomPart = bom.getRelatedItem();
& J% w4 I( J; r 2 h5 l+ A `* B2 S1 [. g: w7 U
content += "<tr>" +
2 Z2 ]6 y- y5 N5 D6 e$ x "<td>" + bomPart.getProperty("item_number") + "</td>" +
w7 W, y4 z! H. k# q "<td>" + bomPart.getProperty("description") + "</td>" +
9 o# N2 k$ q$ d* U "<td>" + bomPart.getProperty("cost") + "</td>" +
0 J b) v& x* V0 j" @. ] "<td>" + bom.getProperty("quantity") + "</td>" + - R& F) I* p! P$ B3 ?
"</tr>"; d. s" A# S. u1 z2 [- `" }
} {+ g+ C9 f5 Q$ U2 ^& c( K- M# ~
return content + "</table>";
1 c. |# E5 {, o% J( B) D6 ~3 t1 ~$ b X+ ~2 M6 [: ?: w
% j6 u, Y0 @8 c( B" c7 ~
: [' y, V# k3 [# h
; t3 u; c, I( RC# * V$ K a: d" {
Innovator innovator = this.newInnovator();
7 Z0 H! A7 o t' e1 u; B' D- t- s
: O3 D; H/ P+ w/ [/ m. e: ^0 o// Set up the query Item.
( K1 q" `2 @% @% KItem qryItem = this.newItem("Part","get");
, ]: k) V% ~! G# |3 B9 \qryItem.setAttribute("select","item_number,description,cost");
2 O5 l3 q- r. V5 C# X: I1 bqryItem.setID(myId);
5 T5 }9 r I' m 8 c2 J/ e) R1 a
// Add the BOM structure.
9 c! e1 B9 t0 S tItem bomItem = this.newItem("Part BOM","get"); 4 A7 w7 V9 v' d- E
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 8 r% U$ H4 z1 O8 V
qryItem.addRelationship(bomItem); 5 \0 Z' [' ^/ c+ ?5 a6 V1 }
7 e3 u: v# m9 r7 Z
// Perform the query. $ Y D. n5 g' \
Item results = qryItem.apply();
8 H; D, n# v1 j7 S( E 9 q& ?3 ~8 U7 p
// Test for an error. + _: k( E# g! }
if (results.isError()) {
7 F v. O) f* ~4 | return innovator.newError("Item not found: " + results.getErrorDetail());
0 b% d( l$ Z, _, i} $ l% d* s) D/ o; K5 E* g) I( w
6 S* _+ y* o" I5 y; V// Get a handle to the BOM Items. 8 [# I5 i0 S7 A+ w& T
Item bomItems = results.getRelationships(); - o% [$ C. ]) ` G2 u
int count = bomItems.getItemCount();
9 r& Z t8 _! m" r+ Z! s- v* dint i; ; W7 y) S) b% _- X$ u% E
. H# I( s/ s( B6 W: Q2 M+ o
// Create the results content.
9 b8 O! p$ b, N% o& qstring content = "<table border='1'>" +
% r: h! X( N" v [ @+ A "<tr>" +
& k& [$ j* h) |' q6 [' A "<td>Part Number</td>" + % s! d/ X7 k* Y! w
"<td>Description</td>" +
9 X8 M3 F* A3 F, W: f3 V' j "<td>Cost</td>" + ( N, Q' E0 k7 l2 _. P7 X* ^$ D" b
"<td>Quantity</td>" + X S3 D" h& T5 h9 s, P X
"</tr>"; # m- m6 q! r- t- n* |
$ M+ y6 A* h6 x: ?" Q, X4 O5 X! K// Iterate over the BOM Items. " ?! M* y" C9 Y/ l+ {
for (i=0; i<count; ++i)
+ v, ~) {4 f! P# c{ " R) S8 g* d/ F3 h2 x* x* V
// Get a handle to the relationship Item by index.
2 H% P, m' ? p3 j3 C% J Item bom = bomItems.getItemByIndex(i); , i5 r+ F7 n+ h/ [8 r5 \! [
// Get a handle to the related Item for this relationship Item.
% x. \$ }9 D: [! X Item bomPart = bom.getRelatedItem(); 9 A0 S0 d: } o; F4 Q
4 h n+ D& O, S( p8 d content += "" + * H' ]7 k6 z9 z9 K2 T2 ~" i5 N
"<tr>" + 8 k3 |, l# `6 L# l4 [
"<td>" + bomPart.getProperty("item_number") + "</td>" +
- f5 F( \1 J$ y+ `, i$ L, U "<td>" + bomPart.getProperty("description") + "</td>" +
( f) [* Y6 z' W+ [ "<td>" + bomPart.getProperty("cost") + "</td>" + # _) F$ M. n; f, d" [6 P
"<td>" + bom.getProperty("quantity") + "</td>" +
% L5 g# a' k5 A4 E+ V9 O2 H "</tr>";
* n8 T' c9 Y1 b# z0 a% @, u! D}
( h" }. c5 g: Z9 L1 pcontent += "</table>";
. x, S$ s; p* n W4 K ! k" n# R' w+ \% x9 Q2 O
return innovator.newResult(content);
, Y V. W0 @. e5 T* R
, u9 [7 t( Z: _) A1 ]" e1 X# v3 j4 _
; o5 ~& e! S( k8 {$ Q* W
: y8 u# W& R6 [0 }+ @1 R6 a7 ]# A! ]0 s! ] S, L* J# I2 _0 }
$ m* n; ~1 I0 \, B( L; B9 R
6 F* K6 C4 C( F0 ~6 B / B6 p. d+ I& b) }) b7 H. |7 K
Page 46 4 @3 z4 {# p! M8 F1 W7 |
5 u+ {7 Z+ d$ V, R# g0 L, M+ r
Copyright 2007
5 X6 s; C* j# fAras Corporation.
- N1 ^3 O$ T7 z& K! yAll Rights Reserved. 3 W# w; C5 f! s, _
VB.Net + q! D. H3 d% {5 v
Dim innovator As Innovator = Me.newInnovator() 3 L$ ~ s: P% w$ A
6 j) |( U% b3 d7 ]
' Set up the query Item.
! k$ _3 e' \3 x$ b% G% k- ZDim qryItem As Item = Me.newItem("Part","get")
* e9 a) _5 u6 Z" W; x, G: { J+ ~qryItem.setAttribute("select","item_number,description,cost") ! B/ d _* b; r+ U- \8 N- \
qryItem.setID(myId) 5 w1 _3 T0 c# q- z7 H
! p+ g$ Z$ ~# C/ @6 O! I' Add the BOM structure.
/ p, I+ e" o' b' i% h9 s; mDim bomItem As Item = Me.newItem("Part BOM","get") / k. y+ D7 C' p' w/ s
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 2 m5 o4 k% A- O% ?
qryItem.addRelationship(bomItem) 4 s6 M- \& L# C" w- J* D3 ^
8 A- _; f& p; Z- ]4 G. k( V( g' Perform the query.
/ c0 K5 D# ?5 m4 d6 N3 ?Dim results As Item = qryItem.apply() ; v" |3 t% `. J: l$ D& d
# O/ l* _+ u3 J4 @/ W) _
' Test for an error. ) v: f5 N7 ~, o: r3 ], x8 W
If results.isError() Then # T& `3 g2 T" X/ O. p
Return innovator.newError(results.getErrorDetail())
! G" @4 K2 h: u6 HEnd If 8 L6 [0 Q- M+ p& a8 ]1 k$ G
# F6 M) R/ I+ V5 e3 z/ `: i' Get a handle to the BOM Items. 3 B( X4 r2 }/ R2 c
Dim bomItems As Item = results.getRelationships() 1 J6 X! d1 s: [
Dim count As Integer = bomItems.getItemCount() 7 A% n$ V9 w; b
Dim i As Integer
# u% @3 [. R! y+ J/ Q9 F - v Y. X. J& V! A) Y
' Create the results content. , i- t6 d9 D3 K; e: M2 b
Dim content As String = "<table border='1'>" + _ 5 K: q( d1 x! {' X0 ]
"<tr>" + _ ) }7 {5 J: S1 ~9 K) D
"<td>Part Number</td>" + _
. K/ X' }8 I6 Q "<td>Description</td>" + _
' x( y" p# Y( ^; Y4 r "<td>Cost</td>" + _
: ^1 \2 k- u2 b; T" s* Z& Q* G "<td>Quantity</td>" + _ ) N! ^' ~ b' F
"</tr>"
1 f/ w' O( |+ `$ L
: O' h, U- K9 e) R' Iterate over the BOM Items 7 j0 [! S7 P, D0 S9 U
For i = 0 To count - 1
$ y5 J- X# F8 c% X' Get a handle to the relationship Item by index. : ]8 w1 X! V2 ?8 |) B+ a* q4 V, W
Dim bom As Item = bomItems.getItemByIndex(i)
8 V5 s! `+ z5 |, s# \3 r( t $ H+ d6 p& K P L) P
' Get a handle to the related Item for this relationship Item. ) `) S1 o& w2 y6 ^ B% `; Y9 E$ D
Dim bomPart As Item = bom.getRelatedItem()
, q9 A/ E5 G3 \8 e$ Q: p & H, W$ z; r- v5 @ K) e% F
content += _
, _. a5 s0 Z) m# @ "<tr>" + _ 3 j8 L$ c/ |) L9 P2 J
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 9 Y1 [, h$ V4 h1 \% c" X
"<td>" + bomPart.getProperty("description") + "</td>" + _
) h- ]2 q+ K/ G, J "<td>" + bomPart.getProperty("cost") + "</td>" + _
* `( S9 {4 ^. c "<td>" + bom.getProperty("quantity") + "</td>" + _
5 t* E8 a- R2 \4 h$ I; g# x "</tr>" * y% n' o' i) \
Next ! @/ B; p( z- ^$ z4 }/ F
content += "</table>"
/ {- t) y2 _" g) `" I/ n; h7 ^
; z; ^& s; q' R# X) c! E+ k$ ~Return innovator.newResult(content) ' s0 p5 o& P' p6 v! f i# D. k
1 l; q |. x+ d& @/ i |
|