|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
' I. f* f" [+ z/ k5 mTo query for an Item and retrieve its structure you build the query as the structure
3 m1 R/ b9 l# d: z$ Ayou want returned. Use the IOM methods to add the relationships you want and
Z; F+ x/ o( s7 Sbuild the structure in the Item. The server will return the structure that follows the ( {% `. `& k1 p# w( |8 }" C
request structure. ' m5 O7 \0 ~( f4 E% e
This recipe illustrates several related concepts together, which are how to get a set
) f- ?$ B/ ^* m7 V9 Oof Items from an Item and how to iterate over the set, plus how to get the related - M. i2 T; D6 V3 b
Item from the relationship Item.
" X* L4 Y; e1 TJavaScript 1 |/ n. k: D8 {3 n* S- ^, I x, \
var innovator = this.newInnovator(); ( D5 U/ E/ y- y% `% j- z7 [
8 ~; Q+ N7 B; C- G: G7 w, J// Set up the query Item. . B) k5 E4 z. d9 Q6 R
var qryItem = this.newItem("Part","get");
" F+ X5 v; b5 t8 J5 jqryItem.setAttribute("select","item_number,description,cost"); / l" l6 N, b0 w- d
qryItem.setID(myId); " w; ] d$ ]1 r7 m4 y
2 U* Y, g) P& Z7 T9 ^// Add the BOM structure. 2 _- _$ @9 y2 z1 n! G
var bomItem = this.newItem("Part BOM","get");
2 w, I( F; U/ p2 T. v6 `8 d" vbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); . j# ~$ `. b. i4 J8 }
qryItem.addRelationship(bomItem); * c+ d: i+ Y% S. E6 t/ z; z
' @2 @. J: R; u' a) N4 M
// Perform the query.
9 K, ^, ~" k) \+ mvar results = qryItem.apply(); 2 T) K' I2 w0 Y
& J M0 a. d. n6 m# w// Test for an error.
6 y0 u8 o- E0 Rif (results.isError()) { % P9 h# K. F! P* T: h
top.aras.AlertError("Item not found: " + results.getErrorDetail()); ) d& Q/ s' y) d7 K! {: U- C8 Z* o
return;
" ]; N0 @1 l1 M- K L* ^: D# b}
8 H! q Y0 S8 o" q5 N+ q
7 i. ]/ D# w* L. L* ?! E) Y$ O// Get a handle to the BOM Items. $ m$ |1 Z7 y& p' [; y) a! F
var bomItems = results.getRelationships();
% J" { ~/ R$ m8 a0 o* hvar count = bomItems.getItemCount(); ! i+ |$ k$ Y1 n+ p: |
6 ?2 E* N& u- }; r/ Q
// Create the results content. 4 H" n+ d9 F0 N9 ^8 `
var content = "<table border='1'>" + ' R- i3 g# d: s7 f& ~7 K
"<tr>" + . i% f1 d8 i. P9 C% `) @7 d
"<td>Part Number</td>" +
0 N/ ?2 M. l8 J$ W "<td>Description</td>" +
" F' t5 a( N9 O& x6 ^9 U( ?: S, e+ L "<td>Cost</td>" +
3 f0 }5 m; J# O "<td>Quantity</td>" +
7 Z& D/ o/ O7 j5 B7 R: Y+ f "</tr>";
: ?2 {) B8 c. K& u q) B" o) q7 j: ?( D! P
// Iterate over the BOM Items.
: n# j# ^ h4 ~8 d" }& efor (var i=0; i<count; ++i) * I# p0 k$ L3 J3 r6 @
{
& u2 k# f" Z3 p9 w! R& a// Get a handle to the relationship Item by index. ) @$ T5 o5 [- c1 g6 U- ^ ^4 e' _2 G
var bom = bomItems.getItemByIndex(i); - n1 p, V0 K$ \+ l" _- Y, n
// Get a handle to the related Item for this relationship Item. 6 F& D7 l, h J- S8 d0 l& k
var bomPart = bom.getRelatedItem(); - w$ Z3 ]8 @$ K/ y' e1 R
2 h5 A) v4 e" m. X& e content += "<tr>" +
9 F/ B/ j8 y7 J6 M "<td>" + bomPart.getProperty("item_number") + "</td>" +
$ l' E1 h7 ^4 a- s) ` "<td>" + bomPart.getProperty("description") + "</td>" + p8 W6 o. e/ t4 W% k
"<td>" + bomPart.getProperty("cost") + "</td>" +
! ?. _( p$ \: [* x7 \ "<td>" + bom.getProperty("quantity") + "</td>" +
6 J7 b# u- V- ^ n "</tr>"; 9 l4 g+ ]9 z S6 R8 j; ]; H
}
2 G8 z) x6 I% ]' [3 Q; y+ Creturn content + "</table>";
4 c/ R9 W& c- e) r5 p( W' U N" W* q( X3 J8 r
0 k. ^4 E3 _3 `! F* M
' ?( t: q7 ~9 X$ P; b) C: R* K3 M
C# # K. o! [/ f" D6 I: u
Innovator innovator = this.newInnovator();
4 F( c: E7 r& y/ o6 h) f" P+ _ / D- X- M9 d& d. U7 l
// Set up the query Item.
+ l& m2 w& p' C( c$ Y# NItem qryItem = this.newItem("Part","get"); . Z# W L6 m5 H: b6 t! y, W
qryItem.setAttribute("select","item_number,description,cost"); $ G. H( {. X) t3 {! }5 a+ k
qryItem.setID(myId);
! C8 a" Q, c# Z# T8 |6 T9 S" g: [ " y# z! T8 X$ D( h( Q- o" |7 C5 E' I6 K
// Add the BOM structure.
, o6 r# E. X0 m; N9 xItem bomItem = this.newItem("Part BOM","get"); ! F8 \( f$ p5 J/ i' n; B, v
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
: n2 v& x5 Y; rqryItem.addRelationship(bomItem);
; f) i# g4 l; W' _/ x6 g
6 k, L" d/ @* l3 Y' {: p5 \7 _( \// Perform the query.
% P2 D5 T3 D( L/ n IItem results = qryItem.apply();
) {6 _: p9 v5 s2 z4 v) |, V
: B# H& r& j. Z+ N, \; s// Test for an error. $ P+ M3 ?3 E: s* E
if (results.isError()) {
' x* q, R' l% W& O return innovator.newError("Item not found: " + results.getErrorDetail());
* l" P7 H. P! u1 J}
! x: a" \6 @ H& y, v( O
/ t# s7 ]) h* O// Get a handle to the BOM Items.
& T {" \5 L: ~ T0 p; q7 ?" \* M" aItem bomItems = results.getRelationships(); : ]' _! u; Z m: G0 w1 g# s
int count = bomItems.getItemCount();
# \$ h6 y8 f" r- p8 S6 eint i; # o8 \# D8 Q" w0 V! L& F
Y, J6 b( Q! ]0 m4 q& I// Create the results content. ; w8 Y# b( j" N7 z! G$ C% T% x, u- d
string content = "<table border='1'>" +
+ R+ q! p. S2 q: t4 P l& S! k "<tr>" +
5 E2 A4 _7 X- H0 N "<td>Part Number</td>" + - ^9 c" Q$ c! z# E) \
"<td>Description</td>" +
( i( t1 x. ^& w8 r "<td>Cost</td>" + 2 q' Z+ `5 C6 t/ ]! M
"<td>Quantity</td>" + & X0 e) v" u) e5 f3 {$ D, O
"</tr>";
( {. R) R& x1 s# M4 o. ] " v4 H! ~7 D7 m& @0 ~+ u/ m
// Iterate over the BOM Items. : j: n( N/ f4 T+ w
for (i=0; i<count; ++i) # f e3 B% b i
{ 0 B* ?& b7 m* \* i. ?6 i
// Get a handle to the relationship Item by index.
# C7 A* V% X* S8 r Item bom = bomItems.getItemByIndex(i);
5 ^, Z% G N* o$ h4 U% M// Get a handle to the related Item for this relationship Item.
) V) }+ C" L( o! g, v9 L% s1 S: K; ^ Item bomPart = bom.getRelatedItem(); & y; M/ I, S, V3 S! f; W
! [8 Q: Z# Y- J9 ]. l B( G/ E7 z content += "" +
" I+ m" a' f& z4 I. z# p "<tr>" +
9 C5 s$ z; s: V& B: | "<td>" + bomPart.getProperty("item_number") + "</td>" + + V$ S, a% g1 ~5 a4 t7 M. L
"<td>" + bomPart.getProperty("description") + "</td>" +
4 q, E7 f2 W; l. l% w; b- ^' K "<td>" + bomPart.getProperty("cost") + "</td>" + , m9 \) C) T' D* ? b9 x
"<td>" + bom.getProperty("quantity") + "</td>" +
$ Q9 b1 H `1 J8 x* V P "</tr>";
; ?. |% l4 v3 |} , j$ e0 y! _4 n% a; ~
content += "</table>"; 6 ^' t4 n, L( Y+ O1 o& f
/ d1 `% d. r7 r( ^4 o/ b& {
return innovator.newResult(content);
2 a4 P' Z9 u( E- ?! K) y: W l) ?
) C( B5 ?4 |( F5 l5 C" J6 x+ y% y# R+ q5 ^: z
9 m; p% D3 v3 z G
/ f7 I/ e+ r3 }1 D, @ Z, ^- x7 _% T& r; ]8 t
; J* i7 n! g8 l3 R+ Y
Page 46 ( m! s/ ~/ S3 a7 n( H' a8 x
) S# r" x! f$ ?1 l0 e- p% }; [Copyright 2007
$ h& L! j+ P4 t3 n% JAras Corporation.
( K) `5 i# z5 N/ b/ }+ [All Rights Reserved. ; _; C% ?8 a4 v" ]" O, R
VB.Net
) R! W; b6 V6 {; W* Q' C& @. l0 UDim innovator As Innovator = Me.newInnovator()
$ {# `8 U" a$ ]: Y1 M6 j# U- I 6 {, Q* K" \! \' a: v: L* H
' Set up the query Item. ' y- r$ ?8 @& x) |; ~
Dim qryItem As Item = Me.newItem("Part","get")
6 M& P5 W% c( pqryItem.setAttribute("select","item_number,description,cost")
0 B5 G& {3 _9 T; K( T8 W( XqryItem.setID(myId) # I2 g) O8 u9 j; j, Q
! n4 M# h% M0 T+ l3 K+ R. S7 L8 i
' Add the BOM structure.
! W1 U, w0 B( f3 |/ qDim bomItem As Item = Me.newItem("Part BOM","get") 9 S, `0 y Y4 @3 N {. S
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ) V" w6 O0 y5 [$ g$ V
qryItem.addRelationship(bomItem) . p; {1 {1 P0 S3 f! V9 n2 Z
; g( V( R1 ]4 S C# S5 L! p0 \
' Perform the query.
+ S* j! C& T4 U; f8 P4 ]Dim results As Item = qryItem.apply()
; @! M: a5 _, z% q5 O# M' |. Z+ A
# O, `* k9 {5 ^% E% d1 C8 ]' Test for an error.
, G. N9 @# Y! Q8 O4 \" S- bIf results.isError() Then . w1 {" t6 t c3 k
Return innovator.newError(results.getErrorDetail()) 3 P5 C2 b( z: H3 D! i ^' ?
End If
0 ]/ F6 w( B, D" ?4 ^
+ z+ g* b, ~ B* U+ O1 `! R9 z/ \' Get a handle to the BOM Items. ~# w9 d1 l% ]1 n: Q6 M! v; p
Dim bomItems As Item = results.getRelationships() + [4 G2 _" ]7 G" k7 K
Dim count As Integer = bomItems.getItemCount() / o1 B. C4 ^ [9 @
Dim i As Integer
9 m/ x( j9 N" J2 \6 G # ?! x$ k+ I; i
' Create the results content.
( c" a+ h, d8 R. y6 k' [Dim content As String = "<table border='1'>" + _
3 ]) n' r+ E) i- A$ C; F/ w6 P: k "<tr>" + _ . R" o! Y# B( [+ Z/ `
"<td>Part Number</td>" + _
4 H8 h% z$ _, j! I4 x+ ~: a$ Q4 h "<td>Description</td>" + _
, C; g' @* \* d. W" s( ^ "<td>Cost</td>" + _
- I7 v1 H' N' M! V "<td>Quantity</td>" + _ " K- I5 A! Y7 _( T; ~4 [
"</tr>" 8 K( `! b* S) g( f
, W: R2 p2 ^7 R9 u: ?6 C6 {' Iterate over the BOM Items
+ T/ u1 L8 l: ?. | ~For i = 0 To count - 1 ' P: [! S1 x( Q" ^, f# n2 K0 C
' Get a handle to the relationship Item by index.
% W( t- _! H+ L) M8 d Dim bom As Item = bomItems.getItemByIndex(i)
5 S% q: X$ T' u1 }# O$ H/ g ( `/ m- r3 N0 U
' Get a handle to the related Item for this relationship Item. 4 K) e1 e, e4 ?
Dim bomPart As Item = bom.getRelatedItem()
6 p" K b. T/ U/ A ( S, ^/ @. `& `5 s0 K. `; B
content += _
% o% b; \9 S U$ V "<tr>" + _
5 h2 {1 q2 h4 W "<td>" + bomPart.getProperty("item_number") + "</td>" + _
8 G d0 W ~# x6 i/ F "<td>" + bomPart.getProperty("description") + "</td>" + _ + p8 U/ j% ?. Q, \0 D5 n
"<td>" + bomPart.getProperty("cost") + "</td>" + _ 9 o& b+ L+ q% \6 Z! _; @% W
"<td>" + bom.getProperty("quantity") + "</td>" + _
; K1 C& e7 T) _, \/ L "</tr>"
( W: e) P" E; M1 j, n$ NNext
) I* R' N' r+ e1 y# H3 G& G9 ~7 Hcontent += "</table>"
& v2 K( O4 M& j6 y% R+ S1 v ! b @( O! \4 y3 P
Return innovator.newResult(content)
7 O& v$ o6 \6 D* M* D+ T- K, J. U; d, o$ {- W% a2 h* Z8 W, h6 g
|
|