|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
Technique ! \8 |- o, X% E- l% ~7 M% z
To query for an Item and retrieve its structure you build the query as the structure
8 Z( h; \; k2 ]% K+ q3 J: }- N/ O. Zyou want returned. Use the IOM methods to add the relationships you want and 3 b$ M0 L. C" u0 W$ |' c- `
build the structure in the Item. The server will return the structure that follows the % u2 R9 D# A* D+ N& b5 z( ^" k
request structure.
2 _: l: t3 d8 y( f, A0 P' bThis recipe illustrates several related concepts together, which are how to get a set
& m, ~7 k/ |1 w* fof Items from an Item and how to iterate over the set, plus how to get the related
" O* ?% [; W0 J# G+ h- A D) B4 b- UItem from the relationship Item. 3 S' X- K: V! r# f% |
JavaScript
( X5 c* z5 p% Z1 P3 N! e/ `var innovator = this.newInnovator(); ( t5 z- E6 [6 `/ c& _
1 U* g, S$ r+ ?
// Set up the query Item.
6 R' {$ N1 a I$ `3 [var qryItem = this.newItem("Part","get");
# V, X2 G, X$ P1 i2 s* f; a. QqryItem.setAttribute("select","item_number,description,cost"); 7 Q8 `) P" Z! ~- C- s% g! m
qryItem.setID(myId);
7 i3 Q' }7 U9 Z$ j5 p) x * R& d8 x% j4 j: k6 D- b0 h
// Add the BOM structure.
# D) K' r2 u" J& f9 ~var bomItem = this.newItem("Part BOM","get");
. u. |& L6 H3 D% m$ u+ pbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
% E, C0 g- f) x3 O* M9 {* wqryItem.addRelationship(bomItem);
* g2 D- d+ C2 A$ o' c9 [9 `
% j& v/ j1 n( W: e8 Z$ w3 e// Perform the query.
7 F/ J% G5 ]/ \8 L! Qvar results = qryItem.apply();
; A2 x/ c2 c6 ^% q9 v* g! m
. H$ e8 v& k0 Q7 x// Test for an error. # m9 Q% O* s8 G$ U
if (results.isError()) { $ P& J( a' t5 p/ e$ Z1 _
top.aras.AlertError("Item not found: " + results.getErrorDetail());
0 s! D" k) o. m; r" G return; $ M9 a" }; y* }5 N5 t m. ^
}
. p/ h" h6 \* } `0 _7 m , a1 ~' R$ ~* v& W
// Get a handle to the BOM Items. , \5 v" E. ]( S( H8 K
var bomItems = results.getRelationships(); . C% N1 z/ `) \7 g5 G: D! |/ G
var count = bomItems.getItemCount(); * ] C' c4 Y7 d% g) E; u9 K
7 X6 d( G0 ^3 W6 X( M2 a
// Create the results content. 7 u$ `" _( u) w; K5 P, E9 {6 a
var content = "<table border='1'>" +
$ N8 u- j! f+ ^ {4 b1 z5 `# G "<tr>" +
& v* C$ V! H0 ~1 j! i. O) U# h "<td>Part Number</td>" + / W/ I2 e: m9 _& S6 r+ m ]
"<td>Description</td>" + 7 O: j! A' K' R2 J
"<td>Cost</td>" + # E9 d7 [, B$ C, |& K2 j9 @
"<td>Quantity</td>" + 1 g* I! x* ]9 }
"</tr>"; 8 L, G' h1 ~0 Z C3 P* D
U! j6 l9 ?) `& T3 S// Iterate over the BOM Items. 1 Z$ G. F- q9 o9 M5 T+ `
for (var i=0; i<count; ++i)
! }$ ~) I; ~4 N! W{ , r7 d6 i, b: f7 Y- w3 x
// Get a handle to the relationship Item by index. " J E- E6 f# @
var bom = bomItems.getItemByIndex(i); ; J, n, G0 B. `' z# a
// Get a handle to the related Item for this relationship Item.
4 K+ ]$ O5 p, R2 g2 q0 y- H- c' z/ D' h var bomPart = bom.getRelatedItem();
K; }+ f/ Z6 a9 ~4 O
& _& F9 y0 z7 ` content += "<tr>" + ( \# Q1 {! I4 P* ?( R0 e$ b
"<td>" + bomPart.getProperty("item_number") + "</td>" +
. `) q$ Z9 S, D' a "<td>" + bomPart.getProperty("description") + "</td>" + & `1 J: [0 Q' T
"<td>" + bomPart.getProperty("cost") + "</td>" +
9 x5 c: K0 F+ u Y "<td>" + bom.getProperty("quantity") + "</td>" +
F1 h# a& u3 z: q0 F "</tr>"; 7 o( V% v* d/ T( e2 o" ^
}
% k2 z! P6 r, T7 J; q: v! P. w9 Treturn content + "</table>";/ p! q8 `4 v% g# R: N5 x# J" v
. M* @- C. h; G5 E6 o8 {% L; d* G5 s
( }6 y6 ~0 c2 Y0 d3 w5 F; S( K
( }# ^; S9 {, cC# 9 q; g* k) Q( ^+ d: g Z1 d
Innovator innovator = this.newInnovator();
" P4 p2 R+ e# A9 i ) ?% o* g$ i+ V4 s( X
// Set up the query Item. 4 l3 J/ t3 ~ A7 k9 A
Item qryItem = this.newItem("Part","get"); ' P6 s; {. J: p. f4 \
qryItem.setAttribute("select","item_number,description,cost");
* c6 p; r* z1 n& V( a- EqryItem.setID(myId);
/ S# S' u" P: v# s8 F
4 _( O3 u$ s! d" R- C4 U// Add the BOM structure. 8 m( @ w! t2 Y; |
Item bomItem = this.newItem("Part BOM","get"); , A' l. W# Y- L% `8 U* u0 Y
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
" H z/ b' g6 v" i4 uqryItem.addRelationship(bomItem);
/ a# T; |( v4 m. Z) F0 O
9 ~" Z G3 Y# G/ g0 P& ?// Perform the query. # ?4 _" o& u' V; f8 E! Y
Item results = qryItem.apply();
2 j1 O; M, n. T7 }' @
# T# g; V' e4 W3 [% ^. O// Test for an error.
* k7 N' ?3 z* k1 k- y( kif (results.isError()) { ! Y# j; W1 ]4 o) V$ G/ j
return innovator.newError("Item not found: " + results.getErrorDetail()); ; N. P1 l+ a6 P/ ~+ L
} . a7 y, J; D* o. G, V
* b" b. N4 s. Q( a// Get a handle to the BOM Items.
: t7 y% ^+ c% v. iItem bomItems = results.getRelationships(); ! c. } v" W& J' C
int count = bomItems.getItemCount();
) R* O5 {) u Z% X0 Cint i;
% d& S6 {" o9 T7 q# E) l
1 f: J" E' h' `# M5 O) c& U// Create the results content.
' L, v4 Y, s' _3 p- n! ]string content = "<table border='1'>" +
* w5 c: w; c( h% c& d S "<tr>" + % A% l: ~. i E Q4 z
"<td>Part Number</td>" + 0 L" Z. {. y; ^5 ^& c. H+ |. u7 _0 s
"<td>Description</td>" +
' z; J* U3 R0 L, Z! b1 `4 f "<td>Cost</td>" +
2 O% b! n6 Q! X$ x( z5 e" | "<td>Quantity</td>" + . R9 n( o4 \& H8 ?, R
"</tr>"; # n$ n& y c" v; k
9 r4 B9 G, X$ b* q# L* T6 Q8 g// Iterate over the BOM Items.
; }9 r. i' ^5 o$ vfor (i=0; i<count; ++i) " @" Z M$ w. s: r6 a9 x% z
{
9 N* T. v8 r0 }// Get a handle to the relationship Item by index.
+ H0 K8 D- R' s* M% `6 I6 a' R) H Item bom = bomItems.getItemByIndex(i); $ a3 o8 F/ @6 f6 [# \
// Get a handle to the related Item for this relationship Item. % i3 x# @& M0 x/ I$ V: m
Item bomPart = bom.getRelatedItem(); : a7 O* S3 c" |/ z
6 O2 p6 p/ c2 \0 ~$ B; i content += "" + ( e7 v9 j9 B7 [/ F6 ]
"<tr>" + 3 T5 a6 n) I$ T
"<td>" + bomPart.getProperty("item_number") + "</td>" +
Y6 l: ^/ ]3 u1 {4 v( m "<td>" + bomPart.getProperty("description") + "</td>" +
& R& F# Z' l! Q5 f" ~ "<td>" + bomPart.getProperty("cost") + "</td>" +
9 K1 O: ]! z+ J- s( _: J4 }7 b "<td>" + bom.getProperty("quantity") + "</td>" + ; B) N0 G0 a4 d$ m8 I
"</tr>";
( a5 h$ M4 S/ `}
2 C8 }, k- _+ a$ \4 S" Q3 Kcontent += "</table>"; 5 j+ U) f# {$ r: k1 s, I
# P, x5 W, F8 l* t% e! Wreturn innovator.newResult(content); , l0 T4 q5 `( c* Y
1 A" j. s1 y5 ~0 \' T
( i9 f. {" n- e1 W) p% G6 g+ R: h: r) W4 ?" I
# o9 Y- g& {# ~) J, e1 u5 s( t1 j! q' e% i
: m( Q- l* y/ o! [
; w2 ]7 n8 g6 S% T9 |7 T9 |+ v Page 46 ; O8 b2 m8 J* E- r( B6 v; J
5 G, M9 @2 v8 |( \0 `Copyright 2007
" k% }2 ^- _( F" y& z4 CAras Corporation. ( }: z' t" n0 c+ {# c2 e4 n
All Rights Reserved.
& p) U5 L7 e2 M$ j; |0 P2 JVB.Net 1 p5 j8 j9 Z8 C3 Y' K; ]# H
Dim innovator As Innovator = Me.newInnovator()
9 }; ]' o7 [/ B7 h( I2 v1 r' U
# a1 Q' Y4 p6 C; T) @' Set up the query Item. - Z5 h4 B. g4 Q8 q; H% Y9 R
Dim qryItem As Item = Me.newItem("Part","get")
9 B* K2 J* ?, cqryItem.setAttribute("select","item_number,description,cost")
6 E3 P$ p8 D W* |; Z+ sqryItem.setID(myId) : g- f# b* a# J
* l! c; v3 b4 K5 r3 d
' Add the BOM structure. 9 F3 |! ~! Y( J. [
Dim bomItem As Item = Me.newItem("Part BOM","get") & W* D( r3 E' |
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
3 m4 `5 b* }) d9 L) gqryItem.addRelationship(bomItem) ( k& j1 `9 @6 u' f% u
5 \9 v; G& l9 b8 G0 ?. R+ ]9 ]
' Perform the query.
1 O* f% d+ s5 ]" lDim results As Item = qryItem.apply() # Q% V- t3 X( n" P/ L
2 H1 d6 b! ] i- E+ S9 l }' Test for an error. N% E9 w% K' Q5 ?' P; b) z3 f" n( o
If results.isError() Then
+ f. o; T4 S3 ?! D) S; j6 m Return innovator.newError(results.getErrorDetail())
Z$ Z' n2 c, [, q2 PEnd If
& b# b" [( f# p5 ^1 |' k2 G
) i3 P% | Y" g" d( f0 a4 [3 J' Get a handle to the BOM Items.
' u2 ~$ X) O7 H: q# ]Dim bomItems As Item = results.getRelationships()
* Z, P6 ?8 f/ \% g3 q2 V& bDim count As Integer = bomItems.getItemCount()
9 Z' ^( I* c. sDim i As Integer ) P2 a( @4 P, S
9 _" C4 v: D8 _/ L/ `3 k1 v
' Create the results content. - ~2 C- Q4 G2 L1 c) g# U# ^3 K5 n( |
Dim content As String = "<table border='1'>" + _
9 B; a; Z+ {: _, r7 `1 _ "<tr>" + _
2 R- E( Y0 R5 ?% Z* Q$ w7 e" Z "<td>Part Number</td>" + _ 3 M/ \4 S; w' C4 ^) S* N/ Z
"<td>Description</td>" + _ ; X/ M+ b4 v, H7 {0 |
"<td>Cost</td>" + _
* K. h' K: {' A "<td>Quantity</td>" + _
' y' V( z8 F" k! ~ "</tr>" 2 l# s0 n& i* r# O7 X0 n' I
! \. }# i2 o$ B+ \" b- @7 ]' Iterate over the BOM Items 8 {6 q. q1 e2 N; e* z2 ]# g& Z4 w5 r
For i = 0 To count - 1 4 B) @8 R4 t% v; P0 j/ x
' Get a handle to the relationship Item by index.
5 ^% @8 X& g. S# ]- ~4 M Dim bom As Item = bomItems.getItemByIndex(i)
, _) |9 i3 u1 a : \1 _. {2 X# a, ^7 {
' Get a handle to the related Item for this relationship Item.
. [ T$ E0 o4 Y Dim bomPart As Item = bom.getRelatedItem() ( k+ F2 }' R- K8 g" ], }& t$ G/ o1 x
9 `, v! r- y: v8 {
content += _
, ^ [. H: B1 \5 [, d1 {* E+ d "<tr>" + _ 9 k) K: D2 H; f
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ " V9 Y$ W" a6 s8 \# Z4 ^
"<td>" + bomPart.getProperty("description") + "</td>" + _ 7 `$ x% B, ~8 i
"<td>" + bomPart.getProperty("cost") + "</td>" + _
& u& e" N5 h- b "<td>" + bom.getProperty("quantity") + "</td>" + _ X8 }% a3 |4 R1 p8 j
"</tr>" 6 f( y7 y9 b* F- ^
Next , |9 M" j0 y. k& M9 Y
content += "</table>" 6 r& H+ n6 Z# b, l6 v' F
! P) } L9 A- E& o7 L( ^Return innovator.newResult(content) 2 _. C' k/ [+ a4 c9 r! ]% i. ~
8 ]' }, R! |& O' u4 \- q/ S0 ]
|
|