|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
Technique ; W2 v1 x3 `& t% d* _' ^" g
To query for an Item and retrieve its structure you build the query as the structure
) P# `% R, e, i0 qyou want returned. Use the IOM methods to add the relationships you want and 2 K( a4 o9 ^: E' O }
build the structure in the Item. The server will return the structure that follows the $ X$ j C( R, {
request structure.
7 H2 }, \" w$ l9 zThis recipe illustrates several related concepts together, which are how to get a set * ?% f3 r2 j( _0 X
of Items from an Item and how to iterate over the set, plus how to get the related
; U' C! b" B5 ~- c' l; dItem from the relationship Item. 0 O3 V9 I& ?. I. t. S
JavaScript
& w H+ e- ^6 E; Zvar innovator = this.newInnovator();
; `4 w. D) X7 [# T ~5 W , j8 a" y ^8 h. U% f0 z% \
// Set up the query Item. & R; ]( z# ^0 }; o# w$ ]
var qryItem = this.newItem("Part","get"); + I4 H4 b" _' \( N! U
qryItem.setAttribute("select","item_number,description,cost");
8 Y, f0 }! e$ P2 m! o& XqryItem.setID(myId);
2 Z, d- z7 S( T) y, c2 |0 O 7 t6 L& g7 j: o* `3 Z W
// Add the BOM structure. * v$ h% o, d: E! e
var bomItem = this.newItem("Part BOM","get"); . K5 l- t* g- u$ d/ o
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ; G, J# U, z3 ~, f9 f: ]
qryItem.addRelationship(bomItem); , k& p/ {1 q/ p; U+ `/ b
9 t! N+ S' s0 C& r) a
// Perform the query. 1 u4 D. \% b$ o* U; C
var results = qryItem.apply();
+ b- Z9 f/ D: f- Y5 { 0 f2 Z8 g% M" |8 A
// Test for an error.
/ v6 I; Y7 m6 aif (results.isError()) { , [: i' s! y( O) X/ Z
top.aras.AlertError("Item not found: " + results.getErrorDetail()); - r! w% U5 [$ j @* t! L& S2 @
return; + i# \! o! P+ f7 L0 T( Q
} ( @+ i. ?) f6 P" H: T; w4 U9 \: f
0 E' J2 Y8 B, s, g) e; d// Get a handle to the BOM Items. ; s& n( |' O ?6 m5 [
var bomItems = results.getRelationships();
# k: y/ I% _# ?2 O: l; fvar count = bomItems.getItemCount();
0 H( l4 C" r- k& V! D
: z, k2 u L' T* ^! H7 l6 \// Create the results content. ) z9 J! G* J5 m
var content = "<table border='1'>" + ' M* L3 i3 T# a6 r
"<tr>" +
3 Q2 I. i- R3 g( }" v1 F "<td>Part Number</td>" + 2 p; q+ @" w# s0 `
"<td>Description</td>" +
$ \6 `- ^7 l7 l' z "<td>Cost</td>" +
7 ~% Q5 W% `' \; H5 ]8 W6 z( h "<td>Quantity</td>" +
' `& I7 `* G/ R% \& u "</tr>"; # y) d- y( X2 `4 }+ C4 a
) G, T% R" k) `+ B. i$ E7 Y
// Iterate over the BOM Items. * I9 u% m" Q1 ~' e2 G! A# R
for (var i=0; i<count; ++i) 1 b) L/ a1 J! C3 f z
{
' z0 _( p& `. @& F" T8 G! A& h// Get a handle to the relationship Item by index.
4 Y3 X, U( \' j% ^ var bom = bomItems.getItemByIndex(i); . x5 J: k- E" a0 t
// Get a handle to the related Item for this relationship Item.
+ r- r' \+ O" w8 o( ` var bomPart = bom.getRelatedItem();
$ h: }2 E- I) }) ^ u+ D* @4 m# F* M 7 I3 W1 k! l1 I2 T$ |7 S
content += "<tr>" + 5 r, W' _5 w- S' v
"<td>" + bomPart.getProperty("item_number") + "</td>" +
5 ]1 j# X) I' U' n2 a, ? "<td>" + bomPart.getProperty("description") + "</td>" + : ~: ` F. f) ^4 t" c9 B; g
"<td>" + bomPart.getProperty("cost") + "</td>" +
" K3 H. G0 t5 J: S "<td>" + bom.getProperty("quantity") + "</td>" + . O, q" H, H( e7 |" E
"</tr>"; + y- T2 \& t( ?: w* c. i2 g8 h+ a. A! X
} * k& W9 U0 l# A! D
return content + "</table>";
7 K4 H( p5 I- v- O6 K+ W, T8 B, W/ a
- t7 y$ a/ {" H- r" U2 y" I
0 x' Z b$ a6 c/ L$ L
# P1 r" h( f3 k! ^/ f6 e+ E% \- F% i* v/ q9 Q9 E2 t+ Y, Q5 ?2 f
C#
0 ^+ R+ n# ?3 VInnovator innovator = this.newInnovator(); & _; ]' C, D: c7 x1 |
, [0 O1 j! s+ R$ J; S( D8 Y
// Set up the query Item. + P% \2 G# F4 |. {5 Y# ^% l& S# O
Item qryItem = this.newItem("Part","get");
2 a, A7 [- b: B! KqryItem.setAttribute("select","item_number,description,cost");
5 J, O9 F! m% m5 U8 }/ \7 V5 lqryItem.setID(myId); 5 P+ X2 ?8 c1 y, l7 T9 T
: J% S4 S% x7 P( H1 a
// Add the BOM structure.
3 \4 m1 T7 s0 o2 eItem bomItem = this.newItem("Part BOM","get");
% C2 j9 o8 O) x2 Z( k3 {& p% f0 ~' }bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); * K4 r6 V A/ v" D ]. S+ I' ~1 I
qryItem.addRelationship(bomItem);
# X6 `; T$ Y6 m/ X$ i 8 y$ s T- }2 @- F- U7 r% V! U5 H# l
// Perform the query. b* v/ a7 ?& _. e! C* Y, I$ p
Item results = qryItem.apply();
, L" d9 Z+ q7 E+ _% ^
/ S, o% z7 _' B$ A. B// Test for an error. h# @- l' r/ D5 w) h
if (results.isError()) {
9 p" r1 k8 Y% ]. U1 u' @9 v, [* Z return innovator.newError("Item not found: " + results.getErrorDetail());
, k6 }! p7 o9 i}
7 W# J- ]" _& N7 H7 P) \
9 L0 s5 f# ? _0 w3 `// Get a handle to the BOM Items. % D( ?+ W: B- k% t: \0 q0 L
Item bomItems = results.getRelationships();
4 `. L. I9 O8 W a, f5 z4 X1 _int count = bomItems.getItemCount(); / X) X9 ^8 ] P! j& k1 t- |( v! Y6 b
int i;
0 y$ I/ T' W" }, @2 x. {7 X; G$ T ' @" T/ Q7 A- F/ D$ J+ o
// Create the results content.
7 ~% I4 x# a& c: y( s$ E" R9 u& [string content = "<table border='1'>" + ; m0 S, {/ T; U
"<tr>" +
, a1 z: e' S+ ~! v7 V7 [$ Z F U "<td>Part Number</td>" + . }' S, y' Z7 m) Y
"<td>Description</td>" +
% q( r! ~8 u1 s% m! X9 L "<td>Cost</td>" +
7 m9 ?/ }. w5 X0 U: M' _6 V( H "<td>Quantity</td>" +
( ?/ f9 `2 Z0 K N0 g* U/ \ "</tr>"; ! N2 }. b6 k4 k+ h
! K% j' E: z, P% C
// Iterate over the BOM Items.
: @7 s" _& o# m% T) j1 [for (i=0; i<count; ++i)
3 L2 x2 Z% z( x* X2 o% ^8 L- X{
; Q' o( m' O6 E6 g! n+ m1 u' }// Get a handle to the relationship Item by index.
0 \7 h7 V9 I) e0 `/ ^7 U) O& ~ Item bom = bomItems.getItemByIndex(i);
4 V- `' Y& e- Z6 |' b' v0 X% o// Get a handle to the related Item for this relationship Item. 9 t: G7 P A! C2 v5 x0 g) F( ]5 m/ g
Item bomPart = bom.getRelatedItem(); + I2 [: ?+ `$ L9 K5 a
9 K: Z% ~# T& K# G' [, U# D6 L
content += "" + ; A8 i& [& L; B8 o3 H
"<tr>" +
X' x, e5 I- `' N- | "<td>" + bomPart.getProperty("item_number") + "</td>" +
- ?; E# L8 j9 F6 p "<td>" + bomPart.getProperty("description") + "</td>" + , {" ^$ J$ z* [% H' M
"<td>" + bomPart.getProperty("cost") + "</td>" +
: t! |6 _! R6 C "<td>" + bom.getProperty("quantity") + "</td>" + 7 v, ~/ F* e; w
"</tr>"; ) K, q! n5 {. y! e
} " ]4 Y2 b8 b4 H! p v6 m! X# I) |
content += "</table>"; : }" K. P( ^+ w0 p2 |& ^% _
9 `8 t8 F0 B0 f% ^9 ~" k7 g2 \return innovator.newResult(content);
7 o2 R. C$ X3 c# w8 ~1 W' o+ I% D6 G A6 M7 k# M: C/ Y' g
0 c. u d7 }6 M7 y/ |
. D9 [$ Z# Z& _ i s1 m' h: ~9 u4 K9 ?3 j7 c
( y: A/ y' U) x
9 A0 q2 ^& Y+ ^8 y6 \
3 T6 R9 m6 _. D; y, N2 y Page 46 / Q( r! J5 n8 ~7 J* E; @$ t
4 U! S$ v \! R. Y% U( y
Copyright 2007 . T4 v- p3 M7 p+ N# i) g2 q7 [; g+ h
Aras Corporation. " j( x" ]4 T8 |
All Rights Reserved. 9 c% w2 T4 H! X; b9 H5 h" m% w/ q
VB.Net ' n$ c: d4 r* i# J/ K9 B" ^
Dim innovator As Innovator = Me.newInnovator() 6 h) t- p8 P1 P; `
" \5 ~% t& h; Q. O9 q* e' o
' Set up the query Item. . Q2 y D5 S- J* {
Dim qryItem As Item = Me.newItem("Part","get")
# Y6 F7 A! V. Y7 FqryItem.setAttribute("select","item_number,description,cost")
E7 W a8 @: w0 S( P8 zqryItem.setID(myId)
6 A8 D- u, a" D- i5 e7 h; A8 _6 `
X: m X: Z6 c' Add the BOM structure. 9 f' u2 h6 C5 y' e8 [% q
Dim bomItem As Item = Me.newItem("Part BOM","get")
8 |* j( `. [/ w G1 r' YbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ! ?2 J9 L# f$ ?
qryItem.addRelationship(bomItem) 6 U& V7 S1 f5 X- r: Q( L
8 M* E/ A8 w/ g1 ]# `6 w
' Perform the query.
. O( A, w9 e( g; pDim results As Item = qryItem.apply() ! A& g7 X3 o. S6 e
' Q o: w1 D# f! {" Q' Q7 G
' Test for an error.
$ t, _6 S3 ^. }" gIf results.isError() Then
3 ?6 t& A0 s. i Return innovator.newError(results.getErrorDetail())
! U, a' [3 n) C8 nEnd If
, W$ c: J6 j5 I, V
* B i: Q7 F/ z' W- K4 | ?4 Q' Get a handle to the BOM Items. 9 b- a+ W4 V; D# q- P( v
Dim bomItems As Item = results.getRelationships() ( x# |. q! y' y* K" X9 ^
Dim count As Integer = bomItems.getItemCount()
% o$ N0 s) h( j; QDim i As Integer
; i6 ]4 \! m) [* x3 t; U; K! x. ~ 6 x8 s/ c0 X( H) U: |
' Create the results content.
/ e; `/ E8 u/ P" D: G G) b! VDim content As String = "<table border='1'>" + _
! z8 ^0 p5 c' D3 ? "<tr>" + _
: r4 u# J3 J7 ?/ S; P$ S4 Y "<td>Part Number</td>" + _ 9 ~# d# q0 v) F, d7 n1 C$ d5 ^5 n
"<td>Description</td>" + _ 5 m2 ]1 }% P' Y- {: u7 k
"<td>Cost</td>" + _ * a7 g. d. z/ K& d" N
"<td>Quantity</td>" + _ + T u/ a" `9 @: G6 c/ F$ R
"</tr>" . x5 W6 V; [2 j1 f. G# k
) V" T v& J: r( m* c0 `/ K
' Iterate over the BOM Items X6 ~; N7 F; ~) w7 i
For i = 0 To count - 1
2 S0 m, q* g9 w+ v+ v1 |' Get a handle to the relationship Item by index. + ^! S0 z( J c x$ N
Dim bom As Item = bomItems.getItemByIndex(i) - m% b3 G! h% T; L# Z
5 [0 P- G- z+ s8 y: S3 N( Q
' Get a handle to the related Item for this relationship Item.
! @7 F! ]' m% \% ^- F( l Dim bomPart As Item = bom.getRelatedItem() 5 z( T5 P1 w2 V4 }
4 v* ]9 e4 i* X5 Z) t( ] content += _ 6 Q: t: ^# }" |+ e G% |2 I. B
"<tr>" + _
, T) s) I+ q. [$ ]* t( Y4 ^' }0 s "<td>" + bomPart.getProperty("item_number") + "</td>" + _
F) m# Z" Q8 h/ u5 D& Q "<td>" + bomPart.getProperty("description") + "</td>" + _
1 Z5 v4 g; C& S+ J% R2 `5 i, D5 t9 k "<td>" + bomPart.getProperty("cost") + "</td>" + _
9 Y, H* s# @4 H1 A "<td>" + bom.getProperty("quantity") + "</td>" + _
1 k6 y- W# m Z "</tr>" - f2 E: L5 d: y# E! v. |
Next 2 H4 ~9 C9 u' F
content += "</table>"
# o4 `7 z+ n% O" V
9 n y+ _9 ^& m1 `; X+ [: }Return innovator.newResult(content)
( f- H9 `; y! c! |( ?$ R) `9 o) n+ U7 w; G1 \( { ~% W9 @# O
|
|