|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ! c, m' K7 e+ `$ B2 {
To query for an Item and retrieve its structure you build the query as the structure * }# A E$ t' w7 C. F/ q9 p
you want returned. Use the IOM methods to add the relationships you want and 6 R% Q; U5 i- j( u
build the structure in the Item. The server will return the structure that follows the ! ?2 T6 `7 L5 C
request structure. ( O' Y ?0 T" L1 S" |
This recipe illustrates several related concepts together, which are how to get a set
# X( [3 I" N/ c0 ]- I5 j1 m$ cof Items from an Item and how to iterate over the set, plus how to get the related
$ M2 `* I# P% A7 e* ^Item from the relationship Item.
- d2 Z S! L- D0 R! b" ]5 P$ _JavaScript
( {# q$ m' Q9 G- v# a. _$ hvar innovator = this.newInnovator();
3 T \4 Y" `5 q$ c
+ A E. O' ~, s5 T; g2 [// Set up the query Item.
) V6 G- |/ L% N3 a( cvar qryItem = this.newItem("Part","get"); - C9 E8 _. }! B. c0 z
qryItem.setAttribute("select","item_number,description,cost"); 9 s* l" U2 { `6 x
qryItem.setID(myId);
3 ^0 T& z; |9 ?' @" _0 F1 _/ V) V ) q2 B9 Z- O" d; \8 l3 O0 x
// Add the BOM structure.
! w: p) r U; y# Pvar bomItem = this.newItem("Part BOM","get"); - }1 b! A" R" t8 x4 ]- J0 n
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ' r N. K( p; z; A' t3 n V$ Y
qryItem.addRelationship(bomItem); , `/ G6 Z0 M1 L) h$ d) t: ]
; V6 \2 \$ ^! I$ c
// Perform the query. 1 _: t' Q# V% J% j- c
var results = qryItem.apply();
+ g) B u/ ^( N% L 6 {& A5 Y: I- _/ f. k( u% f
// Test for an error.
8 c: B) F! n4 p% _7 zif (results.isError()) {
6 y. \' x& @- u5 y6 y top.aras.AlertError("Item not found: " + results.getErrorDetail()); # @7 ]9 t) U+ D L9 |0 U
return;
5 [ p i! E/ a4 O& g} % {, V) [" w9 Y3 t% ~3 z
k+ h7 X5 a! a
// Get a handle to the BOM Items.
) g" m6 m0 S! q! |/ M+ Fvar bomItems = results.getRelationships();
9 `0 N. W/ w2 P& F4 ^" B$ W. N* H. gvar count = bomItems.getItemCount(); S9 b/ [5 |; h+ W* L
3 S1 v T/ Z$ W! o: B f
// Create the results content.
& G2 V+ A' [1 x; e: F. l1 m& yvar content = "<table border='1'>" + 9 Z, N" n. d8 H. x0 K
"<tr>" + , @" C: i0 P* s, u9 E" N
"<td>Part Number</td>" + 8 h; P$ S, J4 y2 i( m9 `) w; h# E
"<td>Description</td>" + . ]* A& X; b4 @3 C1 M
"<td>Cost</td>" + 3 m, Y5 I! `& s) i8 X( a- G
"<td>Quantity</td>" +
4 w u5 t# k" Z/ M "</tr>"; ! y- G+ k: ^# d& s* g
( f. }, ~1 K$ L4 l. g, n// Iterate over the BOM Items. 7 G; b% s9 w# Q
for (var i=0; i<count; ++i) 6 N* n& G% c9 V! V! @
{
: `; P" G1 D$ Q0 p5 ?// Get a handle to the relationship Item by index.
& a& m$ x5 v6 h2 U( O) Y5 j; r var bom = bomItems.getItemByIndex(i); " o! R1 y r- ^% t, r1 H; `- V
// Get a handle to the related Item for this relationship Item.
. P, }; D; |# s6 r5 F7 i7 r var bomPart = bom.getRelatedItem();
( i4 s2 @ w' x
6 V( N# z! Q( c& Y% e' ]/ s# m content += "<tr>" +
* k& K$ v' w+ L+ F( L; I! @5 ~ "<td>" + bomPart.getProperty("item_number") + "</td>" +
j7 }% Z m: C7 a' a7 R* _+ { "<td>" + bomPart.getProperty("description") + "</td>" + . A0 j$ r2 `% i+ t- H
"<td>" + bomPart.getProperty("cost") + "</td>" + : p6 P n# N% a: U$ d$ E* ~
"<td>" + bom.getProperty("quantity") + "</td>" +
% P. y& k( }$ H5 K. n! P. b "</tr>"; " b3 [" M% k- J0 K: B
}
( m: O, r3 Q" f( v9 a5 t% _return content + "</table>";' y; F9 S# M4 i' l6 U- I# G+ E
2 x9 B- A' J9 D# q
) u/ g$ h9 [2 F
5 O! F* U4 J/ x3 w: a
4 J! k! X4 m# u9 d
C#
% Z) z- l3 b0 {Innovator innovator = this.newInnovator();
3 t( e" K. V+ i, u9 z
J! B: |) T2 x5 v8 A// Set up the query Item.
q6 I& f* I5 T9 ^- jItem qryItem = this.newItem("Part","get"); 8 |: n- N1 l! \4 f9 E
qryItem.setAttribute("select","item_number,description,cost"); k9 J! {- I4 ]' `0 w& ^
qryItem.setID(myId); 6 x% S5 {& |/ I, F$ M3 Q$ S8 R6 w
( ?: T# b3 x6 x// Add the BOM structure.
% P! B- {( I* k5 u# AItem bomItem = this.newItem("Part BOM","get"); ) }% h: B) g9 O0 ?+ I1 k' Z
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); + x( c$ e H! F7 F7 E6 C0 e
qryItem.addRelationship(bomItem); " w/ Q. W0 F" f+ p x$ j5 D
# T9 A7 ~- e3 X( A" t// Perform the query.
/ g8 Z/ j5 i( @9 D6 d6 ^- KItem results = qryItem.apply();
% t& @& Z5 S) r: E M- G ) J- [2 r# {7 Z) s6 j7 ~
// Test for an error. ) _7 E8 Z9 v7 U; `3 t) ^& G
if (results.isError()) { 3 e# C8 Q5 ~$ U* K7 ?! U
return innovator.newError("Item not found: " + results.getErrorDetail());
+ I; k: _% A3 L" z}
9 Y. T" m7 \) a
' S0 t0 [4 J* L0 ^( o9 c+ G4 [// Get a handle to the BOM Items.
* N) ]( ^, r1 u8 {8 L, eItem bomItems = results.getRelationships();
5 p$ [- G q a5 Y" P1 pint count = bomItems.getItemCount(); 7 ~. S& {+ D2 ]8 g
int i; 9 q {5 \. P5 ~1 I; q$ j- L6 y& ^ t
- }. o% ]* Z# `! i9 ?7 o( O0 x; `/ ?// Create the results content. # D; k- Q- } g4 E% v
string content = "<table border='1'>" + F+ s* ]% G v4 {/ \6 |6 T. ~! g; K# }
"<tr>" + 3 J& h* v( S; T, o
"<td>Part Number</td>" +
, q4 | v. D% C/ X" w: [7 Z "<td>Description</td>" +
+ o9 F( Z6 j8 W+ ]: z' f v8 } "<td>Cost</td>" +
0 {1 S' q7 h' s+ n; V "<td>Quantity</td>" +
* S1 T9 U1 ]+ z4 _; k "</tr>"; - X3 o% j. E' C7 }3 `* {% d
& i' U! P, m( l2 d8 n
// Iterate over the BOM Items. - M7 W8 C2 c" _! N7 `2 F' D
for (i=0; i<count; ++i)
8 T6 V7 Y; ]9 v' S% O3 C4 A{
/ O$ X0 _- g5 D1 ` y// Get a handle to the relationship Item by index.
) J# B4 E( a. K2 R$ d+ `+ N Item bom = bomItems.getItemByIndex(i);
; N& B: ^0 ~* f0 C! q L: n// Get a handle to the related Item for this relationship Item. ; o, D& v& {! E/ n9 X: A
Item bomPart = bom.getRelatedItem();
' \+ y6 b L6 @. E0 ]- N, a 2 l+ W) p( h" @( c5 Q( X* ?/ H
content += "" +
5 q* A! A* j- m/ K "<tr>" + / J3 c7 Q; F, B" H
"<td>" + bomPart.getProperty("item_number") + "</td>" +
2 @) K- J3 H3 ^- z& Q" O$ ~ "<td>" + bomPart.getProperty("description") + "</td>" +
. i0 u d1 _0 C" c( N "<td>" + bomPart.getProperty("cost") + "</td>" +
0 Z; w# F, |' c% x) h2 _' `5 q1 G "<td>" + bom.getProperty("quantity") + "</td>" +
& W" q- }) @9 B/ W! Z; r" u- F/ q "</tr>"; 6 T( x2 T% y9 o( g
}
2 Z+ r, T& j6 v& a8 Y% N9 I( Icontent += "</table>"; + Q8 M$ r0 l' i9 Q ~
" ~* \3 z4 k6 W# F& T1 @
return innovator.newResult(content);
$ ~7 p4 w9 ]; v" @ N% \2 [8 W, J% Q( p/ i7 p3 b
2 ~, B5 s/ E8 H: T" z
. t) o2 l: c: `* W' h
9 [+ [% y9 o. m4 G9 t+ c, M, D# f' z$ A# ~( F. a/ M
, n1 [7 \& c- W) l+ C& l
8 q5 z: f( M+ [' {7 x Page 46
5 q$ G8 P3 f3 R4 \% T" z8 h
, Z+ S; n; @/ P1 |) m. i4 i, w' xCopyright 2007
( d( r0 V0 \* `: a8 L& `Aras Corporation. 5 j5 D, G% C: Q' ~
All Rights Reserved.
" }, s1 _( t$ q" z1 C/ @& EVB.Net
u Q% z& _. |Dim innovator As Innovator = Me.newInnovator()
! ?* w, j: d( I* X3 z7 p# I1 k$ l
8 w+ |- F2 @5 l T3 ]' Set up the query Item. . t+ b% S: f1 w; `3 r
Dim qryItem As Item = Me.newItem("Part","get") g! C! q$ j. f
qryItem.setAttribute("select","item_number,description,cost") 1 a; c7 o0 U8 _% z
qryItem.setID(myId) ! k9 R+ G6 Z' Z. |& T$ `( ^
Z' \! }6 o" O' j' Add the BOM structure.
: t, _3 o- E" }) I+ oDim bomItem As Item = Me.newItem("Part BOM","get") 9 q; C$ J- z7 ^
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") / L; T W5 {4 I; `
qryItem.addRelationship(bomItem) 3 }+ B/ i- U. O/ U6 x, r
& R) K. C& y! s! I
' Perform the query.
" S8 a6 D8 N1 j g k/ vDim results As Item = qryItem.apply()
' |' _$ [/ P( K, J v- l( m R# h/ G3 x% C4 v, B
' Test for an error.
+ }: ?1 A" J JIf results.isError() Then
# ^: M( x+ D7 [0 T* g+ H& q: W Return innovator.newError(results.getErrorDetail())
2 k* \4 t' ^8 y2 G, hEnd If
3 ~- E/ C4 n9 Q2 S 6 l* n, B1 b' g9 u
' Get a handle to the BOM Items.
9 ]+ N% b a5 @2 z$ a" r2 CDim bomItems As Item = results.getRelationships()
2 b4 b+ |9 d+ D/ fDim count As Integer = bomItems.getItemCount() ' t0 S: j9 I& U I" \& C# y) Z
Dim i As Integer
8 S w! n! ^3 K7 M3 { Z 8 ~6 E% Q. O$ y3 Y P/ l+ j
' Create the results content.
. T! u' u" ?0 V5 f0 ]/ F, HDim content As String = "<table border='1'>" + _ ' |6 x# y) {, g
"<tr>" + _
3 @2 `" w% a" d S3 c7 k: M: h "<td>Part Number</td>" + _
* W2 Y% B8 {! Z$ n "<td>Description</td>" + _
0 `2 C- }* o7 {) {3 A "<td>Cost</td>" + _
, d) @; V6 _& S1 R "<td>Quantity</td>" + _
( N4 s1 q+ K$ Y) Y- n( R5 u T "</tr>"
. X1 S1 V+ Q" [$ I5 u
7 J* r3 O: q/ Y/ G. g7 E% d' Iterate over the BOM Items
+ x* S( Y" j) m2 Z2 LFor i = 0 To count - 1 ( {+ S# n `; P) e
' Get a handle to the relationship Item by index. 6 \7 {$ u, v6 L/ N7 q
Dim bom As Item = bomItems.getItemByIndex(i) ) G' [9 q' ~& Z- L' H# S
R7 Q( o. p3 ?7 r# N9 |
' Get a handle to the related Item for this relationship Item.
; E' ?/ l$ r& n8 y3 y Dim bomPart As Item = bom.getRelatedItem()
4 t6 E; T! Z F7 k# |5 D9 p ; u3 ] c3 O1 b3 b' u ~6 C
content += _ 5 [/ W# Y- [% J8 W
"<tr>" + _ 9 g- P1 ?- z4 L! r2 Q3 t6 g+ E0 \
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
- W8 B0 E1 E) q( o/ C2 d "<td>" + bomPart.getProperty("description") + "</td>" + _ 4 V% H4 D+ Q9 I
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ; {8 u# K$ f4 ~+ C' g3 q
"<td>" + bom.getProperty("quantity") + "</td>" + _
4 h4 f4 G. h, o- T/ C P* a "</tr>"
, A. ^/ `1 Y% y) [- QNext / P/ @+ \* E# g r! s( l
content += "</table>"
) s9 @2 X" m$ L
) a/ ^6 F2 C6 e/ d" x* A/ CReturn innovator.newResult(content) $ |% A/ ]1 x0 p; H7 G
/ S; x9 }! u Y, p$ b' f
|
|