|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
) v* q h, X6 |To query for an Item and retrieve its structure you build the query as the structure
8 E# ]5 I0 `) Q! E, Hyou want returned. Use the IOM methods to add the relationships you want and
! c3 j5 p F- ?6 l( @- ubuild the structure in the Item. The server will return the structure that follows the ! T" r0 g" L2 p( q
request structure. # `# t% O7 ?: A* ?" y2 K
This recipe illustrates several related concepts together, which are how to get a set + w/ F1 x+ J: F9 V) h: Y3 w
of Items from an Item and how to iterate over the set, plus how to get the related
! I Y1 o) |. t$ TItem from the relationship Item.
2 _' V. q/ h& ]* p6 G: d1 Y9 _; vJavaScript " S. i( ~* ^# h% h/ K
var innovator = this.newInnovator();
) W; Y) k) d4 D' ?' M & b/ H+ A" {' m7 c4 x# a
// Set up the query Item. 7 p& S# J) f0 f3 |( g
var qryItem = this.newItem("Part","get");
4 j" g: t2 Y- k* P3 N; ?7 MqryItem.setAttribute("select","item_number,description,cost");
! D g, q7 M% C8 A/ I5 HqryItem.setID(myId); : }4 t5 K3 {( H: I' l! A) \
0 ^; y8 @2 \/ O# u" u
// Add the BOM structure.
, J0 @2 }+ U$ r! G1 c$ x) gvar bomItem = this.newItem("Part BOM","get"); / y+ g% W6 D; P
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
9 K# ?1 [5 n( B. KqryItem.addRelationship(bomItem); 5 j2 n4 H/ z* O- M: S
6 f7 C4 \2 U1 ]/ s// Perform the query. 0 L1 p7 t/ B3 n7 n
var results = qryItem.apply();
! U6 y% L5 ?7 M+ ^% O , K: G0 Z& F- D
// Test for an error.
3 l8 F$ k; k. k. K1 G4 [if (results.isError()) {
0 R, T9 t1 |2 F0 C' @6 w: @4 [ top.aras.AlertError("Item not found: " + results.getErrorDetail());
5 L; O; D! p) L/ w M* T! d' c return;
3 f, B3 Q3 j* x} * \) D2 p, A& H+ o# R! w* l
7 H- N0 m U/ J: O/ P7 B( }1 X
// Get a handle to the BOM Items. - h# b7 K/ G, F1 v
var bomItems = results.getRelationships(); 4 y- k9 H/ a; e4 `
var count = bomItems.getItemCount();
6 p- n. h6 m- L, b, N+ m4 F) a) Z- G% r : M+ V2 t& I. M8 h! a
// Create the results content.
2 S1 F& R& s) m: fvar content = "<table border='1'>" + , }/ B$ g, }) F% n, ~
"<tr>" + - s8 Q# P# t7 }5 t- A9 X4 M
"<td>Part Number</td>" + : `6 o5 h2 K" W- Q. W
"<td>Description</td>" +
2 Y" T& R0 v& N0 k "<td>Cost</td>" + : F% y9 E. l* {+ u1 v2 o
"<td>Quantity</td>" +
5 o) l( M! d+ l. r& Y "</tr>";
. p! w- E9 B' A& e
; J" @6 J) J7 h8 T2 n! q// Iterate over the BOM Items. * o% {6 J/ O- y& [7 I& ^6 \- Q
for (var i=0; i<count; ++i)
; ^( \& m1 A+ \$ L, k{
8 X& |+ `1 Y7 x// Get a handle to the relationship Item by index.
. n+ }! i) V' X7 l) F var bom = bomItems.getItemByIndex(i); . \) _3 \6 \, u0 u7 W$ f- ]
// Get a handle to the related Item for this relationship Item. # o$ a" P6 c5 k% d
var bomPart = bom.getRelatedItem(); 8 N4 n8 K- D% i5 s7 }- a
# e* I1 i: T( k @$ V* e6 q& @ c
content += "<tr>" +
; o3 Y/ j5 I# V- {+ ~5 | "<td>" + bomPart.getProperty("item_number") + "</td>" +
" b7 c, f" P6 L "<td>" + bomPart.getProperty("description") + "</td>" +
! o4 \# W( J1 A" K2 ~. [8 n "<td>" + bomPart.getProperty("cost") + "</td>" +
, v! X# J0 ]9 g; o& r4 } x/ @( E& e "<td>" + bom.getProperty("quantity") + "</td>" +
3 |- c( S6 N3 H" I "</tr>"; 2 k7 o2 D/ T# w; u, O. P
} - Z" p8 z% |& @" [7 J5 W
return content + "</table>"; U6 S$ |' Y! X6 }0 T8 h8 F h/ z
" B! m. k+ }- b: s$ Y, C/ Z
, Y; p# f8 ?9 ~' K3 }" G$ Z
& L' P W! ~/ O2 f
* ^' Q5 s+ N6 kC# 3 U; e6 l3 M' h. S) f5 r3 r$ h: p
Innovator innovator = this.newInnovator(); 3 z) x7 L1 a. g) b) U' o) L
: @4 d9 ~! P" ?; d& X3 u7 n
// Set up the query Item.
& V% r9 c( }1 w% \0 w. m# ?Item qryItem = this.newItem("Part","get");
9 u4 j( L, }% P" z/ _qryItem.setAttribute("select","item_number,description,cost");
3 `7 F3 _7 K9 q- j! UqryItem.setID(myId); 2 j0 p7 W$ f! X, D5 Y# e
7 {9 [6 ~- `' y; R// Add the BOM structure. 0 h1 n/ O% `! O, S% V! {
Item bomItem = this.newItem("Part BOM","get"); 8 s5 h g' a8 s$ D2 _6 H
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 3 ?- \1 j( c' w
qryItem.addRelationship(bomItem); ) r, l/ f+ W) { }9 \" Z* E# i
; j5 h# l) N Z* y$ i" }. f% d// Perform the query.
! c/ J7 N- s. y0 N( ?Item results = qryItem.apply(); # q; P- V R6 K5 |3 Z1 l1 l' |
1 @7 \6 m, t1 F9 \# [; F// Test for an error. : Y1 a+ H& I0 V
if (results.isError()) { * a2 W: b# O4 u0 G9 T$ t l" L
return innovator.newError("Item not found: " + results.getErrorDetail());
7 x2 k2 g; K) \$ [, E M} : [! \& t4 Z5 c
' c9 M7 A/ Z9 C2 N; E/ t# u, t* A// Get a handle to the BOM Items. 6 D# J+ V; t1 p9 P ~0 q
Item bomItems = results.getRelationships(); . r! j6 [; n* R ^5 p' N
int count = bomItems.getItemCount();
; x/ M, U# h3 y8 `; Vint i;
2 G7 v6 V# W6 b
6 C- Z0 P9 m* L) Q" D4 n' p// Create the results content.
, }% i% A M# f6 r; mstring content = "<table border='1'>" +
2 g$ y' d8 r3 D, z$ _5 B; C2 G "<tr>" +
4 P( h2 |0 n$ V1 x( y "<td>Part Number</td>" + 6 N* R8 o* d/ Z/ o8 k- g
"<td>Description</td>" + & b4 Z( ^: D+ u) f1 t
"<td>Cost</td>" +
' H3 Y0 Q& W8 _! h m F "<td>Quantity</td>" + 5 ~! l* Y9 y" ~5 s. J, M2 S
"</tr>";
! Z/ A0 I8 }- p1 J P4 S8 Z- @ 0 Y! Y! ?8 k- W0 s) q
// Iterate over the BOM Items. 9 P3 l# v' m2 M# r) [5 V! `# |
for (i=0; i<count; ++i) - d+ k9 m, [! e' _/ Z6 I9 R
{
7 i( t4 ?. ^$ l& K( t// Get a handle to the relationship Item by index. ( x: d1 e0 @1 F7 }& V) d
Item bom = bomItems.getItemByIndex(i); " \$ M) s. b; g. G& Y
// Get a handle to the related Item for this relationship Item. 0 ]; Z" Y/ i! t. r( b; s; z4 j) t7 G
Item bomPart = bom.getRelatedItem(); ! e1 l& ?% _- D( y P: M. x
* ]. }7 Q1 w5 @' V( @+ u content += "" + " W# n3 a( I' M+ K
"<tr>" + ) x2 N4 U" {0 D; [3 Y& ]
"<td>" + bomPart.getProperty("item_number") + "</td>" + - d; `6 |8 ^4 X3 u! W; P
"<td>" + bomPart.getProperty("description") + "</td>" + 0 u' ]3 Z* F0 @: L; e/ s4 ~
"<td>" + bomPart.getProperty("cost") + "</td>" + / D9 V! ~# F; L( d. E9 y
"<td>" + bom.getProperty("quantity") + "</td>" + 5 R1 `8 u. x7 c2 t" ]
"</tr>";
, j7 f! _1 {: t8 a; P}
& i+ u, R$ g7 i8 j$ icontent += "</table>"; ) w. @ Y+ a. ]4 ?
5 z, r- l+ [0 D8 r. f6 }: Nreturn innovator.newResult(content); . V, E# ]5 X7 K* k. A/ b: B
* S4 O( i( V% G5 t9 j
) [4 \) }# T$ ~) S9 I5 a. [( o' s
% [8 U8 d3 j2 P5 A C) {
/ v& Y! s. P7 i7 N- Y$ U. h: J& ^% A' A' a" G7 X' W/ k1 K
1 U6 q% D( t6 r& @. z1 k5 K
Page 46
* S' k1 p; \0 d1 V , d0 u% q; R1 J5 i. W
Copyright 2007 / v! C% |$ v' W9 n, n
Aras Corporation. ' y) j) i& _2 y4 b" g1 A7 z
All Rights Reserved. ! m7 p; _7 k6 D, ]
VB.Net
& U9 l* l- x9 p8 R9 G" UDim innovator As Innovator = Me.newInnovator()
9 O4 b, N$ b" L/ X. Z, \( a , V' Z2 n. z0 q
' Set up the query Item. 2 e3 W( o5 r% y
Dim qryItem As Item = Me.newItem("Part","get")
6 r% f7 H: a* S, sqryItem.setAttribute("select","item_number,description,cost") ) U# e t- D9 L( _" m, T' C! o
qryItem.setID(myId)
! e' @, x9 h9 P, |5 b
5 C1 g; g3 a# W' Add the BOM structure. 2 F! Z: A8 i* ?4 M. x/ k* G* h$ k
Dim bomItem As Item = Me.newItem("Part BOM","get") # J3 F% _" p8 K6 K" t
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
3 e3 R+ s; U6 YqryItem.addRelationship(bomItem) ' w1 k8 I& p7 e$ s
. q1 G9 B0 y7 r# l2 W# K' Perform the query. L2 m7 o3 s1 [$ l+ S
Dim results As Item = qryItem.apply()
0 G( I9 f# K, Q7 f$ V " l2 V' ^( {) ?
' Test for an error. " t' R9 ]# X0 b3 e# t9 F
If results.isError() Then ! l5 H, v4 {. F0 ^
Return innovator.newError(results.getErrorDetail())
8 Q" w9 i* R8 w) xEnd If
3 }8 X* ` B6 J( o2 s# S6 ^ h
' O% a3 u% {1 w' Get a handle to the BOM Items. 6 P* D3 t3 _0 t; W7 n% T
Dim bomItems As Item = results.getRelationships() 6 r/ q5 j; b: l- Y) B
Dim count As Integer = bomItems.getItemCount() ; L( {7 v) ?0 d. ~, q. H4 P
Dim i As Integer
7 x6 b l) d6 [, P$ R / Y' c! W- D/ U" R
' Create the results content.
: f% J+ h' b& a( o1 ^+ jDim content As String = "<table border='1'>" + _ ' a, R0 h2 x" M7 V* z- h5 J: K8 c& G
"<tr>" + _ $ \9 d. _. h& K5 ^. C2 `' l
"<td>Part Number</td>" + _
5 t1 c7 r. Q' r0 o; v "<td>Description</td>" + _ 6 X: e; G b9 d
"<td>Cost</td>" + _
/ M1 O& H3 p7 b6 V "<td>Quantity</td>" + _ 7 u9 u3 K1 V. H/ z
"</tr>"
5 z8 X8 N& P6 F" _7 X4 \5 U5 o
' B5 C1 v$ ^2 r7 }0 U+ v; A' Iterate over the BOM Items
6 T6 j! A- `- x0 ]For i = 0 To count - 1 , Q" j; G8 \- f' j x/ d
' Get a handle to the relationship Item by index. ( k+ U/ T9 Z- o I6 n
Dim bom As Item = bomItems.getItemByIndex(i) 7 Y, e* @1 _! u4 x0 h' Z
1 i" V! ` M8 M' O
' Get a handle to the related Item for this relationship Item.
/ W. a! I$ M, C( h' M Dim bomPart As Item = bom.getRelatedItem() 8 ^" C. d" b P/ V% H1 r& p
5 [. m% z2 _8 f+ W& n9 t) b4 W, Z' G content += _ # k9 Q" f4 \8 }# {6 [" K
"<tr>" + _
3 h- B3 y8 v. A "<td>" + bomPart.getProperty("item_number") + "</td>" + _ : ]: E. E. @5 M# f
"<td>" + bomPart.getProperty("description") + "</td>" + _ % R7 r5 r2 u) \; K# b" R
"<td>" + bomPart.getProperty("cost") + "</td>" + _ 8 Y) s5 |, h& P+ J
"<td>" + bom.getProperty("quantity") + "</td>" + _ 1 o2 |9 v+ w2 O; J* C
"</tr>"
0 A3 L6 s. l4 R. j+ _! X6 ]0 ^7 XNext 4 o0 t3 L" P6 |; d, [
content += "</table>"
+ J/ P0 W4 @5 E4 _
& Z9 Q! I" h7 ^0 F6 _' ?& K% |Return innovator.newResult(content) + J/ \0 G4 C& G3 `; P
. q N6 h- o5 B+ L5 U& @ |
|