|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
% D8 t5 V+ a$ W M( a* PTo query for an Item and retrieve its structure you build the query as the structure
- \ t- A$ o' i3 t1 |7 H% w7 tyou want returned. Use the IOM methods to add the relationships you want and . l/ G4 X* ]# Q0 J
build the structure in the Item. The server will return the structure that follows the 5 d' @ K# x# D
request structure. 8 h9 ^ ?, q# n$ ^, D- C
This recipe illustrates several related concepts together, which are how to get a set 2 H+ N% G1 e: L" d3 s, t8 q
of Items from an Item and how to iterate over the set, plus how to get the related
e/ s: V& [3 y1 y, ZItem from the relationship Item.
1 R$ L {' Q# {9 W2 `7 D* QJavaScript % k+ |7 b# v, d
var innovator = this.newInnovator(); + i, r2 Z4 p6 f3 l; s. ?0 ^$ x
& k: ]4 S; G' V6 v6 d1 ]; L// Set up the query Item. * h; q- d/ V7 L4 Z" |$ S
var qryItem = this.newItem("Part","get");
* w3 }# [' l1 p8 lqryItem.setAttribute("select","item_number,description,cost"); & |0 }" X3 u3 Y; U
qryItem.setID(myId);
7 E* e; D; u8 x8 w/ G' C! s ~2 q: |/ X4 o, O! S( n. l
// Add the BOM structure.
$ e* K2 M) _% f' y( yvar bomItem = this.newItem("Part BOM","get"); - @. p" c: n' w( k6 e
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 3 G5 q& z/ a9 i
qryItem.addRelationship(bomItem);
& d6 H0 A4 j7 Z/ K7 ^ / `4 W, k, r# E7 G. N
// Perform the query.
# r/ p5 e9 G" L" \var results = qryItem.apply();
$ \' @0 |8 u w6 c) d - W; u5 C) _9 }. s1 r9 X
// Test for an error.
. e$ z. Y& w1 D- x$ W. Uif (results.isError()) {
[* V" v5 e- K9 r4 ] top.aras.AlertError("Item not found: " + results.getErrorDetail()); 0 X& R7 g4 m- Z4 _$ a. l
return;
4 _2 u, z0 k) w$ \6 Y; n: {1 }} % L# n/ h# M7 e8 Z8 b/ |
$ p' c% } W% N9 @" P$ l7 T// Get a handle to the BOM Items.
' e& B: K' t3 N$ a' W4 F* r7 H. Jvar bomItems = results.getRelationships(); , _7 z3 f1 |6 P- }4 i
var count = bomItems.getItemCount(); % ?9 f- s$ o+ X9 }+ P
3 v' x! t' n( T$ r
// Create the results content.
0 k d; ^& L* \. u( m! h5 A4 E) X; E3 v$ z3 dvar content = "<table border='1'>" +
$ d2 [. r( {7 J% J3 d2 S4 b+ i "<tr>" + 5 G, x* X" J- u: n
"<td>Part Number</td>" +
1 O! P, L6 }/ W9 |5 c; z% U "<td>Description</td>" +
3 a% d2 i6 j0 p6 R "<td>Cost</td>" +
. L9 G7 G1 C: C "<td>Quantity</td>" +
* v/ m% m4 S0 ?! e! \ "</tr>"; / e! u( A/ z6 H, H% ~' X! a" b
* y a5 i w, c: O N. U: O6 _// Iterate over the BOM Items.
( M8 y7 |* `+ o4 d; Ffor (var i=0; i<count; ++i)
' Y: R9 \8 C- A6 z/ C6 k4 K: H' l8 S{ + f" f" k! X" t! R: m# a
// Get a handle to the relationship Item by index. 7 ?6 S1 n* i U. k* U: `& [# }1 j" _
var bom = bomItems.getItemByIndex(i);
5 y- f% X m- t8 k// Get a handle to the related Item for this relationship Item. : U h i. O; M3 A3 @* k3 _" D: y
var bomPart = bom.getRelatedItem(); " a7 o9 Y D2 |4 X0 E" F8 e
0 Z& \5 c* x. R1 z content += "<tr>" + 4 q+ l6 }/ m* x2 G- s% f# R& I
"<td>" + bomPart.getProperty("item_number") + "</td>" +
& F8 a$ N4 _4 d3 v* [/ c" F) d "<td>" + bomPart.getProperty("description") + "</td>" +
* r1 I* m- y6 d- E "<td>" + bomPart.getProperty("cost") + "</td>" +
/ B- z9 x; Q r4 v8 W0 f9 d3 d "<td>" + bom.getProperty("quantity") + "</td>" +
' U5 E p* [7 ^% m2 Q$ i "</tr>"; ) t) F4 \- ~& n* f% l3 l
}
# c$ \" [2 @+ P& c* preturn content + "</table>";
8 m9 h4 C" B- @& |- q" i$ n
: h. h7 ^* W2 r4 }) I6 r- w9 _3 c
" s$ q1 z4 y% a) P: \ W6 k* g/ b, U6 I
; r( H: {" p% ], d
C#
3 M5 Q& U+ M; q# @7 \) U+ kInnovator innovator = this.newInnovator();
$ ?3 \5 a! ~1 }0 Z) Q3 P- _& U
% d" t% P2 X) }6 m// Set up the query Item.
( V" I& K: [' K& f& x+ f$ u( xItem qryItem = this.newItem("Part","get"); ( d; T# w3 {; `
qryItem.setAttribute("select","item_number,description,cost");
% Z9 S; ?- M0 Q6 g4 l' JqryItem.setID(myId); 9 [7 @7 C1 s3 n) [/ R. |) @1 V/ a3 O
) b% T6 F. L( \2 x, y// Add the BOM structure. * }0 G( H D0 e3 _
Item bomItem = this.newItem("Part BOM","get"); A% ?5 J+ E2 Q9 C
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
3 |& X8 r& u3 B8 |qryItem.addRelationship(bomItem);
5 L& e# c8 q2 ^7 S2 t2 g5 V & ~$ Y6 O3 |2 o' a1 M
// Perform the query. / s( f% n w, \5 n: k3 k/ C2 n
Item results = qryItem.apply(); / p, t2 ?: I5 h5 g0 E, ~$ r9 O( n9 Q1 c/ [
9 Y9 x% M8 t: | i3 [( E4 w+ _: O// Test for an error.
+ K' x* d8 c8 u7 E- E3 tif (results.isError()) {
! {; i1 k/ P" u5 L/ h [ return innovator.newError("Item not found: " + results.getErrorDetail());
* j! r4 _ y: m. Z5 D! f$ w} ! q, o9 |0 n$ q# | P+ b' k
$ ]& \( V/ w- C4 d R9 w7 k// Get a handle to the BOM Items.
3 x8 r$ R8 k8 {: V; l+ G, J Q9 UItem bomItems = results.getRelationships();
! l* h2 R3 ?+ F, [, T aint count = bomItems.getItemCount();
o- B4 H( G7 Wint i; * i/ m) ^- C7 T+ A$ R( `/ f& k
( P7 j+ _( C; o) ]- J( h- ~// Create the results content. 3 `& V% y) z* ~( H/ Z( Y0 K
string content = "<table border='1'>" +
* t/ ~9 p9 `+ ` "<tr>" + 8 ~* x6 ?* C. [% [* X: J
"<td>Part Number</td>" + # V0 t. _8 H; |# j& t8 V& x
"<td>Description</td>" + . Y0 x( m$ w4 S; Q& g
"<td>Cost</td>" +
x T4 V6 j4 P6 H "<td>Quantity</td>" +
9 a _4 C% Z5 B( G1 i$ R "</tr>"; 3 m7 j. s" g3 m+ e. H3 n/ ~! E9 V
1 O% ?- @* L: Z- g1 i# _
// Iterate over the BOM Items. ! D* B$ m& B2 C9 K' y7 H
for (i=0; i<count; ++i) % A) F) x% P- W* i% t. |* L. h
{
# h0 s7 q# {( x; I5 v& k// Get a handle to the relationship Item by index. ( a4 D5 d4 m# N2 |% E
Item bom = bomItems.getItemByIndex(i);
* Q9 b. K4 a6 N' t3 r$ R// Get a handle to the related Item for this relationship Item.
+ v* ?: _ a# e Item bomPart = bom.getRelatedItem();
1 P/ I3 E+ z3 f1 s
2 b6 W* {8 s/ O1 o' T3 { content += "" + 5 o, X& a0 ?# L9 n
"<tr>" + # E9 T2 W$ _9 ^" `: ]
"<td>" + bomPart.getProperty("item_number") + "</td>" +
' a' @( K* ~" U. I8 N "<td>" + bomPart.getProperty("description") + "</td>" + 4 \, h1 n) ~( O4 o
"<td>" + bomPart.getProperty("cost") + "</td>" +
, h! _4 \" _# ~0 ^( R! D/ e( u "<td>" + bom.getProperty("quantity") + "</td>" + / a3 {: f3 c; N
"</tr>"; 7 F" W( N* v" D
}
1 ?2 X6 J& Y9 }; fcontent += "</table>"; : H* s' `" f$ B7 Z+ K. l9 S
- }1 ^! I' W2 l" l& [, z! m
return innovator.newResult(content);
5 o! f1 X* u- C$ o, T
, u* Y5 J" N4 Q
8 G, y. o3 s3 M9 T9 l' k& a/ J/ r, m) l
3 t9 B6 g+ t( O$ S7 i9 V
, h' c' j: M, n! W
4 z% W O/ ]7 `9 R! i- M. \
" ^, [! R6 `5 \3 e8 ?0 D; A3 d # n, r9 U9 _# p! b2 J
Page 46
0 `8 C1 ^/ y% Z. c9 y ) Y' T# S: j9 U
Copyright 2007 / n7 T. P B( J- v1 ~- ?
Aras Corporation.
" g: P9 y) l8 R$ O! AAll Rights Reserved. 7 Z5 y" N5 y8 u+ f' Q
VB.Net
: I1 F/ F& J U1 sDim innovator As Innovator = Me.newInnovator()
( \/ @; L8 i7 x" |0 F" R* F
9 |$ N; A+ ~9 R2 s' _1 q' | l' Set up the query Item. 0 l5 ]: S/ Q7 N: F3 l. s+ ]
Dim qryItem As Item = Me.newItem("Part","get") 5 k5 c; b3 p. ~+ u H8 ?0 X
qryItem.setAttribute("select","item_number,description,cost") / [/ O3 y( ?; f5 b* Y/ T
qryItem.setID(myId)
) ]% D8 d! m$ K7 T9 G) ]/ O$ e
2 p- R. f n) U- b. b& x) j' Add the BOM structure.
1 w& X% P+ a! g% M, k5 S. t* A: ZDim bomItem As Item = Me.newItem("Part BOM","get")
+ b1 ?( G1 m( a9 z9 H! S. L* kbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") % N, }: S9 S. c2 Z$ ^3 A( }5 }4 O( ]
qryItem.addRelationship(bomItem)
6 l9 H* e" c; s+ Z: x$ Z2 _4 Y# m
" |% e* P# q! M6 x t) G3 d' Perform the query.
( i) Z; @" l- d8 DDim results As Item = qryItem.apply() - H9 Q; V8 N R$ c& D' @5 F
+ {8 U' x4 k0 @' Test for an error.
; N3 {; S! S$ w, }If results.isError() Then $ `- I; Q2 v' S; q
Return innovator.newError(results.getErrorDetail()) 8 S ]$ n! [* M' ` H+ I
End If ) k/ ^; w6 V9 @( i& z9 {
5 Y- f+ T: `+ h1 j$ G$ f" h: d
' Get a handle to the BOM Items. 7 T5 y( J8 d$ I0 F7 ~7 S
Dim bomItems As Item = results.getRelationships() ' m5 p$ Y: |, k4 p1 W3 i' r" j s
Dim count As Integer = bomItems.getItemCount() 4 j- ?8 j% p: s, U
Dim i As Integer
+ [" a7 N# M" e5 X* B3 h% F- i
; a7 }, f) U9 e# ]" Z" S; D' Create the results content. 7 q/ w: i% k1 {4 W- m4 s: M
Dim content As String = "<table border='1'>" + _
% x g7 v! ?+ B "<tr>" + _
. k% S9 }" [( ] E. J8 ~# J "<td>Part Number</td>" + _
9 T" j; o, K/ x7 q/ z "<td>Description</td>" + _ , ?1 f$ x- m* L9 i+ `
"<td>Cost</td>" + _ * U6 @0 @2 P) s0 r! a( L0 u2 e
"<td>Quantity</td>" + _ 8 f3 ?) S ~) z, \; [' T4 O
"</tr>" * _/ [& |# ]+ i; V8 w
5 j) L" V/ Y- K' Iterate over the BOM Items . G' h; B& g \ j% y- n0 s
For i = 0 To count - 1 . W9 Z9 J. { E7 X6 M. K
' Get a handle to the relationship Item by index.
5 j% W3 P4 p$ [- Z$ T9 H% V# E, } D Dim bom As Item = bomItems.getItemByIndex(i) 7 b" O" Y$ {% L& n
! t. T; L5 p/ z( } n+ ^
' Get a handle to the related Item for this relationship Item. ) r0 g" J2 J% \0 v: s `
Dim bomPart As Item = bom.getRelatedItem()
- u" _9 H3 Z. g) l: U + d( R, z' E6 t5 W9 T9 Q
content += _
+ `+ J7 P' Y/ I+ A "<tr>" + _ 3 g" ~3 m) @ k& Q9 _ D
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 0 R7 a- ]2 p2 d7 m0 x% h
"<td>" + bomPart.getProperty("description") + "</td>" + _
. F Z7 d p+ }0 i "<td>" + bomPart.getProperty("cost") + "</td>" + _ & m3 ]" H# m( Y' F% d
"<td>" + bom.getProperty("quantity") + "</td>" + _
; ~0 z9 F; y+ n; I "</tr>"
% f# I/ W5 Q. j9 h4 SNext ( l/ N, T3 z2 C
content += "</table>"
# _6 g \3 i8 b& N/ r* E
) _/ _. y0 u/ y! _. {1 \0 R( e# qReturn innovator.newResult(content) 7 D% Q& A) K. O
( X5 z# ^* {; c2 z |
|