|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
( L, s0 p+ b- O7 N) n; XTo query for an Item and retrieve its structure you build the query as the structure
7 C# z% k$ y/ H6 I3 M$ syou want returned. Use the IOM methods to add the relationships you want and
4 v) @9 x- ~; n+ rbuild the structure in the Item. The server will return the structure that follows the
% O. R8 E1 L/ u Nrequest structure. 0 l$ o( _/ f, F/ Y9 ]1 J$ v1 d
This recipe illustrates several related concepts together, which are how to get a set
3 J$ L" k3 K3 n+ E0 kof Items from an Item and how to iterate over the set, plus how to get the related ( e7 n3 h/ V4 s. z* i. P& D
Item from the relationship Item.
. i5 o; e" }0 E$ m. R" l4 bJavaScript 2 C( l) {- _7 Y& w! l" I% X7 Y
var innovator = this.newInnovator();
% w. ]% I# r0 g# [3 H1 U) {
* Z9 I% t- ?* O) P// Set up the query Item.
0 v1 t: C) p9 y! j1 K* h. Evar qryItem = this.newItem("Part","get");
* x! ~) q) P# G- T+ b( XqryItem.setAttribute("select","item_number,description,cost"); ! W9 u# X5 f8 l4 D3 b ~! j9 }
qryItem.setID(myId); , y/ r( }) N3 u' b- J' I
8 ?! \/ }$ K) P5 ?/ L% |9 K# W// Add the BOM structure. % M; o6 Y6 I$ |. r8 c/ Q7 w& z4 H
var bomItem = this.newItem("Part BOM","get"); & { t( }/ M) q
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
. s( w; X: a+ i6 s) EqryItem.addRelationship(bomItem);
/ L0 ~0 a5 k. N# p2 k + p6 \& v/ `# L* @. B( {! q0 v2 z
// Perform the query. 5 V. Z# \3 k: _
var results = qryItem.apply();
( o* o7 H( |4 `& j5 k. D+ G) H - q9 Y" ?, U2 o
// Test for an error.
* K& ? F* p8 J$ Z4 s/ b# aif (results.isError()) { # p0 a% g. q/ ]- I7 j
top.aras.AlertError("Item not found: " + results.getErrorDetail()); 7 {# e) r3 V4 \$ }% m; H4 J0 P" V
return;
! d/ b" P& v( M- S) A; E}
9 u2 M6 a5 g! o/ k' C ) X9 l+ W4 E" g! Q9 d, e0 X7 W
// Get a handle to the BOM Items.
. J" @( _# l. b. ?var bomItems = results.getRelationships();
1 A- B* E/ Z' ]" ~& gvar count = bomItems.getItemCount();
) f" P o& a" [9 m
[6 S3 [5 Y2 N; T// Create the results content.
/ O6 l) g6 w8 i% p+ uvar content = "<table border='1'>" +
; x: H2 \5 W$ Z/ P& b- h# t( j% c) w "<tr>" +
- w; e! L. G0 G3 S "<td>Part Number</td>" + ( c Y' h: u9 w C3 y' B" m
"<td>Description</td>" + 7 L; w+ h0 D/ t8 f1 q* b
"<td>Cost</td>" +
6 g+ Q: q+ {9 `- k "<td>Quantity</td>" +
7 ]% Z0 U2 L& S "</tr>";
. P/ r1 E3 o/ K) T/ v0 m 9 ~, q Y: K% T$ W
// Iterate over the BOM Items.
$ C, w: t3 p" e- D5 ufor (var i=0; i<count; ++i) 0 Z! ?3 P( v7 [8 j9 S5 `3 {" s
{ 0 _* F: I$ i+ d
// Get a handle to the relationship Item by index.
0 ?) I: \: `/ M- ]/ K/ k) A var bom = bomItems.getItemByIndex(i); 8 ]% T2 j7 x3 U3 W
// Get a handle to the related Item for this relationship Item. ! D6 Z& @/ g) G% @( {
var bomPart = bom.getRelatedItem();
- F2 }% N4 m9 l; k3 q7 t" p( D
# }2 w* v/ X% a- d9 X content += "<tr>" + 8 g2 T. M+ {% C
"<td>" + bomPart.getProperty("item_number") + "</td>" +
( ^2 _8 R+ L! U" ?! T/ k2 ]% a "<td>" + bomPart.getProperty("description") + "</td>" +
9 ^& u0 x6 W1 m) a0 L "<td>" + bomPart.getProperty("cost") + "</td>" +
: Z u$ `* {' L3 k' N: L "<td>" + bom.getProperty("quantity") + "</td>" +
4 N2 }5 H3 E% r {" q( F8 N" y "</tr>";
+ o, M V3 \' P7 b. ~2 J}
" B0 s4 b7 ^# n# G/ s$ Ereturn content + "</table>";3 P* h ~* g8 h9 \( \! ?
' f; J$ z0 a p. z& _( g$ B7 s
7 W8 K, H- Q" I# s- @4 b6 u4 p
. k! o) n% H7 q/ f9 ]% G1 i
: [7 A8 c v6 R" z6 Z& i
C# / J7 c/ W# z5 P e' c8 K% M; C
Innovator innovator = this.newInnovator();
# x: t4 R& J7 S; G( x1 t. p3 x9 x
0 g; m1 h9 M5 K. b3 E// Set up the query Item.
" X8 b9 q2 ]. XItem qryItem = this.newItem("Part","get");
9 C6 ]( Z% a* J8 D. wqryItem.setAttribute("select","item_number,description,cost");
; F' r6 w i1 u1 jqryItem.setID(myId);
) F: a" s- _8 e* }8 j0 } # W$ s i* c2 _) I
// Add the BOM structure.
) `1 b0 Z9 W6 j' RItem bomItem = this.newItem("Part BOM","get"); # \& Y8 ~& s: o0 Z- O+ j0 M
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
$ \2 z& g! P( f/ \( I+ uqryItem.addRelationship(bomItem); . p- w! T# }1 I( u
6 o: E- Y7 q7 r' Y( T// Perform the query.
7 ]" K7 b. M$ t# HItem results = qryItem.apply(); 2 y1 k- W1 X' W& E! e# {; u" u( i
1 ]) k4 L9 A/ u0 V" s// Test for an error. # u* l0 D( ~2 R9 t" E" r$ M( M
if (results.isError()) {
0 I& O. @, x/ [3 [7 C2 n6 } return innovator.newError("Item not found: " + results.getErrorDetail());
: |, C& q: z; p}
& o1 _1 g v- R! Q( k5 x
7 l S) C6 N* e& A// Get a handle to the BOM Items.
: n. V7 w8 e o! f2 @2 [( \Item bomItems = results.getRelationships();
" ~$ w* g. s- w- z. Aint count = bomItems.getItemCount(); 2 a9 r7 X! F+ o" O0 z
int i;
. s. f9 e, N. j3 z9 }, P1 t; x
Y& j* ?4 K- e// Create the results content.
* T" Q9 {3 X5 c$ ^+ r; }) Estring content = "<table border='1'>" + ( e# R P; ^" q% ?' t- A# T( t
"<tr>" + 7 }* Y" t) e$ k0 j2 M) C) L* p
"<td>Part Number</td>" +
3 s5 m) W# W( s G "<td>Description</td>" +
, ?3 N9 K& _% C* n: q) x! @ "<td>Cost</td>" +
7 K. I3 K& ?1 a$ b/ Q5 z2 T! ? "<td>Quantity</td>" +
8 R8 U+ [8 {: ~ ?6 p% _/ G "</tr>"; + V% R7 _- J9 B" t! h d4 H, I9 D
! B- D' O, }6 {% R5 S4 X8 [$ H// Iterate over the BOM Items.
3 K% t" w% j" }* D* |. ?for (i=0; i<count; ++i) 7 o2 t9 [+ W0 N% l
{
2 p) L W$ E# U, N// Get a handle to the relationship Item by index.
! U. V, B6 l$ F1 U. |) u Item bom = bomItems.getItemByIndex(i);
/ i* X* b q1 `% K+ c// Get a handle to the related Item for this relationship Item.
2 M4 o2 U* E) `- j0 P Item bomPart = bom.getRelatedItem(); - t" l: D% A1 x# x+ W
* Y: }1 j4 W: R, l) q8 r- b content += "" +
' J( W @' b! }. k9 }/ X "<tr>" +
2 Y6 R; s: S: y "<td>" + bomPart.getProperty("item_number") + "</td>" +
; [- w8 e9 c T. i$ J8 X* H "<td>" + bomPart.getProperty("description") + "</td>" +
( ]1 o. A- {5 t% W8 L" K "<td>" + bomPart.getProperty("cost") + "</td>" + , ^* R" [9 n) P0 i1 B0 l8 ^
"<td>" + bom.getProperty("quantity") + "</td>" + 2 v( V W1 \/ t- g
"</tr>"; q5 q0 b2 l- U. v: f( l7 {3 x
} % D: O' P7 m. k' @
content += "</table>"; 8 l, b9 U j6 @0 N7 ~
( z! k3 C$ g/ mreturn innovator.newResult(content); ; s. _. _) h, i4 A; W+ u
* |0 N! Z' B8 L* S/ I, y; q0 q. F" u, G
6 O+ T' E$ v3 l/ q! F0 k: t
: X; c2 P! U- M% e; {! X4 z% J/ Y' j
0 ?3 `7 y- z5 R2 |8 ^9 o3 T
7 r5 O) `! J" q Page 46
5 `) u& ?% W+ X, F# Q+ h2 t
! x4 }* f2 @* G3 c& @% fCopyright 2007 ; t6 w/ x/ {7 B* }7 O- c. U
Aras Corporation. 0 u7 V" l% c; z, A
All Rights Reserved.
, v2 k/ |, n3 O. Z8 o9 W6 Z# dVB.Net
" Q- o; N- [/ j, cDim innovator As Innovator = Me.newInnovator() ; d& h* M* Z5 x) z% u
' \) S0 `% q- `' y' Set up the query Item.
' n! R; y5 O* z; G" [# \/ i+ w+ WDim qryItem As Item = Me.newItem("Part","get") , ^+ v# ?. c$ A* A z( c4 T) Q
qryItem.setAttribute("select","item_number,description,cost") ) l+ o7 |+ c! u- t4 C+ l
qryItem.setID(myId) ' V$ `3 W7 w$ h6 }
: L) ]% o" {& _) s
' Add the BOM structure.
$ K, Z" b3 q- F$ x* gDim bomItem As Item = Me.newItem("Part BOM","get")
3 m, m: `; n" i, |3 |bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") % |& e" l6 q# @2 E. E
qryItem.addRelationship(bomItem) - z0 D' H1 p$ a( P, a7 ^+ S. Y
& H) l+ p4 t* H: E' ~( @2 F
' Perform the query.
/ c s2 C% Z. J$ Q: _5 IDim results As Item = qryItem.apply() " A' ~4 K. }& k( M/ Q+ o- l
" Z% {* [+ H$ n+ _& t7 z' Test for an error.
1 r+ V2 z/ S8 ^6 \# X1 D4 \If results.isError() Then
* j o+ F# R1 @$ T Return innovator.newError(results.getErrorDetail())
# t& k: m7 d: ?, `: uEnd If
( y3 w2 H; ~$ j9 I; }5 E : h5 F( ]5 P: N& h* u& x
' Get a handle to the BOM Items.
# W1 h! d9 b4 fDim bomItems As Item = results.getRelationships() 1 o' R3 c6 y0 i+ Q3 {
Dim count As Integer = bomItems.getItemCount()
1 Y- A: h; {/ Q% s- cDim i As Integer 1 b2 l) `: |6 W9 K$ k
4 p* u8 Q! i$ I1 }' Create the results content. 7 Z% o2 q* J/ O$ @# E" u+ O9 C
Dim content As String = "<table border='1'>" + _
- }1 j: L1 ^) ?7 P "<tr>" + _
. f+ r% p: |4 X5 b' C3 F "<td>Part Number</td>" + _ ( L G) _% C9 i
"<td>Description</td>" + _ * ]4 m! j* B, I/ q) c" ~2 c; d
"<td>Cost</td>" + _ . k6 J8 z0 T9 |, A5 Y$ A
"<td>Quantity</td>" + _
# e7 v7 h, N0 z4 W% Z4 v k. E2 F) ~ "</tr>"
. B4 K" [" l, `5 Y* \" X- q, ~ - S+ G! G/ ?! N0 `* G' S3 c7 l
' Iterate over the BOM Items
3 H1 M: F" q3 bFor i = 0 To count - 1
7 M/ p7 Y q2 O* P' E, E' Get a handle to the relationship Item by index.
7 r# Y% c6 E5 |6 Q' |) d1 O$ N4 {2 _ Dim bom As Item = bomItems.getItemByIndex(i)
4 }* H; D5 T, `# [1 c( u) @
# ?: P3 H9 V& }& ^/ j7 P' Get a handle to the related Item for this relationship Item.
3 a9 Q& C9 U- l: U Dim bomPart As Item = bom.getRelatedItem()
6 ~* o0 d$ f$ \7 |9 k+ H$ n ; T: K% L$ d2 s1 G0 {
content += _ . Q2 s4 e5 O( V0 J( G
"<tr>" + _
: P$ U! F' l% ~+ r" v1 ~8 G$ G. R "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ( p7 P0 k6 ?2 e T7 z
"<td>" + bomPart.getProperty("description") + "</td>" + _ @! D5 r4 D; A9 E. K
"<td>" + bomPart.getProperty("cost") + "</td>" + _ + j. {2 c! w' [8 a; |. u# ]
"<td>" + bom.getProperty("quantity") + "</td>" + _ 4 ~* l: p' n9 D3 N& t5 T6 ]
"</tr>"
! z1 ? }6 M0 ]- p5 M- x9 @' i( xNext 4 \/ d* F: [0 u g! a
content += "</table>" 0 O2 R, U9 w% k" G) ?
5 E' ^9 C+ v n, [$ a
Return innovator.newResult(content)
: {- g1 k# M& _9 z# L9 c
2 C7 t1 c3 [3 r ?' P |
|