|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
0 v4 j; S4 f; N WTo query for an Item and retrieve its structure you build the query as the structure
" X6 }6 }# T% |. K7 [- d3 v$ c2 I! dyou want returned. Use the IOM methods to add the relationships you want and
: Y- N+ F4 q/ g( ]2 H. e2 sbuild the structure in the Item. The server will return the structure that follows the
4 L* g* _8 z+ j" b y( C, {request structure. ( I% v! t4 a( V3 P# G9 v: C) L
This recipe illustrates several related concepts together, which are how to get a set N3 g' M" \1 K+ x: s& U `
of Items from an Item and how to iterate over the set, plus how to get the related
/ [3 M/ v; A$ I s& o# @, TItem from the relationship Item.
" b7 l4 F7 s# c6 d7 J9 p5 UJavaScript 6 a8 y; y3 M* N8 e- N" n# s
var innovator = this.newInnovator();
9 G8 o; n+ H: y , ]6 Z9 I$ |" o0 c
// Set up the query Item. 2 N, h# G4 N& ^7 t" {( h+ a) M8 i
var qryItem = this.newItem("Part","get"); ' x3 d4 ~! E4 m$ p' j5 r
qryItem.setAttribute("select","item_number,description,cost"); ! {( l) x( X" W; { E
qryItem.setID(myId);
; B/ ]* J0 z4 U1 l4 f& ~# Y
; `! m. E' K0 ^' O6 H- J// Add the BOM structure. 8 {/ e/ p, L8 P! o# ]8 D
var bomItem = this.newItem("Part BOM","get");
2 u3 n7 [: h8 M0 a: O7 b* PbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); . \- v! }4 d# d. Q3 \( U
qryItem.addRelationship(bomItem);
/ T7 ~7 S3 n( O: H8 _
9 Y$ D) `, |5 A( N// Perform the query.
4 j$ W$ k! s7 {3 r" s0 kvar results = qryItem.apply(); 5 `5 S; t/ @0 M' v
2 _% k; M; a. `; v0 i
// Test for an error. 0 e) H( ]3 u* e0 P) U$ X
if (results.isError()) { 3 U# |( H8 ~9 G4 o
top.aras.AlertError("Item not found: " + results.getErrorDetail());
, p8 Q3 P! W; J4 ]% }9 J return; C3 G' L d/ \4 H
}
: l. w/ `7 ]* a! U# C! G1 W( I
. d$ @: a" \8 h. _; B% X Y- ^// Get a handle to the BOM Items. 0 F+ J( T3 w) Q$ X
var bomItems = results.getRelationships(); 7 ^" r/ |+ Z, {4 P/ {
var count = bomItems.getItemCount(); ; x1 k: B3 W! m" G: p
6 [9 f9 b% B& `, G& j& k5 [// Create the results content. . O0 n* j2 z" G% n6 \5 N
var content = "<table border='1'>" +
% F1 Y; w! }: C; n8 h6 f "<tr>" + . Y- y c( {6 m5 C2 l/ V: P
"<td>Part Number</td>" +
8 `2 Z% i, S; z "<td>Description</td>" + ' }) y+ F$ J" D4 q) a- ?$ c
"<td>Cost</td>" +
% z. B+ f+ j: [0 F% |4 a% P$ u E# @ "<td>Quantity</td>" + % H1 Q, t. x# K& {+ Y1 M
"</tr>"; 5 Y3 M% R) t6 W8 y- |
% X& K, p% b; Z: L3 ~// Iterate over the BOM Items. : g6 D9 h/ o8 C& k9 x5 b Y
for (var i=0; i<count; ++i) 6 b$ P v1 T0 N( H- V2 h/ I
{
. ]# \: l+ c0 l9 e+ m// Get a handle to the relationship Item by index.
8 g# S7 _! n" [9 { var bom = bomItems.getItemByIndex(i); , j! v4 c2 _9 l4 t6 P) q& I
// Get a handle to the related Item for this relationship Item. 7 {, I8 c4 [6 n9 m J# M! o; U7 Y4 z1 I
var bomPart = bom.getRelatedItem(); $ {" y# [. m" x
; R; t* G e2 ^; c/ ^3 x content += "<tr>" + 0 [. g) G$ Z" N. e
"<td>" + bomPart.getProperty("item_number") + "</td>" +
5 y- V9 C1 Z3 I "<td>" + bomPart.getProperty("description") + "</td>" + 9 u- s1 e% q4 B' T: V
"<td>" + bomPart.getProperty("cost") + "</td>" +
- _3 [# M. f' [9 v "<td>" + bom.getProperty("quantity") + "</td>" +
0 x2 r0 z$ ~; b' ~& }6 j "</tr>"; + ~ E, l9 U8 v( _$ u9 ~
} ( X0 p [# M5 |- @
return content + "</table>";0 r* J$ l. ]% F
1 `7 N4 _4 g0 h7 F* ]; e
" { K! F1 X+ o" s, L$ l
3 ]6 O S9 y3 L& V# {, ?& f) _5 r0 r" K( ?
C# 5 i8 Z7 G! `# g- d7 I1 i8 r
Innovator innovator = this.newInnovator(); # b4 r9 i$ ~4 F9 X( N% D' H _
1 e# h/ [& S0 B
// Set up the query Item. : X" U) X( K- h }8 `; y. C0 y/ t4 w
Item qryItem = this.newItem("Part","get");
8 e; j$ t& _" u: \# o0 M( I- NqryItem.setAttribute("select","item_number,description,cost"); : l* ^3 ?# B5 g# u/ a- Y' T
qryItem.setID(myId); ; `& h; U- N$ b' ~( R6 C
/ D& c6 v, [9 X" t2 a( b
// Add the BOM structure.
: q/ g/ _$ ~! T: z& {9 x3 D$ cItem bomItem = this.newItem("Part BOM","get"); % H- R" V X# t
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 4 R6 }& c* a* W& O( W
qryItem.addRelationship(bomItem); # t; |, N1 j7 {3 j
5 Q3 C- _/ E; s8 u, g! G1 x
// Perform the query. 2 z5 f- d8 `, B. I# g' l) l- d
Item results = qryItem.apply(); 2 H: q/ a) m* U# y% ?
" g( \1 M& T, Z0 S$ @5 `// Test for an error.
4 w' g7 r2 p: n* e7 B3 X8 {if (results.isError()) {
; p* X1 D" g) G ?2 y: u return innovator.newError("Item not found: " + results.getErrorDetail());
+ S5 f$ ]2 ]* Z( y1 M& X$ r}
( n& Y5 N" S2 x
% G9 x8 L: b) @ |8 a) u// Get a handle to the BOM Items.
; l, m5 M. h. R1 RItem bomItems = results.getRelationships();
- V/ o. E) M* |) Y1 hint count = bomItems.getItemCount();
( V8 A/ Z7 P; s: v l2 B, N/ Vint i;
$ ^- a* V- S8 _+ i
1 s' M( g) `( d! W// Create the results content.
, i3 w: b' E1 l( B, fstring content = "<table border='1'>" +
' I- d3 w+ H R& C8 z% o$ ` "<tr>" + ) f- p$ @& q6 R) @) g9 T/ }
"<td>Part Number</td>" + ; A+ Y5 }+ B+ ]- |+ l2 D
"<td>Description</td>" + " m3 j& w' a8 E7 F; y3 T
"<td>Cost</td>" +
4 T9 \6 H$ x, n, P9 Y, ^* R "<td>Quantity</td>" +
$ a$ s* j; A6 E! O; R8 L "</tr>"; 5 } |( b# U) T+ Y x* X; ?
% v4 L9 v- i) t3 k
// Iterate over the BOM Items. `$ h! T0 J/ F/ a$ P5 R
for (i=0; i<count; ++i) % @) P+ O7 q/ ~" A, `
{ # m8 A& m0 ]2 A V( ~
// Get a handle to the relationship Item by index.
N% R& V$ {& _6 n! v; B" T$ g6 e Item bom = bomItems.getItemByIndex(i); 4 q. C1 { [) N P1 W
// Get a handle to the related Item for this relationship Item.
4 _/ J* r: D" c6 d8 k Item bomPart = bom.getRelatedItem();
5 S4 m1 l" N1 G& e9 u5 a : E! x4 m5 ~/ V: l" \- U
content += "" + 2 E/ y! D& y$ }5 h6 e0 ^
"<tr>" + ( o$ k$ v4 Y% N: z. G0 O
"<td>" + bomPart.getProperty("item_number") + "</td>" + # y1 M6 V3 _1 t6 Y
"<td>" + bomPart.getProperty("description") + "</td>" + u' }3 u r: j4 t
"<td>" + bomPart.getProperty("cost") + "</td>" +
3 d. I! f1 N, d9 ^* l2 S; ` "<td>" + bom.getProperty("quantity") + "</td>" +
( t8 d f4 W- P: G+ j- P+ j2 I, m5 e "</tr>"; ( h; O" [ @% ^; l8 Y& b
}
/ b- A+ O2 j2 u) _' gcontent += "</table>";
0 T1 i ?6 h3 |4 W c- | ! ^9 D( Z1 S1 T7 h# m
return innovator.newResult(content);
* P3 J# t \3 }/ b1 l! O @; F H5 B* C% x+ k) B% A0 V+ F
3 X3 g6 V5 z2 o6 c5 _, b: N
6 h. v/ S2 r1 R; z& p
+ r( c. z4 f2 m0 H- ]: c- v N$ c' s6 ^- W
3 a: X7 t" V( l
* \9 S) \* `' H Page 46
' H$ L+ p9 H% j: v( k8 r6 h - I4 A5 K8 t- Y1 {( s
Copyright 2007 + ?5 b" s5 h: `# v
Aras Corporation. , d; G% V! m, _5 |* W$ A( ?- ~
All Rights Reserved. ( c2 o' p8 F% D! ^& g T6 b. U
VB.Net " W6 t8 Y* Q$ I6 H( q3 K$ y2 o6 G* h- v
Dim innovator As Innovator = Me.newInnovator()
% L1 E8 ]8 |2 L: y4 T, \8 t 5 C/ ^+ \5 L0 V2 I- Q& Q
' Set up the query Item. * h& j. `& l1 r( G: o
Dim qryItem As Item = Me.newItem("Part","get")
0 m+ W& o. `8 N6 {3 \qryItem.setAttribute("select","item_number,description,cost")
# D @; V! q3 MqryItem.setID(myId) * O- o1 H. d2 f3 w3 \$ i
# @ |3 V8 Q1 c' J) V' Add the BOM structure. 7 `+ v/ a# D! O: J$ n
Dim bomItem As Item = Me.newItem("Part BOM","get")
9 }, c- t8 O, x. u t1 `bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! O0 q. }, b5 {' M$ qqryItem.addRelationship(bomItem)
$ }* D3 E+ B) v, z, M2 ^% X 1 V' V7 Y S5 O3 e/ E& T! T
' Perform the query. % z0 | o" B, Q+ H/ J; S
Dim results As Item = qryItem.apply() ( S' ^9 i; O* N4 [' j
+ [) P1 k2 C# | x r2 x' Test for an error.
% Y/ |" J2 U7 x8 @, E$ ]# Q6 z4 U% yIf results.isError() Then 6 Q% B+ @: {, H% D
Return innovator.newError(results.getErrorDetail()) ! d% T" Y) E4 @1 H7 S7 G" [
End If $ |- y# y3 z5 ^! b6 V
: t) D! K6 t- ^/ o$ f' Get a handle to the BOM Items. 3 h4 U W4 q' q0 F) C
Dim bomItems As Item = results.getRelationships()
% ~- F% I0 e& E5 WDim count As Integer = bomItems.getItemCount() 1 h+ |! P7 L- f: o* K: V
Dim i As Integer
# D7 X; C$ f: A) t0 G' Q: L1 g0 R
* }( P T) i7 E% F4 {5 u: }' Create the results content.
) }/ p# q: Z! T" K0 rDim content As String = "<table border='1'>" + _ 8 r4 T/ O( z4 Z
"<tr>" + _ + `2 Y0 k+ n& _ R$ J
"<td>Part Number</td>" + _
9 p/ ^& O4 i+ R! b0 [+ ^: ?* ] "<td>Description</td>" + _
4 w* b# U5 e7 d& K "<td>Cost</td>" + _
, E" {6 h u+ t/ ~3 \. \; M "<td>Quantity</td>" + _
7 b, R4 ?+ ]& h* D; K( @( I5 K "</tr>" 9 l. Q8 y+ A) [: m+ n k
* n* m9 f4 o8 ^0 i6 X: i5 U' Iterate over the BOM Items 2 x* Y2 i' k) [
For i = 0 To count - 1
- A, h1 k' N8 C8 Z3 w$ P' Get a handle to the relationship Item by index.
8 \1 f) f$ U, d/ _. T Dim bom As Item = bomItems.getItemByIndex(i) 3 s2 v6 j S0 z- r( [
! [9 t3 E5 Y8 ]4 n/ Q6 r
' Get a handle to the related Item for this relationship Item. 2 s' k+ f. b( \ v) c
Dim bomPart As Item = bom.getRelatedItem()
' M: V7 C( Y* P/ Z# L ' T2 R8 K$ c8 g+ |! I
content += _ 0 o9 e: W" c- y, _3 n( X
"<tr>" + _
. Z) {& i& y0 i9 s) G+ ~4 V "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ( y, L$ e6 k% w+ q4 l* j
"<td>" + bomPart.getProperty("description") + "</td>" + _ * k& l. F4 r2 J- l- _5 A6 ]
"<td>" + bomPart.getProperty("cost") + "</td>" + _
8 }/ y& x8 s) Z9 t! v( f7 v7 } "<td>" + bom.getProperty("quantity") + "</td>" + _
8 p5 y: k# W. {7 ~! a" v) W8 X8 }- B "</tr>" ; W8 N; [" V5 ^( a# k
Next d" M8 R, |1 ^! t
content += "</table>"
2 m2 i, w$ V# g9 i
; Q5 r! [4 A( l I0 Q' t6 s# u9 Q) FReturn innovator.newResult(content) * R/ ^- h; l; f w" h
& _( D% z O: p: G9 j2 w
|
|