|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
7 P1 `0 ^4 u) v5 YTo query for an Item and retrieve its structure you build the query as the structure
, ? M q5 p9 s L4 O# F {you want returned. Use the IOM methods to add the relationships you want and
, g6 U( O3 q( v' Qbuild the structure in the Item. The server will return the structure that follows the 5 u$ z! A# |+ Q" R( F! d
request structure.
; S/ i5 p9 p2 `6 @This recipe illustrates several related concepts together, which are how to get a set
& S, R/ y! @ ^$ B F' A z/ Gof Items from an Item and how to iterate over the set, plus how to get the related
& D1 @) r. A2 kItem from the relationship Item.
6 J) o% D. W; Q. { x3 lJavaScript
}. F7 P: x/ d( y. }' \var innovator = this.newInnovator(); ) w' J9 ?' |2 j& T
& N6 J# b) Z0 k& @' j) _
// Set up the query Item.
3 Z: [% O3 d2 p1 N8 evar qryItem = this.newItem("Part","get"); 9 P5 H4 j; A0 x' k. o
qryItem.setAttribute("select","item_number,description,cost"); & b4 l% b9 R; i, Q' t8 i' c9 I$ L
qryItem.setID(myId);
/ C* f/ T" e* j
& U1 t0 F2 M6 S7 `// Add the BOM structure. ) q( C6 I8 n" k! e
var bomItem = this.newItem("Part BOM","get"); 9 ]) C! J; M! O% e( l1 k7 d
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
' W! O8 x9 ?: s) G: ^2 }% \) DqryItem.addRelationship(bomItem); ; Q( f$ l5 R+ |: e7 Q" Q6 Q# m
# x: S2 F9 |6 y& j+ {, X
// Perform the query.
2 }7 M* m0 d+ ^& Yvar results = qryItem.apply(); ; W( G1 c" m4 }5 ?4 J
* K f# u7 d/ S9 }1 s// Test for an error.
( b- ~, U4 F1 i7 L) ^if (results.isError()) { * Q R; g) { t0 C, l
top.aras.AlertError("Item not found: " + results.getErrorDetail()); 3 J! W" Z. w" q( Q+ F3 g
return; 5 c% ^; S4 Q( b2 \4 c' B
} 9 N) l7 u0 V& I" ^/ P
% M! s5 Q6 i- M5 L// Get a handle to the BOM Items. : ^+ z; \* U. x; H B2 @3 H
var bomItems = results.getRelationships(); 6 {3 p+ m2 }* O. O* i9 s8 z4 d
var count = bomItems.getItemCount();
! c0 s- q y4 U% O( @
5 i" v5 ~2 n) J, J! U8 d6 M// Create the results content.
% w' Z9 J) s2 h+ dvar content = "<table border='1'>" +
. f& p: W( q' v5 l "<tr>" + ' i; Z0 L, X' {0 Y
"<td>Part Number</td>" +
4 l9 n- v& u3 G% n "<td>Description</td>" +
# L; @4 h: L# r- O "<td>Cost</td>" + 5 j! B7 M) s- R* V. Z- Y
"<td>Quantity</td>" +
" M& l9 A9 e% r3 \ "</tr>";
: ~7 v; I; s( f / U1 k6 E) T* M0 a/ |' K/ \
// Iterate over the BOM Items. & Y- e2 t) G1 M+ Z9 K
for (var i=0; i<count; ++i) 8 \: D# k+ j A# Y& A0 a: p0 ]
{ 5 R5 U+ x, w' M. M/ _
// Get a handle to the relationship Item by index.
; Y* _9 K" i' t/ ?( R( y8 N var bom = bomItems.getItemByIndex(i); ! m% s/ z8 L+ H
// Get a handle to the related Item for this relationship Item. ( _+ K+ Y. y; `+ G, E
var bomPart = bom.getRelatedItem();
1 E e8 y$ v* A' r$ F8 i : p% `; y% W6 m4 R
content += "<tr>" + B! _6 I# J6 A4 C2 T" a
"<td>" + bomPart.getProperty("item_number") + "</td>" + ( i. d8 |8 V, z8 l* s5 S
"<td>" + bomPart.getProperty("description") + "</td>" +
4 b5 q; k+ _. u7 H/ Z0 |! B/ } "<td>" + bomPart.getProperty("cost") + "</td>" +
8 C( O1 U7 I( s. z( e0 L7 d "<td>" + bom.getProperty("quantity") + "</td>" +
+ o9 Y0 h1 t/ _" \2 { "</tr>";
: f6 P& {& n* O} : \) u [9 @" r4 v
return content + "</table>";
4 N( G( V; f* T! m1 ?% z1 c. [- m! ?6 _1 m- X, _& U
T5 s$ m3 s' d- u1 a: p6 [% S* I
! E m5 ]4 M) D0 V" ]# C w
7 V- H' j. M" |
C# 6 B6 }3 G4 {6 D5 d: h) f
Innovator innovator = this.newInnovator(); 4 r' {4 e6 [ S
7 M' y" M, O( `, V$ ]5 F. U5 |
// Set up the query Item. 3 W9 t4 D# I/ R* _/ m* D
Item qryItem = this.newItem("Part","get"); - K7 S( E3 J. [0 P6 d
qryItem.setAttribute("select","item_number,description,cost"); $ S6 B* y; Q1 k$ j7 Y" {8 I( y* b# x
qryItem.setID(myId); 6 S* X! r- x4 c# r
' A% r: \& ^% f2 f// Add the BOM structure. & |( u3 Z3 v3 T2 j. f2 }! m
Item bomItem = this.newItem("Part BOM","get"); 6 Q a/ F6 O9 u' a, ~& p( X1 S: V
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
( z8 Y+ s, H" y1 tqryItem.addRelationship(bomItem); g& y+ ?2 ^8 y$ C
4 p/ s+ N& m: w1 L* P// Perform the query. 6 e) p: k! L. A4 Q9 w4 F
Item results = qryItem.apply(); & I7 @% i0 J2 @9 _0 t: y/ T+ F8 y
' q! `4 U( R! S1 z8 d1 J9 l// Test for an error.
6 C, X" e% ?# \$ b+ p; Aif (results.isError()) { , {+ X0 a7 B! y7 s% l4 q1 I1 w
return innovator.newError("Item not found: " + results.getErrorDetail()); ; C7 C7 l& a# b( N! t' ^9 E. Z
}
6 p" o- v3 R1 I" t% _) g 3 S' X |3 W9 M0 S; y
// Get a handle to the BOM Items. - ^5 A, M: ?' `
Item bomItems = results.getRelationships();
$ Q: j$ d: ?) eint count = bomItems.getItemCount();
1 p/ H% y [, M O9 }int i; 8 Y# v! o/ X; a: {! v
! a# y8 C6 p6 O// Create the results content.
6 h' h: M8 ^# g% v" M1 I L3 Gstring content = "<table border='1'>" + * s, b) |* ?4 t5 o
"<tr>" + ! O/ F8 W; m4 _4 ~5 h1 o
"<td>Part Number</td>" +
" D1 n0 o: N9 ]0 A+ ]4 z. T9 F# b "<td>Description</td>" + % \' c4 l! W" N1 _/ w
"<td>Cost</td>" + & `0 K0 k; Z8 K9 z9 c
"<td>Quantity</td>" +
' y- u. Y- y7 l- l3 i "</tr>";
4 @5 B! O f" x" b9 H 3 F: i( {% |+ y5 N& D5 A
// Iterate over the BOM Items. + f4 H+ s# o5 L V$ J7 i% E
for (i=0; i<count; ++i)
% K: {/ L4 l7 K+ v2 C+ p{ . Q# Q# d' W/ v5 n: x9 M
// Get a handle to the relationship Item by index.
" f% L& ~3 s8 R2 r Item bom = bomItems.getItemByIndex(i);
6 K2 Q5 H0 _1 `7 }! g+ \// Get a handle to the related Item for this relationship Item. : }- b) f( t5 I& i4 F" R: v
Item bomPart = bom.getRelatedItem(); ! u }' f, r! O* F& i! [& C
& W; C3 r& m; O$ }9 [9 v# C content += "" + ~ V7 W4 a+ D
"<tr>" +
, p4 X$ S: F& R. [ "<td>" + bomPart.getProperty("item_number") + "</td>" +
) `" W, p* a; v5 A "<td>" + bomPart.getProperty("description") + "</td>" + : H V+ r# m$ Y' G, E$ a
"<td>" + bomPart.getProperty("cost") + "</td>" + 3 h* ?- D* X' X. v9 ]9 _
"<td>" + bom.getProperty("quantity") + "</td>" +
3 _9 R8 z, D, t6 d "</tr>"; & a9 C- {' u/ h2 O g! h' J4 l
} : Q0 X2 K/ v5 S
content += "</table>"; : i8 {* |$ }# K: ^" j
; d4 R- J9 K8 a0 rreturn innovator.newResult(content); " C% J: f/ I: v* Q8 b1 g
% N& c7 R9 C7 E/ Q/ D# U' _ q+ @( E5 B3 V
, n6 Y: c% W7 ~% N8 [) ~) t1 _# n7 Y# W- T' D4 s/ h( f
; ]& x0 a; G! F* M
# m" {* |2 \! A: ~* f7 k: r( i( p5 A 0 d5 t) a! w; o4 r& p, p
Page 46 2 n9 r- f4 N' q, M2 i0 _. }* ]0 S! B; d- Z, ]
4 j4 `: {! ]8 g# w
Copyright 2007
- R* M, q7 }2 R! x8 m9 g9 y2 \- k" DAras Corporation.
( `3 `+ u( N7 }8 y+ @3 LAll Rights Reserved. 4 |/ @' V0 b% Z0 c) O7 [/ w
VB.Net
; S) A! w& b$ W* }/ E( \4 l0 TDim innovator As Innovator = Me.newInnovator() 0 p9 u- v |! r
# F! N* K8 x. Q, `: v* p' Set up the query Item. # P' V) o, ~) k* F# \
Dim qryItem As Item = Me.newItem("Part","get")
$ d* ?" }0 W+ h* lqryItem.setAttribute("select","item_number,description,cost") ; G+ |; p3 e+ W
qryItem.setID(myId)
6 x- [, d5 k' t5 r- W# I% U 3 T8 X* B6 ? c+ @( D2 b/ A4 D' l
' Add the BOM structure.
1 c, V( m/ H! S; D1 [* ^5 [( E6 iDim bomItem As Item = Me.newItem("Part BOM","get") ) ?' N V3 R9 m9 f
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") * y! p: N. R) r% A- {1 ^: f
qryItem.addRelationship(bomItem)
7 X2 C( `! o3 l. s9 q# B ! P; o0 d: [6 Z5 L1 Q- n% {
' Perform the query. 5 t. ?9 S* q. T* r
Dim results As Item = qryItem.apply()
j, |0 A4 @/ h8 @) V8 @+ U
+ F$ J4 g4 e- @- X2 z! r! e$ {' Test for an error. 2 d* j; F( K8 Q' y; N% N
If results.isError() Then % U5 v+ m; o) g3 p2 D9 l
Return innovator.newError(results.getErrorDetail()) ' x, F6 y. W+ D
End If
$ _& E- y2 [% f & s8 O. b7 R: O* ]7 ]3 H
' Get a handle to the BOM Items. & h" ^! y2 k# i
Dim bomItems As Item = results.getRelationships()
* Q0 o. u; u+ R9 T' A1 w9 XDim count As Integer = bomItems.getItemCount()
; e( z0 v4 n* F( k$ UDim i As Integer
( K1 |% g" B. T5 g: k( t9 u: \9 s
2 X7 L7 i# Y" C0 R; g' Create the results content.
# M7 L$ X5 R; t H3 S; g" VDim content As String = "<table border='1'>" + _ 8 {4 B; X t* ~. k1 E1 G
"<tr>" + _
$ v! \# K, {5 a "<td>Part Number</td>" + _ ; g. Q1 A6 Q1 q- g8 a* ^
"<td>Description</td>" + _
* S, a1 U2 A( m! N3 c( }6 o "<td>Cost</td>" + _ & S$ G; v2 C& ]7 I1 D3 Z
"<td>Quantity</td>" + _
6 R* K: b$ C$ P s/ A "</tr>" ! \4 k+ f8 N& ^/ W
( C) v ? ~# I3 r. m/ M' Iterate over the BOM Items ! U' a; c( G c* X! x
For i = 0 To count - 1
$ B, e: @8 o7 J8 Y1 }' Get a handle to the relationship Item by index. 7 S6 l2 i4 u1 d) `7 {
Dim bom As Item = bomItems.getItemByIndex(i) 1 f. B/ @+ q0 @; V
V2 ^( Y1 J: F# j; y( N r4 ^' Get a handle to the related Item for this relationship Item.
3 _& ~4 \1 T+ r Dim bomPart As Item = bom.getRelatedItem() 8 Q! q6 a& [% Z5 g7 V
_) ^; g, a; P$ @: f' w7 ^/ K
content += _
4 B' m$ |+ k: n% Z# s" e8 T! ~ "<tr>" + _
6 V2 L/ n$ b; n/ T "<td>" + bomPart.getProperty("item_number") + "</td>" + _ , B( ?1 }4 O5 Q* _* _0 O
"<td>" + bomPart.getProperty("description") + "</td>" + _
- X' q& b3 q) {, ~' B "<td>" + bomPart.getProperty("cost") + "</td>" + _ 0 p% ?+ r. r0 \3 Q4 u) O
"<td>" + bom.getProperty("quantity") + "</td>" + _
/ s& p' l3 [9 B/ v7 g "</tr>"
1 I# G% m( e$ L8 C+ r. J- gNext
! U- u, n T, }% t1 D4 L/ `) Icontent += "</table>" * S$ `) s5 Y6 ]$ F% Y! k7 p
- Q' q6 W) g: [( Z) B) n. y
Return innovator.newResult(content)
! p( d7 M* X+ u V( e# R0 h2 z
+ Q5 n* X1 w# L. J% }4 w5 n |
|