|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
- o7 }8 `- I; u5 W" b7 RTo query for an Item and retrieve its structure you build the query as the structure 5 o3 q3 Y. w5 ~3 T0 k5 A( p. {
you want returned. Use the IOM methods to add the relationships you want and
6 g$ h" ]1 |( x" [# u4 ]. obuild the structure in the Item. The server will return the structure that follows the . a+ c' R& m. S- [" Z' T$ E$ C
request structure. , K2 k* i2 }7 @0 x; a4 m+ I
This recipe illustrates several related concepts together, which are how to get a set : F. f* b' v% P e
of Items from an Item and how to iterate over the set, plus how to get the related
6 Q0 f& U( K" v, P6 }4 |& p$ TItem from the relationship Item. ! a' r4 }- [! W6 S; a8 o. z5 K& W
JavaScript
3 ]* b7 T ]% u! J O" Vvar innovator = this.newInnovator();
/ r7 G$ U" i) t( F3 A: B
# \7 ^0 o" w% g1 Y5 U/ z: A& m// Set up the query Item.
5 J8 S- `. D1 wvar qryItem = this.newItem("Part","get");
- C7 z1 T/ v6 I/ u% D4 |2 PqryItem.setAttribute("select","item_number,description,cost");
% X1 [& h9 c( vqryItem.setID(myId);
) o/ d3 R/ H* v/ g; f; {! n
+ L( k( W+ n3 R// Add the BOM structure. ) S) Z4 s- [6 E, i; n
var bomItem = this.newItem("Part BOM","get");
: @4 F1 i: d5 l6 J5 b5 kbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
$ v! G$ o, Q: o! QqryItem.addRelationship(bomItem);
+ B3 X. q0 L; D" ^+ ]$ l
$ C8 ~8 T/ a5 D0 a; W// Perform the query. 0 I% x/ ?' t) i1 I2 @7 j. m
var results = qryItem.apply(); " S" n U q5 \0 m3 H% [
! A) f/ j3 d$ U/ f+ c
// Test for an error. $ I) N s( O, A( Y, e) s3 L
if (results.isError()) { 3 z" s6 p4 G; a2 g+ {4 f) c
top.aras.AlertError("Item not found: " + results.getErrorDetail());
O8 G, _* d" t+ M! E# ?9 k. Q return; a% G/ W8 j: G) D9 I
} + R7 A5 V. Q p3 o2 f/ q/ w- \7 `
% k- R2 O8 A0 y8 f8 G
// Get a handle to the BOM Items.
0 c3 M! ]+ I/ _* `+ dvar bomItems = results.getRelationships();
+ p# `/ Y! { h* n% G( r0 c. m- h0 ]! ?var count = bomItems.getItemCount(); * k, }2 y, e, c
. K3 z+ U/ E- k" `// Create the results content. $ O3 p; k2 p5 r3 k2 \# E
var content = "<table border='1'>" +
3 j2 o. `4 m8 k' M. N* c "<tr>" +
% m6 J+ W% Z5 I8 P n "<td>Part Number</td>" +
6 Z$ q+ s4 P# u "<td>Description</td>" + J) g/ {% ^4 d
"<td>Cost</td>" + 7 d# I1 m# V4 q5 I
"<td>Quantity</td>" +
% T) g; Z/ V* U$ @# p "</tr>";
2 L- v& m" @& o4 L + x, `, ~+ F7 f* ~. [
// Iterate over the BOM Items.
9 U# V* b8 |' cfor (var i=0; i<count; ++i) $ b. ]. e4 R4 B$ ] w3 j
{ 3 h" i) }& q0 g& {0 R) t* l
// Get a handle to the relationship Item by index. 1 q& r) {& o! I. G+ E* T) a# e
var bom = bomItems.getItemByIndex(i); 5 i! O( Q* G2 }6 Q: Z/ a$ I5 d# Z0 _
// Get a handle to the related Item for this relationship Item. / z% h& F$ K! l: K' o
var bomPart = bom.getRelatedItem();
& B9 C& y$ [, Z) B' r9 U, z
8 L6 s0 { P5 K4 a content += "<tr>" +
+ t5 G, k: [' b2 P0 M "<td>" + bomPart.getProperty("item_number") + "</td>" + 3 ~- A5 H- l; c; w2 K
"<td>" + bomPart.getProperty("description") + "</td>" +
& `. ]/ L5 G6 d$ T- E "<td>" + bomPart.getProperty("cost") + "</td>" + / y& \8 t [9 ]( k- X* r2 F7 I
"<td>" + bom.getProperty("quantity") + "</td>" +
: x6 `/ Z! U# E5 o; A "</tr>"; % N/ e* x& N. D9 I+ f
} # J# ?3 J4 k9 s$ V! ^, M- z$ x) }
return content + "</table>";
- ~6 x& @6 X$ z' x) M/ V
: |, ^" B; X) \7 ^8 y6 Y& `3 c) e3 \ |6 v: k ]
6 j7 _. w( f* x2 f& d
$ G5 j+ D7 g ?2 \4 n% FC# ( |: i. r, {! p- I
Innovator innovator = this.newInnovator(); 5 _1 e3 _, L: ~& P7 f
* f6 P( m, u& q
// Set up the query Item.
6 w0 S4 m/ l0 W3 LItem qryItem = this.newItem("Part","get"); 4 _, e; S) z( b3 T7 C0 `
qryItem.setAttribute("select","item_number,description,cost");
7 Z% J( V: U" E# z& _% `2 F( j; u$ OqryItem.setID(myId);
7 y" Z( U: g- B2 d " _" S3 e( }( k6 E9 u2 H% f
// Add the BOM structure. % ]4 R) C/ K0 W) S8 ^; [, `. H
Item bomItem = this.newItem("Part BOM","get");
; m7 m( |4 D& w2 `bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ; _- ~! r4 p/ {0 ~* B8 `2 v
qryItem.addRelationship(bomItem); & o% v% f% ?- b$ O& p0 w
- N8 E1 C$ F( f: {6 T
// Perform the query. - B2 d) L M' q% Q
Item results = qryItem.apply(); 6 Q1 u$ A+ w: P# e! M* R: I
" G( k5 Q) q$ O( _% L// Test for an error. / I% \6 _7 Z( }& \) ~
if (results.isError()) {
/ A0 k/ x. }+ e* T4 D return innovator.newError("Item not found: " + results.getErrorDetail()); ( G( B m7 M% R; _$ Y) x+ w
} 9 \! J" @' `- I3 _
) t) R, [ F3 N/ q// Get a handle to the BOM Items. J& r0 c" Q' c0 [7 _
Item bomItems = results.getRelationships(); 4 _% o0 A5 o, b4 |* x, t" j' e
int count = bomItems.getItemCount();
- v8 i1 h3 E9 R- F- W8 Mint i; + f$ N4 i+ e; m9 K: W
) r( v: O% z& i
// Create the results content.
5 X( W. g- |1 I' {6 q4 g+ astring content = "<table border='1'>" +
& n. D; S+ Z$ T. S9 v "<tr>" + " P, v* y/ l3 q% x& G& t4 Q
"<td>Part Number</td>" + 6 e. } W( x, X, f- d
"<td>Description</td>" +
. F: B M2 m9 ?: `: n "<td>Cost</td>" +
& `$ g) T0 T3 _7 N7 Z" Y "<td>Quantity</td>" +
+ y( d* V& ^' O. E/ h7 |0 J "</tr>"; * s% |! D" ?. p. |4 z
0 f" I9 q1 O9 x6 K// Iterate over the BOM Items. ; F/ u) O5 P2 I% K
for (i=0; i<count; ++i) & \ |+ K$ p; m7 A8 [( ~9 W
{
: B: @ g3 E' x: @; g// Get a handle to the relationship Item by index. ) K- e* h, F* w; J1 T! d
Item bom = bomItems.getItemByIndex(i); 2 o+ s* D4 E8 y" O9 P) h2 V. w b
// Get a handle to the related Item for this relationship Item. $ @9 [- {9 T2 d. I0 j
Item bomPart = bom.getRelatedItem();
# R3 v* J9 B4 d7 U# d 9 _7 G/ ~1 ], T" u# I( j
content += "" + 8 y& E- ^! F" Q ~' N5 E6 P
"<tr>" + + @, l. L/ j8 R) \
"<td>" + bomPart.getProperty("item_number") + "</td>" + # W3 Z, l5 n% s5 Q1 |. \# d/ P
"<td>" + bomPart.getProperty("description") + "</td>" + 5 E \5 e! ^" j6 w* G
"<td>" + bomPart.getProperty("cost") + "</td>" +
6 {$ G6 H; T2 o" c "<td>" + bom.getProperty("quantity") + "</td>" + ( A/ ^4 N7 ~& S8 U3 z* \) Q
"</tr>";
: x. w' p3 T. j& T- E}
& W" Y8 W: G$ r, P" F$ ]3 Vcontent += "</table>";
5 N! K" l; d; q/ q. V) D! w# [
7 T* c0 ~* v7 Y; Xreturn innovator.newResult(content); ! K! l2 G3 a: M1 N& x. r+ X3 v: S
# p/ B: U4 {7 K& y9 l9 f) A! p+ t0 ^7 A6 W# C$ x
7 A5 j6 [; {+ K! D& B: ` F8 l- w
5 [0 S0 ~' _, h0 z0 [' l6 R* Z3 S0 N8 u Q8 G* S7 n8 U$ ?
* Y1 ~: d3 m5 M2 L
: t: U; u* B; E$ U% x9 {
Page 46
2 K; d0 E: s+ l" P: ] / Z q$ ?+ i7 W: C1 Y! k1 i5 Q# n
Copyright 2007
p; a6 @( O/ [+ d) TAras Corporation.
& B: ~. R7 t- l$ E& Q) lAll Rights Reserved.
- s, I' s* k& i* M" W8 ?VB.Net
: l8 v7 ^% [" I, c& H8 a: uDim innovator As Innovator = Me.newInnovator()
5 e& W' Y2 q5 p0 L1 A( |
0 c" |% `# i' I3 {' }2 f w5 @' Set up the query Item.
$ e, a; ~+ K+ I& d7 UDim qryItem As Item = Me.newItem("Part","get")
- S$ h$ k L1 c. l8 O+ ^5 EqryItem.setAttribute("select","item_number,description,cost")
# K. ^+ [5 Z6 VqryItem.setID(myId) ! e* a% Z% e6 t% Y: y
* U |9 y/ n1 Q) [2 d( p/ S1 T' Add the BOM structure. % T0 ^3 X B7 a' _3 W( y9 b4 ^1 l
Dim bomItem As Item = Me.newItem("Part BOM","get") . q4 J( ~- m4 a: W* G
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") & `0 O9 ~+ p P1 Y9 |9 ~
qryItem.addRelationship(bomItem)
- Q' t" Y0 z$ [4 ?. C. }2 f5 @ 3 _: d! Y0 z, g$ R$ E
' Perform the query. 4 {. N# l; ] P
Dim results As Item = qryItem.apply()
7 ?7 q+ ]7 m' ~6 a( ]3 {7 Z8 q
. `. b0 }% Q0 M2 q0 A9 J9 e' Test for an error.
* R! }) H& ]. G/ vIf results.isError() Then ) D& R& E2 _2 a9 Z5 H3 z& k
Return innovator.newError(results.getErrorDetail()) # c* g g" [+ e" T
End If
; @+ w+ F% P9 ~. c& @! [4 G / N. b& l, [4 Q7 R) X
' Get a handle to the BOM Items.
+ D0 x8 s; X8 |Dim bomItems As Item = results.getRelationships() $ ~ q8 T% N+ d" l+ Z/ x
Dim count As Integer = bomItems.getItemCount()
" b1 }+ G, T% x$ W" C/ f" ^$ Q# ZDim i As Integer 0 Z) ]" a; Y9 V F6 a9 c
) i- u) M, b6 H7 w. S; o( B) j
' Create the results content.
$ k( @3 H" C" x0 K% e1 gDim content As String = "<table border='1'>" + _
: t9 h6 f1 u# N! U$ F8 }0 g0 F% @( y7 e "<tr>" + _
6 Y5 A5 _5 w' G( [ "<td>Part Number</td>" + _
( x- h1 F0 V& J/ u% c- p "<td>Description</td>" + _
8 e1 B& ?& `6 n( i \ "<td>Cost</td>" + _
( A3 e0 s3 P7 N* F X- _ "<td>Quantity</td>" + _ : ?. Z+ b/ }# Q' l7 G& y/ G# N
"</tr>"
0 R& k$ j# Q; c # J5 a, w* y8 g+ i
' Iterate over the BOM Items
9 d+ @2 P7 h$ A( k0 S8 jFor i = 0 To count - 1 % o, y/ }2 S0 Y7 \( v; k+ w
' Get a handle to the relationship Item by index.
5 @- A' k" j4 r0 Z& h: t, U Dim bom As Item = bomItems.getItemByIndex(i) * ^ i' Y' k' T( y) ]
; Z) b/ T% b9 H B% S2 R' Get a handle to the related Item for this relationship Item. * I3 \. ^5 O- b6 ?2 w
Dim bomPart As Item = bom.getRelatedItem() * c+ N0 x' G$ E' m G" L2 @
3 F9 u. b5 E: u0 I5 d5 X( a, v
content += _
$ Q1 g& c4 H& o$ @9 E: B "<tr>" + _ , I" b$ R# K( k: O: H# m) u, i
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 0 I8 ?/ _- I" t9 T+ J
"<td>" + bomPart.getProperty("description") + "</td>" + _
8 e% L( M5 Y1 B- X- K5 g) H1 F "<td>" + bomPart.getProperty("cost") + "</td>" + _ ) J- @) B) M w ?# I5 k
"<td>" + bom.getProperty("quantity") + "</td>" + _ - E7 v% B! a/ b- e) w* C; K" A
"</tr>"
4 @% y$ o5 `: D6 [$ KNext 3 ?! t2 a2 K& k5 @* B1 f% W: R
content += "</table>" , S; Y: D+ P, Y/ ]' w7 P! ^
. B# G/ I: d# r/ f0 ]+ Z' O
Return innovator.newResult(content)
' l4 u3 {, x; O! ^3 B* b. v! r$ U3 Q4 X2 Q5 u6 @! u
|
|