|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique $ e! @2 C& d6 P; G4 W, L# s) h: q
To query for an Item and retrieve its structure you build the query as the structure . S. j- m+ [ Y, k9 U7 e7 c
you want returned. Use the IOM methods to add the relationships you want and - P P* M5 N( y' Z4 u6 w8 ^
build the structure in the Item. The server will return the structure that follows the 6 f( D5 e) ]8 F8 t( W& u* c
request structure.
& I/ B" ~9 Y# U0 ^7 r' @This recipe illustrates several related concepts together, which are how to get a set
2 X$ ^( |5 Y2 y* P3 i& Yof Items from an Item and how to iterate over the set, plus how to get the related
3 e3 _2 E. c! _) { @, LItem from the relationship Item. 6 J4 G9 P" |5 @# S; _2 b& S
JavaScript
5 Y. y& A5 a6 N$ `var innovator = this.newInnovator();
3 ?$ z* i- z9 w: ^
9 u! I/ M& R3 M& H' d# E. L// Set up the query Item. 3 ?$ e' l) e0 g5 g% M
var qryItem = this.newItem("Part","get"); " E0 |! p# ~4 ]1 M) L: Y* a+ J
qryItem.setAttribute("select","item_number,description,cost"); 5 y Y7 l6 y# U% B( d; V" [
qryItem.setID(myId); 2 M! f( o# W- d! v* u, u
9 R5 T( y4 B, s6 y
// Add the BOM structure.
( j5 l( Q# q4 c R0 D& M% x+ N; Fvar bomItem = this.newItem("Part BOM","get"); , E, S2 W; n* F' V, |
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
% a. v; m9 ^4 `6 a' d2 ZqryItem.addRelationship(bomItem); " V( ^; z" a# ^
4 ?$ X) n2 \% M6 ^5 }# J
// Perform the query.
0 ]3 e9 |2 M! o6 |. A5 U$ e7 p" Uvar results = qryItem.apply(); * y4 I& y$ @( ^; x$ f
+ ]; T: @4 ~! O// Test for an error.
3 v* a6 L, k: o5 v3 Oif (results.isError()) {
3 r( u( J7 U |) W: b top.aras.AlertError("Item not found: " + results.getErrorDetail()); 8 T& T/ B; B/ M3 t6 C! I
return; ' D! i, K+ n% E$ o" `) D- y) U- [
}
; g2 A6 F; Y$ {+ P; k0 i
3 P8 Y7 T6 x- h, Q// Get a handle to the BOM Items. * i Y3 ^: K/ c& a/ Q0 ?
var bomItems = results.getRelationships();
2 t" d+ f9 m0 U. vvar count = bomItems.getItemCount(); + P0 I3 r% u5 A
; P/ f* U+ _9 [- W) i# J// Create the results content. 9 N1 c( [/ A0 x
var content = "<table border='1'>" +
1 [) @& |/ E2 b8 P1 z "<tr>" + 9 Z6 @; b% @2 i: n' u
"<td>Part Number</td>" + 8 }5 w+ _6 Q3 T0 }* ?! G* K
"<td>Description</td>" + % z; t" v$ ?8 @. Q- S5 v
"<td>Cost</td>" +
" M: r1 R& l8 b, Z' o "<td>Quantity</td>" + " ]7 f2 k/ S# o% l) o
"</tr>"; % \: t! F+ k& [ i6 g' }0 v
5 r' ^; P2 m7 _ m+ t4 L// Iterate over the BOM Items.
/ c) |8 J% x# ufor (var i=0; i<count; ++i)
6 r/ N. O- L+ ~, A{ 8 _& Y# o8 g+ W- {1 d- b4 ^
// Get a handle to the relationship Item by index. / J' A0 \% a! v! g
var bom = bomItems.getItemByIndex(i);
- G7 _+ s& Q$ I/ z) K6 E( w// Get a handle to the related Item for this relationship Item. ) I# j. b% J$ [
var bomPart = bom.getRelatedItem(); * A7 G8 y1 c, [/ T8 m
' g0 T0 X/ _. i" z8 V. _; H+ h
content += "<tr>" + 2 u" T. \2 ^7 E( n& X) P
"<td>" + bomPart.getProperty("item_number") + "</td>" + 1 W V, |# o0 L" w
"<td>" + bomPart.getProperty("description") + "</td>" +
$ m$ o% P8 F7 m) o2 l- [ "<td>" + bomPart.getProperty("cost") + "</td>" + % L& x( j! X; H. b; d
"<td>" + bom.getProperty("quantity") + "</td>" +
( |9 B' S4 j( ] v "</tr>"; * D% P) A2 A" `# S
}
! r/ l1 ~- r \3 qreturn content + "</table>";
3 ^; E3 a- x1 e( }- T1 e- z0 a( V' m' B
# l1 F) q2 w8 b( ]8 M2 R) c N6 e% A# I. W. z! b6 p, c7 G
8 j1 y+ W) ~ J% V# TC#
+ Y! i) [, L* iInnovator innovator = this.newInnovator(); 2 r: n3 y; s4 L0 A
; A3 \5 H' D5 v; u: c! i// Set up the query Item. & q8 k' N: m9 Q1 Y
Item qryItem = this.newItem("Part","get");
. N* s: ?- I6 ^7 w3 `5 t! ]9 yqryItem.setAttribute("select","item_number,description,cost"); s u, @/ H; R$ n- H: V6 W
qryItem.setID(myId);
1 I- x6 e6 O2 j8 P8 J, l: \" a
+ k: _$ v% O) i+ z) g) M* O// Add the BOM structure.
( n+ Z4 u: _4 A$ g3 qItem bomItem = this.newItem("Part BOM","get");
3 Q2 P K+ q- T4 j9 ]' ybomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); , B, V6 {3 c7 S7 [5 P, `% q7 F! L1 ^
qryItem.addRelationship(bomItem);
8 ^8 S9 f' s( @& {+ A( d , `6 f, d8 @6 d$ I
// Perform the query. 8 [# ~; K, f/ h& V; s0 m5 F3 v
Item results = qryItem.apply(); # e9 g s4 D* e- h) T6 m
3 a% U& J- d9 E" m$ M
// Test for an error. 9 c8 j0 S5 ?+ ]0 j5 b) S2 q% C$ y
if (results.isError()) {
9 V& S: y, q2 S& T6 Q return innovator.newError("Item not found: " + results.getErrorDetail());
$ w1 O% R3 E Z+ t* h}
% b3 H( V; C7 K% x- ]
" i4 c) F2 m0 C, q0 R// Get a handle to the BOM Items. 8 b# O( Y. s7 l. k
Item bomItems = results.getRelationships();
# c( m. V( g& Q* M+ F- w. |, ~int count = bomItems.getItemCount();
2 G' l% a0 H8 T) n# |& }int i; 9 ^* ?1 O* |. T1 k8 ?- F
* G& e6 C3 \4 a- Q// Create the results content.
; W* ~0 J) N. U, j3 X; ?" D# jstring content = "<table border='1'>" +
+ r$ S7 J$ }8 X. P$ |$ H "<tr>" + / e: j; u% Y: t/ B9 F2 h. }
"<td>Part Number</td>" +
* F" y3 r- z( v# \# F "<td>Description</td>" + 3 u7 G0 q0 Q' b3 V
"<td>Cost</td>" + 6 s" F! y' [/ @ y$ u
"<td>Quantity</td>" +
) V& }1 J1 z) J) c; W! p- r "</tr>";
4 y1 e( C8 ~$ A9 @4 ~ + l9 ?- Y1 W3 z, Q' ?
// Iterate over the BOM Items.
$ Z8 l! N! N2 V0 f. ^. c& t2 o0 m+ gfor (i=0; i<count; ++i)
6 F: |: M7 O. ~, ~6 x6 I, e: I{ 8 q: F& S5 N1 p. f
// Get a handle to the relationship Item by index. ( H2 g6 C, B; z# v8 B d
Item bom = bomItems.getItemByIndex(i);
B! D. v2 Q* U2 p4 @( ?+ r( j// Get a handle to the related Item for this relationship Item.
& p+ ~% Z& g# A1 y8 u9 t Item bomPart = bom.getRelatedItem(); . i6 U; f# t& ]9 {, `6 B
; [+ a9 O# k4 @( o1 J
content += "" + & J7 c* _3 m1 b/ _! M5 E
"<tr>" + ' @/ c: u, P8 a4 ?# `$ }* ~
"<td>" + bomPart.getProperty("item_number") + "</td>" +
v, t6 d4 u2 {$ H) d "<td>" + bomPart.getProperty("description") + "</td>" +
: Q! W6 I X8 j! L& a( b& o "<td>" + bomPart.getProperty("cost") + "</td>" + 5 |' I, M) h0 I* |4 W, H7 m% E8 E
"<td>" + bom.getProperty("quantity") + "</td>" + ( r# M# Y( T9 h$ x
"</tr>";
, {9 O) q9 v3 ^4 D}
) n w0 ~0 k. kcontent += "</table>";
: Y2 R4 n9 M1 `8 w7 f, @- X! v : m+ f: C. a) y- `
return innovator.newResult(content);
9 O1 W$ B P$ w6 ~. t
5 t: x( T, n; M& ^! a8 r0 e) Q/ A, G9 v2 S4 j' J$ Y x
2 }6 A' g+ f+ ^9 w5 g
, h5 G' q& a3 d n) ]& `. N) p* U% T1 ` C. ]: N5 Y
@( L$ N2 I! h9 i! r( `
2 o, S# z1 M8 b3 ]1 }6 j9 y6 p- B. d Page 46
S2 S+ G) B2 M( o 8 v9 P8 g' M# T- A; [; v
Copyright 2007 - n$ {: V: }: s! Y2 h3 o
Aras Corporation. 8 ^7 E1 i. }* }( l) z% T
All Rights Reserved. + p3 I8 i+ \9 D
VB.Net
7 s8 g/ z3 R: G3 cDim innovator As Innovator = Me.newInnovator() 2 L4 j! |1 g/ h2 }! P9 H
, f$ L4 B$ l. @) j! [' Q/ U' Set up the query Item. 6 I1 \1 y5 j! A. g' ~4 J! j# K7 a
Dim qryItem As Item = Me.newItem("Part","get") 8 |# L4 P; P' [2 R3 [
qryItem.setAttribute("select","item_number,description,cost") 4 ^% i4 @$ x7 k( l! A* U# Y
qryItem.setID(myId)
$ j+ e5 d; o B- r3 A) H
+ n0 X6 V5 R! _, i* r0 R( N' Add the BOM structure. " Y6 s! v# e8 J5 W
Dim bomItem As Item = Me.newItem("Part BOM","get")
9 q9 A& ]0 n6 ]( x) K |bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") % O4 W, V% O. Y
qryItem.addRelationship(bomItem)
. [, m4 R) b, ]$ r: s/ Q ) J% V* K/ `0 w! Q; T0 f A
' Perform the query. ! K3 h4 m; V) e! @' T
Dim results As Item = qryItem.apply()
) {! ^( k9 U$ R) y4 v1 ^- k
4 K6 I; @) ], X1 F( J$ g' Test for an error. 5 [! w6 i( V1 N' o; U
If results.isError() Then
; |/ h3 H& ]! ^* | Return innovator.newError(results.getErrorDetail()) . A% z/ p: u. m/ n
End If
: z, b* e- m) k3 m( F ! G, T. s6 i) V) v
' Get a handle to the BOM Items.
( f3 o! _7 I: ~Dim bomItems As Item = results.getRelationships() + L0 L+ f/ g8 z' K, y
Dim count As Integer = bomItems.getItemCount()
! I; W% |/ Q% ?9 ?- q8 LDim i As Integer ! H* J k5 {" M. ~0 O4 H
% m% j3 h2 W+ ]5 c9 k' y' Create the results content.
: ?" C- T/ `/ X, Y( }. x9 BDim content As String = "<table border='1'>" + _
- Y; x- R/ r) X; x. ^ "<tr>" + _
/ z/ G1 y- D5 R2 A "<td>Part Number</td>" + _
8 B: y2 a2 r( s, A5 A "<td>Description</td>" + _ . U- M0 o" |, ~8 a9 Z: M8 E
"<td>Cost</td>" + _
( M4 ]! i/ ?0 Q3 l9 u2 k "<td>Quantity</td>" + _
/ _2 b* j' m8 F; d- b) x0 n5 t "</tr>" % @2 `5 s9 T1 r a
9 g- w/ l! `2 @; r$ R
' Iterate over the BOM Items
; m# O" x- |4 |6 j/ f# ?+ p uFor i = 0 To count - 1 0 V, x- P. ?/ z+ b& t
' Get a handle to the relationship Item by index.
+ ^- `: }7 t* a5 S# _ Dim bom As Item = bomItems.getItemByIndex(i)
* z- q3 A$ X8 F; R3 g 8 g5 b4 K( ^* F2 j% w% t
' Get a handle to the related Item for this relationship Item.
) m9 B7 L0 w+ b( U' @. ~- n- U Dim bomPart As Item = bom.getRelatedItem()
~: m' O0 k1 M$ T" ?4 f5 J , a5 w7 s1 E( u5 p
content += _
6 J+ } [4 \, _$ t "<tr>" + _ ; o3 _* m i9 W; ]
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
) v" D5 Z5 v3 r: l "<td>" + bomPart.getProperty("description") + "</td>" + _ / P5 J' Z0 D2 m4 K
"<td>" + bomPart.getProperty("cost") + "</td>" + _
5 g# I: ?$ ?4 M: M1 ~ "<td>" + bom.getProperty("quantity") + "</td>" + _
4 K* v( O/ i" {! i) } "</tr>"
( {- T% ^5 \+ n0 c0 wNext
& J2 y4 a/ _ Q/ W. ^" @6 T# G. ?, Xcontent += "</table>" v+ {$ K5 s: H K) c( q& R& p3 U
, o0 y5 j% M* `+ I6 [; iReturn innovator.newResult(content)
# @6 s- x8 J" O n1 C+ | Q/ W W
# o; l x3 t( z# m! }5 P4 I7 t |
|