|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
" p: w( e: [% m( ~' W0 y; DTo query for an Item and retrieve its structure you build the query as the structure
* c, M. r) t o2 c4 R3 c/ X% tyou want returned. Use the IOM methods to add the relationships you want and
0 [. H9 [/ H% y2 }# Obuild the structure in the Item. The server will return the structure that follows the 2 c1 q W% z7 `: G# _
request structure. - f6 m& |# b8 [' w
This recipe illustrates several related concepts together, which are how to get a set 4 |- g' @: j" Y8 V5 o- H. r
of Items from an Item and how to iterate over the set, plus how to get the related
/ r! j7 u* X* m8 I7 g4 d* mItem from the relationship Item.
$ [) i3 E5 z0 |9 RJavaScript
; L5 w1 p1 t+ w& Jvar innovator = this.newInnovator();
( L$ [4 y g( m/ v & y6 m/ s( E6 s4 l ?( b
// Set up the query Item.
% z) A7 ^5 }/ c0 E, Rvar qryItem = this.newItem("Part","get"); 9 t' f0 x$ C4 w& X8 l7 C- [/ R+ w) F
qryItem.setAttribute("select","item_number,description,cost");
; k: l* |- A; R+ YqryItem.setID(myId); 3 M+ x& _; s- X6 p3 n: ^
( M, n* k; s) W4 U; u% _// Add the BOM structure. 9 _( E! f1 U( v$ P7 V: O1 z# }6 z
var bomItem = this.newItem("Part BOM","get"); + @* V3 u. p# `& G
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ( b- f! y( i) A ]
qryItem.addRelationship(bomItem);
+ T5 }" i( Q" G 2 W) p5 m5 [3 V( A
// Perform the query. 4 B7 r; D1 v* ]
var results = qryItem.apply();
6 y) O* H6 |; @& c4 y8 {1 g3 q $ F+ b4 L+ P$ I
// Test for an error.
5 i7 Z+ N+ N, b- Y" F; K$ N. L% a% nif (results.isError()) { - S$ ~3 w$ v! F! P
top.aras.AlertError("Item not found: " + results.getErrorDetail()); / r4 r0 S1 s* c2 \) [- G
return;
! U7 V1 ?* l' Z/ t& U' j/ e7 j}
8 J: [$ r/ [$ y4 O: J, d" i7 A! o- j
- s+ ] [8 }1 F( Y1 W3 [4 S// Get a handle to the BOM Items. ! i7 K% ?# H9 l N
var bomItems = results.getRelationships();
3 v6 v# g+ i' D3 j4 cvar count = bomItems.getItemCount();
! s9 V6 k1 X% {3 J. _8 w: ` # Y* J2 v- R, J8 [
// Create the results content.
) U6 t8 `- F1 }+ O1 ^' Lvar content = "<table border='1'>" +
: ~& A8 g# T8 x. N5 g- B$ E "<tr>" +
; \# ` A) Z( |) p* x6 r6 @ "<td>Part Number</td>" + * r+ d* C7 k* Z
"<td>Description</td>" +
- i, d) \" s2 G" c5 e "<td>Cost</td>" + % s: {; y* z- F: b m) n
"<td>Quantity</td>" + ! G. r) ^8 c8 V) j+ \
"</tr>"; 5 }+ l% N6 O! B; R1 B
: A! h' j; N; ]3 f+ {// Iterate over the BOM Items. , U: L2 Q1 I& O A! W
for (var i=0; i<count; ++i)
0 Y/ W4 o; L# b$ H$ I/ {* ?{ # M' q4 p) V9 }4 J" C; Q7 _
// Get a handle to the relationship Item by index.
6 R" I% g2 P, G1 `; f8 q L7 y var bom = bomItems.getItemByIndex(i);
6 h Y" j& M0 H# g& o* s- I3 @$ p// Get a handle to the related Item for this relationship Item.
- @/ p4 a0 |2 |# x: n' @6 O var bomPart = bom.getRelatedItem(); ( _5 n6 y0 M; k, j3 @& n
/ |& \( y7 _! ?. a" f content += "<tr>" +
# B$ w+ D3 U; x9 L' D- B3 n "<td>" + bomPart.getProperty("item_number") + "</td>" + , }. f% L! T. e
"<td>" + bomPart.getProperty("description") + "</td>" + 6 t4 s/ N$ [5 W/ P9 d
"<td>" + bomPart.getProperty("cost") + "</td>" + $ u" u/ X5 J* p3 {, h, f
"<td>" + bom.getProperty("quantity") + "</td>" +
' M) F+ `" K- ^! v( s" a' N7 ]7 G3 G0 e "</tr>"; / S/ e' I. k2 _
}
, x+ |- n a! m( Dreturn content + "</table>";
5 Q T8 w9 a0 z7 [
6 V/ o+ L7 W9 j- k* A9 i
7 e* B( U8 p# o8 R5 L f3 D" @9 p( N ?- o/ g, z& B
5 N5 v% O. \$ [+ t: g. n2 B2 B6 w- ]C#
* ^/ G0 V3 ]3 u1 }Innovator innovator = this.newInnovator(); ) j2 S# x+ q, d: K" W: ]* l
! w' B( }; {7 l( _
// Set up the query Item. / s( v6 ~( M: x3 i) }4 G
Item qryItem = this.newItem("Part","get"); ' o8 x/ Q5 c" m& k% d9 d
qryItem.setAttribute("select","item_number,description,cost");
: q v7 C) d: ]& r2 X' K( KqryItem.setID(myId);
) o3 T# p& u) u6 S5 @- [ E% Q
# {1 S7 p7 ~5 @" d" P4 V// Add the BOM structure.
5 D- p: P! p% F WItem bomItem = this.newItem("Part BOM","get"); 1 x4 M5 Q7 o0 s. F
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 1 p- n, f8 q* w' y- o
qryItem.addRelationship(bomItem); * p+ z* b( }2 u1 Z$ e/ Q
, y: e$ r& K" g. g% p- D
// Perform the query. ( Z. _; m r: W6 `) V( z
Item results = qryItem.apply();
# q" W! `" v* h( g6 _6 L( W7 K. [
6 M$ A/ V; `' d! ]0 @8 g// Test for an error.
, Z" @" t9 r7 h8 i& M# hif (results.isError()) { - x# Z3 a: I9 H3 y% V
return innovator.newError("Item not found: " + results.getErrorDetail());
% M" q; t6 S8 ?9 y& F} 6 A2 Z- X* Z& i
% I7 u4 t" u7 @$ s7 y* N// Get a handle to the BOM Items. ( y, y8 T6 f. b8 t9 E9 H
Item bomItems = results.getRelationships();
# ?3 N/ p! E. H! Z* Rint count = bomItems.getItemCount(); Q9 S; d' N0 {7 T3 p0 j. k/ _
int i;
. M: H+ `7 d. W% L- ?# K* i( d
+ F, R+ ^7 ]5 B: x3 H9 v// Create the results content. ) I# r: N2 z, F* [) d+ D
string content = "<table border='1'>" + " f4 ~! A% }# u9 Z% b' h' [
"<tr>" +
8 s, g# {9 F7 U" L8 n+ q "<td>Part Number</td>" +
9 r& s( Y; K) \4 U "<td>Description</td>" + 8 H i5 o& Z" \, @' D/ Y/ L5 I2 j
"<td>Cost</td>" +
. m; h% U+ w& R "<td>Quantity</td>" + 0 C2 ]6 x$ u) O Z
"</tr>"; ( V( i; I: d! w" X# z% n
) [; A& w1 C% w, z& O9 G
// Iterate over the BOM Items.
U! i5 q2 i0 r1 Pfor (i=0; i<count; ++i) ( U$ j! B/ o6 K& Y9 h% E
{
- N, ?* a4 w4 x) R: @// Get a handle to the relationship Item by index.
* r( d9 f- p* l% e! m* m Item bom = bomItems.getItemByIndex(i); - s8 {" ?, W/ d5 U$ u4 u5 ~: T
// Get a handle to the related Item for this relationship Item.
) f$ g( P% Q6 s" E% j! h& _ Item bomPart = bom.getRelatedItem();
6 x, o: v: V$ k0 s* T/ _6 T
) F& c8 }) B+ {9 s0 N content += "" +
' }* U' b$ t" f3 v" e& n" @" e "<tr>" + 7 D; Z) g o' m+ x4 B+ ~
"<td>" + bomPart.getProperty("item_number") + "</td>" +
. J, p( j/ C' h$ @* ?5 W% o "<td>" + bomPart.getProperty("description") + "</td>" +
/ ?! q8 _$ \1 e "<td>" + bomPart.getProperty("cost") + "</td>" +
% L4 O& O" z3 g# x* O "<td>" + bom.getProperty("quantity") + "</td>" +
4 c; R% a7 Y9 j5 t; p0 R2 H* f "</tr>";
. U/ q1 u# b2 l; a3 K}
" H4 ~/ F( ?4 K* w' K9 d3 _# l0 Ocontent += "</table>"; : n9 B! p3 B) ?9 Z, v
% B" ?6 k2 S3 z% Greturn innovator.newResult(content);
# ~1 s" c B" v) i+ [# C @% r2 E& C* e/ i
7 _% E* I7 p% Y/ X' q
. _' I$ s, u" s
' }; D% W0 E$ V: h: k* |5 j& Y9 E: _ {( W! x: `3 p" ^. g
+ Z+ `6 d. c$ L! y
) `: S M: T$ S) ?) Z5 P" P
Page 46
* @$ _2 t5 H) k9 J
" V$ H% P0 V( H# l% V8 Q W1 pCopyright 2007 % ]. o9 Y% M/ ]" q
Aras Corporation.
" t" g; M3 Q A/ j7 VAll Rights Reserved. $ d( M( @; b+ f1 n2 {: a# b
VB.Net ( |6 ^0 G5 Z. d" D: z. o" M
Dim innovator As Innovator = Me.newInnovator()
$ _5 q3 y0 M" a# z- p
# d6 `& J- Z3 O' Set up the query Item.
1 W' z' N( Q7 h& S( y# i7 R- N" ]6 c4 HDim qryItem As Item = Me.newItem("Part","get")
5 l) \0 o8 o }* v5 BqryItem.setAttribute("select","item_number,description,cost") 3 u0 [8 L5 q. d5 f3 X+ s
qryItem.setID(myId) " \3 c' {. K k
3 a+ n" H( O# I8 W5 g6 q' |/ B
' Add the BOM structure.
( E% u! }7 y! `2 j( U/ UDim bomItem As Item = Me.newItem("Part BOM","get")
& s4 ^: j' |/ o, c7 l' ebomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ; {$ W7 u3 y+ X+ |2 f
qryItem.addRelationship(bomItem) : d% x; n4 ~% O4 k7 T1 ~+ e
, [# e. G4 y7 m1 y' j9 d3 C
' Perform the query.
: }- u; S% ^* kDim results As Item = qryItem.apply() 6 |5 V$ n* u0 c9 Q0 `! @& }
1 o; E& r1 w! l! @7 N# T# x5 z
' Test for an error. % F; t& R: ?- t5 e! O8 u; w+ p, v3 j
If results.isError() Then ' n' E! O2 o1 Q
Return innovator.newError(results.getErrorDetail()) 5 o# _4 e9 a$ ], |3 n" A
End If % d- P; Q( R$ p/ J4 r& T- y. z
/ \8 K! J/ X# } s& y8 W
' Get a handle to the BOM Items.
, J1 Q$ ?# k7 X1 mDim bomItems As Item = results.getRelationships()
+ f; S& H( d: I/ S$ CDim count As Integer = bomItems.getItemCount() - a' B$ V( ^8 ^! u9 [3 R
Dim i As Integer 4 F4 u' _+ A4 ~4 f
5 I' C e1 W3 k* ^! S! T8 ~
' Create the results content.
7 d2 B. \ b& ^6 S; o& ZDim content As String = "<table border='1'>" + _ 0 _* w8 ^# P& N6 b# a* _
"<tr>" + _
h6 R- @7 D4 ^- F "<td>Part Number</td>" + _ . u- Z5 f' c4 k" d- r
"<td>Description</td>" + _
" p2 H9 R) w. {' B0 c& ] "<td>Cost</td>" + _
$ K; {- [* G, t: S "<td>Quantity</td>" + _
J6 \ [1 B: l "</tr>"
0 _3 [* K S" a6 y+ o5 E1 C ' }7 N8 g( S2 H* @. F8 ]& q+ k
' Iterate over the BOM Items
* h& C, G8 ]( H6 A! {/ [For i = 0 To count - 1 " d# G% h. j* p2 J5 k: V
' Get a handle to the relationship Item by index. 2 }) g8 U2 `' [
Dim bom As Item = bomItems.getItemByIndex(i)
6 j0 e! b. ?* p+ t / `) o% w: k5 `7 C2 S$ Y C9 f
' Get a handle to the related Item for this relationship Item.
1 f M, E$ _0 O6 u* r) W3 T: M8 w: ~ Dim bomPart As Item = bom.getRelatedItem() ' @: a3 L+ H7 K* V( {) g! @
S7 W$ W. O. C4 e$ A0 g5 ~
content += _
+ i0 [& ~/ L. U "<tr>" + _ ; i9 O1 c5 _! R& ^
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ ! {+ B- z( @4 K1 ?+ P# V4 z
"<td>" + bomPart.getProperty("description") + "</td>" + _
" s. A. c; ~1 [$ b/ B! M "<td>" + bomPart.getProperty("cost") + "</td>" + _
[* L' M4 L# h5 M* Z' g "<td>" + bom.getProperty("quantity") + "</td>" + _
3 N* t" E8 p/ s; ? "</tr>" 1 x; {" @" n3 N" Q9 o. m4 A5 k
Next - F% b* f! ^* i3 `8 Y0 a/ T
content += "</table>" ( r5 N9 K z8 n: f- |; o+ p
7 m5 t2 t0 p6 Z3 j
Return innovator.newResult(content)
+ D* r6 S3 s$ C& y8 h/ c$ x1 R' R
& L& ?- w* o) ~ k8 f |
|