|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 4 |+ O5 |; E6 m) v5 T7 K0 |
To query for an Item and retrieve its structure you build the query as the structure 1 i9 S$ U4 p8 r' y. A4 v, y
you want returned. Use the IOM methods to add the relationships you want and 1 B; `* o1 I2 d) `2 ]4 s
build the structure in the Item. The server will return the structure that follows the ; ?% R% d, G2 z( [
request structure.
; F% _) ~# {& b5 WThis recipe illustrates several related concepts together, which are how to get a set
$ {6 L' S5 Y9 I* D: l* L: tof Items from an Item and how to iterate over the set, plus how to get the related
# r6 H( D, z% S: m1 BItem from the relationship Item.
2 [7 n9 C- D, }* p: iJavaScript + g, \0 Z O1 X2 O& _7 y$ B. P
var innovator = this.newInnovator();
: }* L, i7 A4 k8 {
% L$ O( J! G" S5 T// Set up the query Item. . } _2 [+ i% J: [2 n4 q- j
var qryItem = this.newItem("Part","get");
0 W, b' q6 U N$ @9 y" A8 f: \qryItem.setAttribute("select","item_number,description,cost"); 9 w# f( ~5 w. k, X/ `5 S7 `; E
qryItem.setID(myId);
$ h" E# T: ?0 q. f7 j0 W
: g3 i! [2 l" M- n. j+ a" _// Add the BOM structure. 7 Z( f0 {' F7 _; x$ M2 x; J$ o
var bomItem = this.newItem("Part BOM","get"); 1 H; k8 D D: \% y ^7 |
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 8 {$ h/ z( A1 n" Y( |2 m. A% a
qryItem.addRelationship(bomItem); ( s, c+ _" b9 ^" R8 i& H
) R, b6 [1 T8 d# B// Perform the query. , O6 @1 m6 d' x- {4 z
var results = qryItem.apply(); " N9 H$ i' X" q/ N, X0 v% p
8 J* q5 i K' V# e' z* Z, l; C/ E// Test for an error. o. S/ K5 S: W+ o
if (results.isError()) { 2 {9 L: i: W7 d7 u! Q5 q$ ^- ~
top.aras.AlertError("Item not found: " + results.getErrorDetail());
" M. `# c# A) V return; 0 l# b6 Z N. _- o6 m( W6 h0 A$ E
}
. w. H8 V( q0 u% B- u 3 f N) q, n: z! c& `% \ S
// Get a handle to the BOM Items.
( X( f, u4 P" Q) \6 gvar bomItems = results.getRelationships();
" H6 P2 u( x# D6 M# e7 svar count = bomItems.getItemCount(); ! l% k+ ^$ F$ W& ~
0 K: l4 u. R6 W// Create the results content.
, ^" E( [7 q g2 l3 Qvar content = "<table border='1'>" +
) V. P' C7 v+ z& M "<tr>" + & L3 {( d6 o t* J. L
"<td>Part Number</td>" +
3 w& U3 h, Y% Z& s2 o7 v" S "<td>Description</td>" + 3 |0 o! B* H" M; W0 m: v4 I4 b
"<td>Cost</td>" + 0 E/ i: g- F% T* m) p
"<td>Quantity</td>" +
/ f; v4 D, J2 P n/ y& p. _/ l' | "</tr>";
6 g+ o! A! C4 t9 x
- @! [4 A& G' s" n7 L// Iterate over the BOM Items.
2 d( q5 }7 k# _6 rfor (var i=0; i<count; ++i)
0 O/ X) y% _: G" I& v" g{
6 k2 e6 Y1 k) w9 b6 ~+ P! n8 r3 Z// Get a handle to the relationship Item by index.
7 B; h3 X' u( E# J% W var bom = bomItems.getItemByIndex(i);
8 k% }* M- ~% _1 _+ e8 b// Get a handle to the related Item for this relationship Item.
7 b; s( ^" w# w5 d) R var bomPart = bom.getRelatedItem(); $ t0 O- V: b& C2 [
% N* k' |* T% O; o5 N1 H' q content += "<tr>" +
% i- t' @. z F; t* P "<td>" + bomPart.getProperty("item_number") + "</td>" +
, A& M% A/ ~% r$ }$ ]) q3 x "<td>" + bomPart.getProperty("description") + "</td>" +
2 x& |, B! c; d. H9 k "<td>" + bomPart.getProperty("cost") + "</td>" +
5 ]$ @ m8 Y" w7 a "<td>" + bom.getProperty("quantity") + "</td>" +
1 O1 `3 E# ]' P1 s2 [6 W4 G2 f "</tr>"; , i3 U' b( o# w- A
} 0 B9 f! q9 C- O
return content + "</table>";. X4 i9 {) n. }7 v- y, l! o" F
6 x: T+ ]- v7 N% a! v! l
* j2 b- h8 o& B0 u$ f' ? X1 G, \4 l9 I- n& J2 y) C7 b: v$ \
* ?& n H0 W' U0 k0 \0 e; c; sC# 1 r0 z }+ v0 ?) y3 ~
Innovator innovator = this.newInnovator();
3 `+ J8 V* {& T# R \
' H, I [- q( A1 F+ O9 v- ]5 v// Set up the query Item. " C) L7 n" R1 e; f$ D
Item qryItem = this.newItem("Part","get");
2 G' n( _* d: D% U I$ BqryItem.setAttribute("select","item_number,description,cost"); / d$ Q4 r, ~& f" m
qryItem.setID(myId);
0 @3 Z* A5 A! S6 O. N; E( ^" h" q
6 X) h% ?' N: W// Add the BOM structure.
1 j, Z$ f' ?$ d! aItem bomItem = this.newItem("Part BOM","get"); $ {* m5 n2 J% C* Z. ?" w
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); Q2 M: L' P) _9 K0 v& A6 e3 }
qryItem.addRelationship(bomItem);
/ B2 k# m |+ b% `& e, _ 1 Q$ S6 }" \: y0 w/ y, M$ D9 }7 p# w
// Perform the query. & o; A- p* m* d
Item results = qryItem.apply();
0 Z" N: P9 j" @! Y
5 j, }8 c/ S1 v& \// Test for an error.
8 N4 k8 d5 `7 `( h% I' Uif (results.isError()) {
* }. C9 [$ U5 e( L return innovator.newError("Item not found: " + results.getErrorDetail());
7 r, s9 ` N9 K" P9 [- N}
/ R* z5 g0 y/ g: w9 h( b8 b
# J& b6 [/ D' i9 \// Get a handle to the BOM Items.
% f6 z( K+ U/ N# y7 HItem bomItems = results.getRelationships(); 9 R8 {/ j6 Y" z& u; p8 n
int count = bomItems.getItemCount(); * y9 d# x5 x/ j$ K5 n
int i; ) v, N$ T( ~' |" _4 F1 y7 h
- |! i/ Q, L4 Z3 P# G- a p: W- H
// Create the results content.
% a# h# a" _, v8 S% Q$ B4 L8 Hstring content = "<table border='1'>" +
& b6 ~7 E4 {% o "<tr>" + 2 F, l$ U& M7 ], t
"<td>Part Number</td>" +
: d7 _) D1 i1 i. u8 H4 | "<td>Description</td>" +
9 S! P$ Z7 [8 Q( ]0 { "<td>Cost</td>" + 4 L, {$ h. Q0 w
"<td>Quantity</td>" +
& V, T3 P8 L( U: o$ k+ D" m6 U "</tr>";
/ D6 ?7 {$ f* m* i 7 [! ]4 P/ b; f6 W/ S1 n/ h( r
// Iterate over the BOM Items.
$ m* W; F9 i% K9 Z. Yfor (i=0; i<count; ++i) 1 B+ k" S4 [% z Z
{ * b1 k5 a+ s' {" M
// Get a handle to the relationship Item by index. }2 \/ ~# A! R1 X. U, D; {
Item bom = bomItems.getItemByIndex(i);
! X& T2 X4 O% e3 i5 q" ^// Get a handle to the related Item for this relationship Item.
& N6 ^1 o! i5 J* T4 x Item bomPart = bom.getRelatedItem(); # l0 h8 O( K* }" _6 L8 `
: }2 Q; T% O- H$ n: ]/ Q( S content += "" + $ n# \3 S& k4 v
"<tr>" + + |) _" k! @# |! n4 k+ u. f
"<td>" + bomPart.getProperty("item_number") + "</td>" +
6 v. {3 M5 I, \0 `9 X) ]3 L "<td>" + bomPart.getProperty("description") + "</td>" + * g- d W" |, r1 e
"<td>" + bomPart.getProperty("cost") + "</td>" + 5 M4 y9 w% a t- t9 @4 \
"<td>" + bom.getProperty("quantity") + "</td>" +
7 g a% t" H: h- m$ D" G "</tr>";
& \/ z+ w) x6 Z( y}
! N6 e z) E' w. }) r$ bcontent += "</table>"; 2 s/ [$ i6 k- H: k
1 Z9 y8 b3 [; Z, {return innovator.newResult(content);
1 \( @( c, R3 G* a5 ]" Q0 ]" v* |4 _ t# @# W
# r+ l4 @+ B3 X7 m5 t1 b0 m# ^" {
" h8 ?, H% ]4 e# P
8 w+ E' X: W' v: Z! y* P- ]3 r& j- ^3 F
1 E- L; i; Y+ F& f+ k4 \& ~* f& u
( i: d7 ]" K8 X% ^0 b - {, I/ m9 J( d7 K8 g/ V" P, q2 |
Page 46
0 A0 I: N+ i, ]/ x6 ?9 N; y & p A. `$ P2 X9 T% L
Copyright 2007
! x+ Y2 _( B0 J! ^Aras Corporation. * U& s: |( Y1 E; s3 d! W
All Rights Reserved.
- K$ n" L, i8 s! p6 J2 gVB.Net ) u# z: V/ x8 a" e# ~, B
Dim innovator As Innovator = Me.newInnovator()
0 E1 |3 t9 B1 T6 `. ^% M
$ {; L9 o6 |5 W1 q" Q6 X0 m' Set up the query Item.
: a, H! E9 C1 aDim qryItem As Item = Me.newItem("Part","get") 2 T- H1 f/ w* H1 S$ G: g( }8 G r
qryItem.setAttribute("select","item_number,description,cost")
" p% Q. |' E8 Z; @% M" r* j% L: dqryItem.setID(myId)
/ N, K/ ^% \; X% R
& H" M* u- b) D5 t& B0 u' Add the BOM structure.
0 t$ A8 D) e: q6 h6 DDim bomItem As Item = Me.newItem("Part BOM","get")
' a0 `( T3 z; ]bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
; W4 t" O2 d/ i5 a6 a& rqryItem.addRelationship(bomItem)
) F6 V/ `; ^" Y* X r - b$ R) T2 d/ E n+ O/ \, ~! R% G$ ~
' Perform the query. ' T( T# V. j' u8 d4 y" A
Dim results As Item = qryItem.apply()
$ v! f3 X6 f: L( c! G
5 N* }* r: B# s$ g: a4 P' Test for an error. * g _( J* l- X. O$ V4 C( _
If results.isError() Then 3 K4 u( M0 _! A! w% d5 p) |* Q
Return innovator.newError(results.getErrorDetail())
* X/ D& ?1 Q; V9 [" HEnd If $ x8 t. a4 B1 A9 \( d+ a: L
' l' y+ f! R( T* }8 h' Get a handle to the BOM Items. : I. Q; d h5 C( b: P% Q: N
Dim bomItems As Item = results.getRelationships() $ R$ o( R% L. p/ Y X$ A) b
Dim count As Integer = bomItems.getItemCount()
* E, u) w( r6 T5 v( ]Dim i As Integer
' j2 E, j1 ^& D$ o6 W% I0 q
+ `, [! i! Z" a; v3 l' Create the results content.
5 _5 V" Z/ W! M. m* `Dim content As String = "<table border='1'>" + _ * W; l& d: D0 l1 F/ y' v+ o# |& B$ k6 g
"<tr>" + _
' \- l3 F. p, T6 y& K' _ "<td>Part Number</td>" + _
! o7 ?% t7 P X. S "<td>Description</td>" + _
) P F, G# v; E1 A- C "<td>Cost</td>" + _
^" L: `. E1 N0 G "<td>Quantity</td>" + _
" N8 C, m2 O7 L1 B& R& Z& j "</tr>"
: M, _8 m @) M: f; d4 [# F
/ S$ A- W8 D: D% k# M# x' Iterate over the BOM Items ) b: D1 Z5 u/ Q, M$ }* R5 \) c! G
For i = 0 To count - 1
# n+ V* F$ S% U' }; h' Get a handle to the relationship Item by index. / T5 l4 |8 t) A, a
Dim bom As Item = bomItems.getItemByIndex(i) 9 l: D8 s' o9 u# R
T0 m0 a# Z( C0 O! C; v1 L: [
' Get a handle to the related Item for this relationship Item. 9 |: `( R3 M( j% T
Dim bomPart As Item = bom.getRelatedItem() 4 U/ L8 W* B3 w4 r- V2 B* c8 H
P9 ^; B$ |# s content += _
! T0 t3 D3 L# [ "<tr>" + _
' O1 F, \( o: |' V "<td>" + bomPart.getProperty("item_number") + "</td>" + _
/ V; i5 |, x* |* {- U" j "<td>" + bomPart.getProperty("description") + "</td>" + _
5 Q5 q1 Q# j6 X/ }, T- B, j "<td>" + bomPart.getProperty("cost") + "</td>" + _
5 Z: ]" Y7 E% J) X+ c "<td>" + bom.getProperty("quantity") + "</td>" + _ * ]+ x( Y2 f: R% X% h3 |
"</tr>"
3 A* M; n3 h4 yNext $ \- ]/ {0 b5 v2 F- F8 A! ~* m/ L
content += "</table>"
1 b5 p: M& T" e1 [ : A7 V/ J* E8 E# I5 G: k$ @4 U3 o
Return innovator.newResult(content)
8 n4 M+ v, z2 ^# b4 ^0 G- S5 K0 r( g- v) D+ e0 z( f
|
|