|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique : r, U0 {& f6 Y5 l5 A
To query for an Item and retrieve its structure you build the query as the structure
/ Z5 q* ^# [! t6 d; e0 U/ c5 w; @you want returned. Use the IOM methods to add the relationships you want and & j: P5 W: J- G4 y, |: c
build the structure in the Item. The server will return the structure that follows the ' s9 l- X; v# ~( w( j; ?- q
request structure.
" `( C. U# B" P) z6 c4 ?, sThis recipe illustrates several related concepts together, which are how to get a set 5 F+ H3 R% L& o/ c$ F6 k+ t
of Items from an Item and how to iterate over the set, plus how to get the related + o( d5 M- p- \% I0 ?1 n: i( ?) j
Item from the relationship Item.
6 l1 `% H& i+ w9 U: V$ c( r7 E+ ^JavaScript
, K! @/ N+ T9 B' R% A# g9 fvar innovator = this.newInnovator(); 7 G( _9 `5 Z! l) C* Z# s i- L
/ [+ ]. M* C/ k( s* r0 c/ x, M// Set up the query Item.
, J( V3 Q/ O5 M9 q7 ^var qryItem = this.newItem("Part","get");
( _8 {3 c' ^" o6 v0 J FqryItem.setAttribute("select","item_number,description,cost"); ! j9 d9 x* {( E$ O6 H8 D8 D3 `
qryItem.setID(myId);
0 s( }% J1 m1 h2 L, p
4 E: r8 i7 ~6 j$ y% [0 t2 D// Add the BOM structure.
0 H- W2 H, Z5 V( v+ ]var bomItem = this.newItem("Part BOM","get"); & `) p: y: k( S- v& W& g2 ~
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); . T8 ^: w" G) e/ Z& ?+ w
qryItem.addRelationship(bomItem);
5 @$ K$ X. }' c# f, z 1 Z( S: f) G) \2 C1 K5 w+ y
// Perform the query.
! I- @$ |; {9 D$ T) fvar results = qryItem.apply();
& r$ V' e: K4 d/ J+ e ( y5 y6 Z. L: h2 }- D O& |
// Test for an error.
" D1 H) Z. \. Z% ]if (results.isError()) { & A* g) \7 v& n. |% W |
top.aras.AlertError("Item not found: " + results.getErrorDetail()); " v& N5 q1 Z; A5 j2 F$ F3 t/ ]4 W
return;
' B$ T4 ~. w! Z; J; m$ x1 u}
, y# H; r" Q! O6 { & G* O0 P% Y$ \, D" }1 \; _
// Get a handle to the BOM Items.
& u& R) @" L% b, J, Q# g+ Y( rvar bomItems = results.getRelationships();
4 ^. t" o2 S7 D# e, K, J6 [var count = bomItems.getItemCount();
5 _( F2 i6 F: x" z6 F l( t
& t6 T4 w/ _' \* I/ ^: q// Create the results content.
5 ]6 o( d7 q+ C# {5 Zvar content = "<table border='1'>" +
5 u5 p& J- A. V: ~# r "<tr>" +
. P2 [1 Z% h2 n: v# e "<td>Part Number</td>" + 8 X5 b: Y5 F# T) k# b
"<td>Description</td>" + ) w5 k$ u# _& o$ n! q: i
"<td>Cost</td>" +
# f" M. N9 V1 o' z5 C% ~6 u& b "<td>Quantity</td>" + 6 }* }- a7 C- W3 m
"</tr>"; 2 q/ m$ K( f- e! D8 i1 C) S3 o
6 ?- y1 Z& J9 a$ K" v! F, e) i8 `
// Iterate over the BOM Items.
; |9 M7 J/ @$ c4 [& I7 p0 Jfor (var i=0; i<count; ++i) 5 W, l7 R% E3 \" l4 G3 M! N& t a
{
' q: s c! S1 p, {$ D! l+ c// Get a handle to the relationship Item by index.
' g" ^: r# M2 W var bom = bomItems.getItemByIndex(i);
: z- F, u& Z, `7 w% h// Get a handle to the related Item for this relationship Item. 0 S$ y8 s, Q$ O8 U1 O0 d, _& p) h
var bomPart = bom.getRelatedItem(); + x+ Y; z$ U6 x, P& x
2 ?) Q- t6 l/ X( `+ @ content += "<tr>" + ' P" j; b' h+ |3 N
"<td>" + bomPart.getProperty("item_number") + "</td>" +
; k# E5 M" H, c "<td>" + bomPart.getProperty("description") + "</td>" + & }+ P- O' p3 a2 w: B8 z" w* V5 u
"<td>" + bomPart.getProperty("cost") + "</td>" +
* \0 I. X/ q k5 ` "<td>" + bom.getProperty("quantity") + "</td>" + 2 Q1 ]' b' S! Q1 l/ i7 K/ G
"</tr>";
m" X2 N& Q9 m8 ]9 A}
! O& y6 z; {9 J1 P9 E% z( p) Dreturn content + "</table>";
( T3 Q* |4 Z: g: I& `
$ ^2 F7 |$ ]" v# P6 w \) ]
]! u, y* J$ U. \, a
. ]- c6 g) `9 J- X/ u
% X; P# r3 q& L g1 K$ Q* M5 eC#
. C( X& t. c5 z( V1 EInnovator innovator = this.newInnovator(); 3 A2 a! O; n) E2 l2 k/ }/ P
6 y0 C* w# B/ g// Set up the query Item.
/ g2 J+ @! R6 BItem qryItem = this.newItem("Part","get");
% d, G, h N/ k& }6 ~# r' HqryItem.setAttribute("select","item_number,description,cost");
\1 e3 ~+ a7 c' h' ^% n# A" mqryItem.setID(myId); 3 r4 Q" R) t! Z
9 B6 M/ Z; D0 X! t! L
// Add the BOM structure.
! f6 P' ^( D- ~+ l1 l$ N' WItem bomItem = this.newItem("Part BOM","get"); ( F. k$ W" A3 E, k- K" C7 E
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
$ o6 u6 }% y* a& c* } ]qryItem.addRelationship(bomItem); ) ~9 N, C, c/ y4 l, @2 }3 S) w/ S4 f
5 _0 [+ h/ q" _* p/ t) q
// Perform the query.
! x5 L6 T% x) a/ R' MItem results = qryItem.apply();
9 D# W+ G M# g; } ' D; o( ]0 s& \; D7 S# c
// Test for an error.
; Y. ]2 R8 {, n. A; a8 W, X9 @7 C) xif (results.isError()) {
4 N5 {: G1 w0 s V+ r return innovator.newError("Item not found: " + results.getErrorDetail()); 2 L3 | T: ?. `* k) d( w& ?7 i, A$ Q0 s
} + T% {9 r* U( o, ^
0 M1 Z- G* c" r2 c// Get a handle to the BOM Items.
: `5 z! C% J2 UItem bomItems = results.getRelationships(); , M4 c6 E8 s% m+ e4 d; i
int count = bomItems.getItemCount(); " R/ n) r q. ?% u
int i;
( U/ q0 d1 @2 G# W: I |# q" d$ p- } {0 S- _+ H) m
// Create the results content. . a, k, R) N6 }) B
string content = "<table border='1'>" +
" k5 @2 A& v) m2 n& O, k "<tr>" +
4 p( Q4 g# v2 X# {; Q "<td>Part Number</td>" + Q5 i# k& Z2 I
"<td>Description</td>" +
6 a% O( I: V7 Q; F/ j# ~ "<td>Cost</td>" + 7 \6 z( D w+ L) S B7 M) L
"<td>Quantity</td>" +
% u3 E2 R( g/ p3 v/ R$ |/ u1 \- k "</tr>";
9 E& u$ U8 w3 ~8 H [* ^ . B, s. s$ r3 t5 \" ~4 w; x
// Iterate over the BOM Items.
; s' }2 M9 K- k9 Wfor (i=0; i<count; ++i) " O: S( v) B7 |
{
4 w* \, Y/ X" U. A// Get a handle to the relationship Item by index. ( p) `4 l, ?1 R, Y, ?* v3 Z$ w
Item bom = bomItems.getItemByIndex(i); 0 f4 w6 o# c% `2 H- l* H
// Get a handle to the related Item for this relationship Item.
3 L8 J, i3 \% B Item bomPart = bom.getRelatedItem(); 6 Y0 j4 z4 S( K: B
# g' c9 s3 W+ W% M" i* ^ content += "" +
3 c: b& n! A# H6 L W4 C& ]- L$ a1 u "<tr>" +
; b7 Y" Z. S. k2 ^9 z "<td>" + bomPart.getProperty("item_number") + "</td>" + + N* \0 ~0 s- \' l; m/ |
"<td>" + bomPart.getProperty("description") + "</td>" +
% L; x6 b- ]5 [/ d1 [; s# Y8 ~8 _ "<td>" + bomPart.getProperty("cost") + "</td>" +
; a. m# {; ?8 B+ R "<td>" + bom.getProperty("quantity") + "</td>" +
, E- \7 r G# E "</tr>"; . u% N! t% o8 [7 s' s, F& w
} o' z- S' o( V. C" Y |# |
content += "</table>";
6 o+ ]5 S1 ]3 s
1 V/ {& n0 _) R% D0 Oreturn innovator.newResult(content); L2 p% A4 ^: k$ u
( l! V# ^% j0 |, ^" |) o6 X( e
5 T! G* u4 j* R( R. M
7 X! y& A; T# q M9 r1 Y* w! t, W. T1 }; `( G" I- L
: d1 Y, D( S' t' O
' v1 ?0 [( ~2 w6 _: I
. L" G0 z8 F* }: B" g/ U Page 46 ' n3 x3 Z5 ?0 k7 u9 R2 y
! x# R1 Q' @ f; x7 ^. k& v& o5 u
Copyright 2007
: G2 n: S" G* h i. u. {2 RAras Corporation. z: o7 i7 |+ o
All Rights Reserved.
! N% ~, t. `1 uVB.Net # o( [# I% Q% [& U4 T
Dim innovator As Innovator = Me.newInnovator()
% ^: ^1 b2 y; J% Y1 A1 h* S * r$ |8 ^# y4 |( h5 x) t7 m! |
' Set up the query Item.
( `2 ~9 T* W: B" r' l0 \" T6 aDim qryItem As Item = Me.newItem("Part","get") , v9 W5 J" `; m$ a
qryItem.setAttribute("select","item_number,description,cost")
4 K. Y4 [) M7 l3 ~" tqryItem.setID(myId)
0 G2 U; F c$ x% P0 w0 ]
+ ]3 }8 K; C6 s3 }1 G' Add the BOM structure. $ u% ? x P5 C0 j
Dim bomItem As Item = Me.newItem("Part BOM","get") : O3 F9 Z* B: R! T$ c* f
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") , n) I$ p, n& g* p4 X8 H
qryItem.addRelationship(bomItem)
! n5 e9 J/ f7 R/ N2 {% i 6 }( I# H, t5 t, K- q4 ?! D2 v
' Perform the query. 2 Z9 X$ s" d4 U% g# w1 `! c2 {
Dim results As Item = qryItem.apply()
- h2 _1 O' ?; S
- L1 P, B' ^( N' q' Test for an error. . G) }" T/ y3 y' j
If results.isError() Then ; @* S' ~/ m4 `0 X" b" f
Return innovator.newError(results.getErrorDetail()) 4 o3 n0 y( F+ O6 u/ I! R, `
End If ( }7 w. a5 V6 F0 U* }6 ?$ P
* W; _5 @: c7 K& v$ a$ L' Get a handle to the BOM Items. ~- @3 X& C$ B' z8 t. I# t [
Dim bomItems As Item = results.getRelationships()
* n! L% `& |! j6 J* h j4 oDim count As Integer = bomItems.getItemCount()
3 F# D. E$ ]1 q7 l& G# S1 yDim i As Integer
9 }! i7 C* ]$ G1 w, _- o0 k( @: }
" U2 T# v& p$ w# h0 @1 P; ]' Create the results content. - p0 _. m. ^; w# W( ]/ |) E
Dim content As String = "<table border='1'>" + _ 9 h6 T. ^+ R4 i# E0 _$ g" c4 ?
"<tr>" + _
5 o S7 h# g) I; h7 R "<td>Part Number</td>" + _ 7 a2 q9 d! i( h4 N& f
"<td>Description</td>" + _ # @; T ^3 ]# Q# g' a" I( K
"<td>Cost</td>" + _ 2 {% X! J; S- X6 F% D7 ^5 e
"<td>Quantity</td>" + _
9 k/ S' R+ ?& E" y! L b2 m8 y2 ?1 F "</tr>" / s, K2 L) B- c6 A. h! A
f Q0 X8 D* D4 C/ N& U7 a3 X' Iterate over the BOM Items 1 V0 e7 X4 ?& L. Y1 {! a! E% @
For i = 0 To count - 1 $ ?& k1 L8 a5 z% Z1 H
' Get a handle to the relationship Item by index.
3 I6 Y! X! e; @8 a6 b; l4 U' o1 T Dim bom As Item = bomItems.getItemByIndex(i) / W1 w6 e3 r3 E, \
' J, S! g6 w% p2 R' Get a handle to the related Item for this relationship Item.
0 j0 S! s" B2 C# v+ R f+ }) D Dim bomPart As Item = bom.getRelatedItem()
& O6 q/ P. {8 p s: J+ I
0 }' O; ^0 o9 q( R+ v5 l1 i/ [ content += _ 1 c* H+ P5 L$ S! N
"<tr>" + _ + A9 w; q: f, t
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ % v$ r# c" a) q) s
"<td>" + bomPart.getProperty("description") + "</td>" + _ * q, V* P2 N8 Y( C) A/ R3 j
"<td>" + bomPart.getProperty("cost") + "</td>" + _ , ^8 G9 m4 U! f) p, M/ ?
"<td>" + bom.getProperty("quantity") + "</td>" + _
& H0 o3 H6 @. e. `% J" C "</tr>"
" q' C4 Z; }/ f7 ~+ ZNext
( A9 n$ j0 L ncontent += "</table>" 5 I7 \" D9 y' U6 D
7 `" Y; b( {0 r6 QReturn innovator.newResult(content)
2 D. V- ^3 M) S- F
" u0 M2 r, t1 e# ^6 ~, g5 W% h |
|