|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 0 X* z! Q% w- a6 S# t# O: s
To query for an Item and retrieve its structure you build the query as the structure
+ n3 i, P0 P( U" K7 O6 U8 `you want returned. Use the IOM methods to add the relationships you want and ! Z' Q6 k& w5 y2 L
build the structure in the Item. The server will return the structure that follows the
, k# I6 g' r# O7 s# I/ Z" c _request structure. ; J& m! c" s* u" n0 r$ t
This recipe illustrates several related concepts together, which are how to get a set % b! v# e- c5 S; V0 h* u& Z* y
of Items from an Item and how to iterate over the set, plus how to get the related 3 s7 m0 c$ b* s# u
Item from the relationship Item.
5 s3 c2 {; K, fJavaScript
2 w- Z( b! h0 X& F7 Mvar innovator = this.newInnovator(); , T" v) y8 x$ G' n
8 z. N7 a. S& d6 _3 e( r// Set up the query Item. , L$ a- h! k- r
var qryItem = this.newItem("Part","get");
+ a- I! y: z' Z# oqryItem.setAttribute("select","item_number,description,cost");
$ y/ u, M4 r6 d ~5 x& v4 x- NqryItem.setID(myId);
$ ~1 s* ?$ N, S6 P% N6 F4 L / }& B# g. i' E/ p, r* k& t8 _
// Add the BOM structure. . l" M0 L8 }* O0 r
var bomItem = this.newItem("Part BOM","get"); - W5 N4 r0 n/ u
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
4 A. m8 J' k, T4 ]' t/ H* mqryItem.addRelationship(bomItem);
$ W7 _; Z/ s( d" _# v7 b ( r0 Y4 ~5 y8 t. H3 ` C
// Perform the query.
k" q1 g. P. k6 c' _var results = qryItem.apply(); 2 }$ ^# G3 j) e$ G. c5 k
- [9 I9 Z8 [4 u6 J. X; o// Test for an error. % u7 [1 N5 `. j; y6 _5 {1 D$ Q! \
if (results.isError()) {
, X( Z& ^5 ~ l# ` top.aras.AlertError("Item not found: " + results.getErrorDetail()); 9 D7 e0 F9 D5 ]
return;
R/ k9 O% g: u( M: M4 \: B$ s}
) K2 b; t( E* y9 ]+ |- R 4 r1 z E1 O& b% C) e
// Get a handle to the BOM Items. 2 d& k: [' H+ g$ P
var bomItems = results.getRelationships();
$ \% m- H: R$ ivar count = bomItems.getItemCount(); , r: Y. K) ?8 ^, ?6 w
3 E" e* T9 S3 G$ d/ z8 l. N" @
// Create the results content.
8 r/ h$ x/ _" ~2 n/ fvar content = "<table border='1'>" + ! T; M; c/ w& ]1 z
"<tr>" +
' |% R& B2 y" `3 {" z "<td>Part Number</td>" + + w- i" O$ o. p7 I" \6 L Z
"<td>Description</td>" + 0 E m: d# Z2 w3 k) j
"<td>Cost</td>" +
! h2 S" P2 T2 e2 { "<td>Quantity</td>" + ( |( }# P: o! h8 a
"</tr>"; 6 g0 S5 r5 R) ^( x F8 Z
8 r4 o: d2 s% g2 M// Iterate over the BOM Items. . o/ E6 }5 j/ I5 q5 p6 G u
for (var i=0; i<count; ++i)
: n- p) ` U! G! p( c) t{ * r# B: D, N9 B9 F0 h2 W
// Get a handle to the relationship Item by index. 8 h. C: o4 r& j$ F2 Z$ C. q7 d: H
var bom = bomItems.getItemByIndex(i); 7 j a) e: ?! }/ l0 G- B! r4 c! |- R
// Get a handle to the related Item for this relationship Item.
; L: p1 Z0 k2 X. E7 s1 U7 w( m var bomPart = bom.getRelatedItem(); 5 V$ v$ \# i" m, Z
! N% d% Y) {, \/ A( b5 f content += "<tr>" +
' b; F1 D/ Y, l [3 x* ? "<td>" + bomPart.getProperty("item_number") + "</td>" +
8 ^) H. Y! i2 Z "<td>" + bomPart.getProperty("description") + "</td>" + / _1 n9 z" {) P9 G
"<td>" + bomPart.getProperty("cost") + "</td>" +
9 @# [- b) ~2 \ "<td>" + bom.getProperty("quantity") + "</td>" +
) U! T* [. A0 ~6 g' s4 ]1 i "</tr>"; 7 U" @7 j! e) M' D( `& j1 W0 I. k/ Z
}
8 n* F, m3 K0 W4 oreturn content + "</table>";* {2 q( D( H' D
/ k: t0 z6 {% L2 V
. s) T: G0 Q) ?6 J! x- Q8 u
' u' i7 K% b$ L y/ ^
4 v: d7 ?, `$ _$ TC#
3 o" B( J1 C0 Y/ E5 N' jInnovator innovator = this.newInnovator();
- Q$ N: i9 ~- U9 y; o
3 O! u& Z2 q* @// Set up the query Item.
. F. ~- U1 l3 e# f0 k+ `$ KItem qryItem = this.newItem("Part","get");
$ \# \* G8 V, Q/ B5 R3 d1 zqryItem.setAttribute("select","item_number,description,cost");
7 N7 M7 o6 D2 m/ X2 O* j: Z- W" lqryItem.setID(myId); ! I' N! J: j8 g& M; ~
- X3 |. i7 _. \8 V! A
// Add the BOM structure. 0 y t; m* h( s1 ~9 ]
Item bomItem = this.newItem("Part BOM","get"); 9 Q2 H- |6 h, h
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); . S: c- m" f- `- i9 Z) c5 V
qryItem.addRelationship(bomItem); / O4 J6 x# A4 K; ^5 D' O
8 I( ^/ \. f0 Z2 U6 X+ \
// Perform the query. , ~; ]* G& D. E ]
Item results = qryItem.apply();
8 ~( z0 I9 }" r a1 X: o " P4 M6 W" m% J+ ?6 M" o+ ?
// Test for an error. 8 {% ]# S" U8 ] {0 x! n& j3 [2 p
if (results.isError()) { / P6 ?1 i' @+ H3 @
return innovator.newError("Item not found: " + results.getErrorDetail()); * V6 H4 r8 K% @" P: V! a& [* O# K
} 4 \& q8 Z- ^5 i0 x
* i/ J' y1 f. }. L// Get a handle to the BOM Items.
1 o" Z2 V1 v: A2 q6 y$ iItem bomItems = results.getRelationships(); M3 K& e J0 u/ k, q( T [
int count = bomItems.getItemCount(); ) c* {) |5 ]+ C7 p
int i; ; `2 F4 o; Z5 d0 m+ }! t5 ^4 E# Q0 F
& Z2 ?: k- s2 L+ z
// Create the results content. $ R6 u; _! J" A' `
string content = "<table border='1'>" +
# k# y+ e& [. |5 k( z! l9 M! O/ W1 _' c" B "<tr>" + 5 L9 t' M7 S; h( g+ |
"<td>Part Number</td>" + # J( R1 J# A4 f+ v) n& N
"<td>Description</td>" + # p/ Y! n- L( W
"<td>Cost</td>" +
d4 ~% E0 Q4 I( W "<td>Quantity</td>" +
7 S- @2 \; L) L. B+ ?/ Q: g "</tr>";
* r$ R; C% N- E. j7 `+ @+ ?" ` $ N5 ], v3 k3 M/ ?
// Iterate over the BOM Items.
4 {7 L0 V8 t9 n P( Dfor (i=0; i<count; ++i)
: `0 m" ?$ A) G# R. D{
` w' Z* j5 A$ [" J; H// Get a handle to the relationship Item by index. / m5 ~! E! L' J( y# X1 e
Item bom = bomItems.getItemByIndex(i); ' r. \) x6 ^+ ^9 O3 U. v. {
// Get a handle to the related Item for this relationship Item. ! T" `$ `- ]. b/ T% @' N
Item bomPart = bom.getRelatedItem();
1 T% D+ o9 t3 P
. L v: k7 Y7 p+ V4 v6 t4 d, a content += "" + 2 ^) E0 e8 X3 u8 g# q! p6 v
"<tr>" +
. E+ X w8 x: m5 u9 W5 B: d "<td>" + bomPart.getProperty("item_number") + "</td>" + w7 v# i" H- N* ?
"<td>" + bomPart.getProperty("description") + "</td>" +
$ {; r/ X, n6 Q6 R/ Q2 B. z' p4 p "<td>" + bomPart.getProperty("cost") + "</td>" + 0 x7 S x- E. E; V
"<td>" + bom.getProperty("quantity") + "</td>" +
& K/ I; K ?' a7 f/ U5 K "</tr>";
9 I5 ~, O9 S/ m/ b3 I) A}
3 e) J. j8 k' S& L9 _content += "</table>";
: }4 B% l* S" t
+ L" i& \" T& X) a) Ireturn innovator.newResult(content);
S$ \* K+ M& X) l
1 e! `) M1 S/ |5 A" D7 A( S! @% v) }% R; C
3 M U+ V* t7 M1 P( L8 N: F9 H. [' o1 K
* k7 u! b2 M4 b' r/ M
f$ g: ]; o4 d( U Q8 V4 [1 Q% N+ d
Page 46
% M2 c( J. @. |3 T
; B% z+ B( B2 _- f/ y3 xCopyright 2007
- f; ?7 Z) k& d8 U) w6 X& zAras Corporation.
! T4 }/ j7 W( X& f+ J* L |All Rights Reserved.
5 E9 @3 \; P6 x, m/ C; Z6 DVB.Net
7 x3 O6 T9 y6 [) c {3 |2 ^Dim innovator As Innovator = Me.newInnovator() 3 e, ?9 d: u. c; O) M( @
% f, Q: ?$ `- B" ]9 b% ^3 _' Set up the query Item.
" M3 g$ q% @( C& _9 j2 RDim qryItem As Item = Me.newItem("Part","get")
) C9 I( n) O( e& E( E3 h+ X, wqryItem.setAttribute("select","item_number,description,cost")
7 T8 s+ [' W a$ }) u/ wqryItem.setID(myId)
+ V) l' S# Q q+ t: p: W
, [; k+ X/ B9 j0 T4 P9 A( l" g' Add the BOM structure. 3 C) O8 `% e9 Z' S0 c2 T* n
Dim bomItem As Item = Me.newItem("Part BOM","get") 7 g. l; ^% f: [ ^2 ?2 l9 r
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
/ _+ ?" V4 w% MqryItem.addRelationship(bomItem) ) F- ^1 _6 R7 e
, j( C9 L) R4 G' g& b3 _3 o' Perform the query. + p+ l+ G+ O& ~ \5 |
Dim results As Item = qryItem.apply() y% S$ c8 a4 k+ Y0 M4 z# e
) T6 r W$ x# M* U1 r# {8 S; e6 V
' Test for an error.
" z4 ]: l3 B# P* ^& V0 KIf results.isError() Then . P( Y8 k3 t2 e
Return innovator.newError(results.getErrorDetail()) 2 y, L+ b9 {/ \! _" R
End If " [# x1 m1 D2 h. T
( e$ q% F( a3 m. K8 C& u
' Get a handle to the BOM Items.
: v4 U- ]9 W" n. _, m( RDim bomItems As Item = results.getRelationships() 1 B5 Q- `5 j5 K) K7 {- k
Dim count As Integer = bomItems.getItemCount() - O# m9 x7 `. c }$ {, n
Dim i As Integer 6 f3 a/ C4 W% R
! `( l( {: n* ?' ]( X9 K
' Create the results content. ; F2 W: E8 r$ C! n- ?$ \6 O! a
Dim content As String = "<table border='1'>" + _
6 H" v; t: ^! U5 t "<tr>" + _ 0 o& F" a1 M( {+ k) E) f* W
"<td>Part Number</td>" + _
- N$ t- E* o# W "<td>Description</td>" + _
" ^: l+ S7 E6 p5 r/ C, N- ` "<td>Cost</td>" + _
% M/ E$ K/ t1 ]$ t% y% v "<td>Quantity</td>" + _
) E4 k. [* G% m" k ` "</tr>"
' S- y- q. x9 I `# [
0 x+ c9 C7 }# E5 D P' Iterate over the BOM Items 1 h( }7 k$ ^9 t' T
For i = 0 To count - 1
0 L9 X; J( V2 v* ^& v1 v" n' Get a handle to the relationship Item by index.
2 K' y. m# b( v) T# M Dim bom As Item = bomItems.getItemByIndex(i) $ E: |& A+ t/ [- H4 d
! R4 ~7 A) ^, r. Q- J* r
' Get a handle to the related Item for this relationship Item.
. Y# \5 w% z. Q" }8 H- i Dim bomPart As Item = bom.getRelatedItem() 4 u( m# n P4 `9 H: B* o8 V
$ u" T X! t) k
content += _ / [9 m2 \. B) r& L7 m& X3 e5 ]0 o
"<tr>" + _ 5 z+ v( x1 v9 I5 I4 D+ Z; m
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
& {5 Z/ R9 W. m/ U- X "<td>" + bomPart.getProperty("description") + "</td>" + _ 2 M# ~* d3 _: B2 F* b
"<td>" + bomPart.getProperty("cost") + "</td>" + _ - C9 @8 J0 R u/ y
"<td>" + bom.getProperty("quantity") + "</td>" + _ , F& g8 g* b0 f
"</tr>" + `6 i. \% j. F2 i* |( f% ^
Next 6 x6 y- G. G* j* u$ k
content += "</table>" ; v' z: r6 e: o3 a- c% q; `- {# r- [6 l
# Q8 B4 w1 p! ~# }: Z# e
Return innovator.newResult(content)
( n& @2 \8 c- s( [. ]4 i+ ?( m$ D9 o" q0 d% \$ V/ k
|
|