|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
Y; L. {" }# @To query for an Item and retrieve its structure you build the query as the structure
v7 K0 \, ~/ oyou want returned. Use the IOM methods to add the relationships you want and
$ o& c- Q, Y) m; F0 pbuild the structure in the Item. The server will return the structure that follows the - i5 n; z" Q* M% h" U0 I4 h v4 [
request structure. 3 F# x2 T* V+ m9 J7 h U
This recipe illustrates several related concepts together, which are how to get a set
$ J+ W1 c3 n4 u5 Y) Kof Items from an Item and how to iterate over the set, plus how to get the related
0 v. s; j: Z; g# }. T9 Z* mItem from the relationship Item.
" K" Y5 c2 d1 |# T# e/ Z B- ^JavaScript
c( w! n2 }1 }: A( gvar innovator = this.newInnovator();
# e: C" A8 ^" n) E% j3 `3 V O 6 p5 V6 B2 Y8 _
// Set up the query Item. 7 |; p0 ?* F! e2 {; E1 b
var qryItem = this.newItem("Part","get");
; ~9 Z. I" a# J8 z, _5 b8 HqryItem.setAttribute("select","item_number,description,cost"); ' e( w* k3 L) M: x q, b3 c
qryItem.setID(myId);
{+ F" a! f; F( t0 f% P
* Y0 f' o) L" }- s) d// Add the BOM structure.
( W3 y+ Z5 W: Avar bomItem = this.newItem("Part BOM","get"); ' _. G' l% t( y8 I! g. D9 G
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 8 {* g% V7 D6 c6 d' F
qryItem.addRelationship(bomItem); / Y0 | ~5 a% d; _
' j* |0 W P! j- P, M# R* i
// Perform the query. 5 I V( T! e" \; g5 G
var results = qryItem.apply(); # P v( E% ]+ e O( u* _, j4 f
) \3 V; d' f6 ]6 D0 I
// Test for an error.
/ v3 s% ?" l5 b& q4 o4 @! Rif (results.isError()) { 1 A2 w. l, W% X2 L5 B
top.aras.AlertError("Item not found: " + results.getErrorDetail());
* r+ p1 f3 K7 W return;
) S5 }4 l* Z( x; q6 p8 J# i} ; e0 g: u" G7 I$ K5 |
" Z) O) m, {+ }* D; M
// Get a handle to the BOM Items. 5 h. K& r2 E+ |6 h. o
var bomItems = results.getRelationships(); 5 }1 G* M! w r5 r1 R( b( T" ~" ?
var count = bomItems.getItemCount();
6 a) R* I1 K, Y' L+ Q6 ^$ O & W: ~; \1 {* ^/ T
// Create the results content. , M/ k6 R! U4 R4 X) {" B
var content = "<table border='1'>" +
: g& m- L0 l5 j4 ^ "<tr>" + , {8 ?$ ?- c* D- c' ~" ~
"<td>Part Number</td>" +
- p5 F% u' P/ h( x0 A: z "<td>Description</td>" +
9 b: s- b! b: g% F1 o9 d5 \4 A4 t- q "<td>Cost</td>" +
: d X& U. B& j) k( G "<td>Quantity</td>" + 9 d) i$ e2 c6 B0 ?6 A+ J
"</tr>"; " n9 |# P1 X. g' ~& i3 t. O8 O+ ~
1 l- k( m7 W& t6 b. v1 y f// Iterate over the BOM Items.
( m/ J" ^3 |5 G) I2 _& Bfor (var i=0; i<count; ++i)
; U R2 Q" W+ B @8 t{
! Q3 D+ ^1 B# r! \2 s6 z2 m" @& y// Get a handle to the relationship Item by index. + T9 M3 T& ?( N
var bom = bomItems.getItemByIndex(i); + J/ ?+ S0 q+ J9 u
// Get a handle to the related Item for this relationship Item. J; V4 S P$ G# N- U8 \& o/ v+ s
var bomPart = bom.getRelatedItem();
/ U( ^0 x2 |8 D1 N) i( j6 X4 d$ G
( ~. V& U* a: U7 G0 N6 j content += "<tr>" + / N% t: E" S7 \, I. |! G8 H: U, n! m4 `
"<td>" + bomPart.getProperty("item_number") + "</td>" + 2 z. ^6 u1 V8 W! B7 ~- `8 g* _4 }
"<td>" + bomPart.getProperty("description") + "</td>" +
0 ~' N. W, f1 h5 `& b "<td>" + bomPart.getProperty("cost") + "</td>" +
4 _3 h4 F+ d9 p( { "<td>" + bom.getProperty("quantity") + "</td>" + ) H/ j$ o. u8 T
"</tr>"; ; J/ f6 W) z5 N' y g0 S& v Y
} ) {3 \$ b; k: ~5 w" l" x# K
return content + "</table>";
5 g3 I5 j! y7 ^' ~- K/ i- B) i
p; T: H q% O- C! g$ Q2 I5 W% h+ ~0 B. a6 k# N$ u1 F
2 Y% h" j$ \3 @9 I
5 i% ]' y4 g# \* V+ o3 h7 J7 b4 GC#
% p4 E+ `3 ^& H ~7 Y* n% qInnovator innovator = this.newInnovator();
; [1 W6 {: R( R" W8 ?/ T. ]
+ E9 [% m9 p; l2 X Z4 C// Set up the query Item. & ~, u: {) k+ e5 E8 f* u
Item qryItem = this.newItem("Part","get"); $ R4 ^$ O* U( [; b: b
qryItem.setAttribute("select","item_number,description,cost"); & x5 R ^: \+ {2 I
qryItem.setID(myId);
& ^7 t6 n1 a, l8 ~( @
' K, m3 V3 T% U- q" P// Add the BOM structure. # z# R2 S) T) S# f
Item bomItem = this.newItem("Part BOM","get");
7 J8 U6 n( t5 sbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
0 c- P J: t) S$ {9 C% I" JqryItem.addRelationship(bomItem);
. x( p6 h8 ^& `% C: o( v9 n
1 c! X+ r4 O" @* j7 ?$ `- S9 y1 e \// Perform the query. & m; s. t, r, W5 v% {
Item results = qryItem.apply();
' J( r8 ~& C- @( ]/ X" v* }* P b
R2 m# p% J" G3 e// Test for an error. 9 c0 F' l4 Y* T- w/ N. _& j
if (results.isError()) {
6 D/ `! }1 m3 g: b- X return innovator.newError("Item not found: " + results.getErrorDetail()); 1 E- Q) {" R7 ^ U/ v- t" J/ _
} / L' O5 [ M8 U7 j) Z/ F
# J( o& w2 Q% p* V
// Get a handle to the BOM Items.
; ^0 m6 g. I4 a9 BItem bomItems = results.getRelationships(); 8 \; @; x8 Z" ]* |; E
int count = bomItems.getItemCount();
' ]& ~$ K) ]* I- j9 L1 R: bint i;
+ h- l# R9 s$ C0 {. b) t
1 f) C+ \7 I$ L$ L5 D// Create the results content.
8 |) m4 x1 S( S9 p- r `0 x5 mstring content = "<table border='1'>" +
( T, P7 h8 p, T$ X2 o4 q "<tr>" +
" D0 m0 W, D0 m0 @, \: I- @5 I& h+ j "<td>Part Number</td>" +
( ~2 u3 x" k1 `* b' v "<td>Description</td>" +
; n! ~# p' F8 b( W# @7 R9 t* a( u "<td>Cost</td>" + 9 i9 o3 @/ m+ U# `: }
"<td>Quantity</td>" +
9 K7 B/ w3 z9 M6 Z. b* m* L "</tr>"; : v0 m$ v+ L9 d$ ` K
5 s+ }% r8 ?3 _% c2 y& h6 ~& [// Iterate over the BOM Items.
4 l/ N- f. a8 e9 j/ B. Yfor (i=0; i<count; ++i)
9 _ o( r+ `* J% W. H3 D' K: C{
- A0 D% R/ l$ g! q0 {5 K// Get a handle to the relationship Item by index. 8 d. Y7 ]" m7 j* a5 j+ r
Item bom = bomItems.getItemByIndex(i);
" G/ K8 L) s6 i7 x: {" y: j$ r// Get a handle to the related Item for this relationship Item. 7 {7 I7 E$ G! X( h7 ?
Item bomPart = bom.getRelatedItem();
6 R' d x' A% G. B
! L$ u8 g* `2 { content += "" +
+ C. i! c$ g! ^5 r5 E% F6 J8 t "<tr>" +
1 O0 i. g& N, X1 V "<td>" + bomPart.getProperty("item_number") + "</td>" + 3 J# v4 U6 i0 Z1 B) V, k5 a6 b
"<td>" + bomPart.getProperty("description") + "</td>" + 2 w; R3 n0 T* U1 s$ p+ T
"<td>" + bomPart.getProperty("cost") + "</td>" + 1 m8 n: K4 y- d' J6 o
"<td>" + bom.getProperty("quantity") + "</td>" +
! b4 R# h( w, F. b4 U# x "</tr>";
: U8 Q/ {- I2 V2 G$ P} ) x6 p. [0 H$ F/ j
content += "</table>";
2 T( n9 E" [" l w; B 4 h& b* @+ p1 _7 m6 f% T
return innovator.newResult(content);
( X/ O6 w+ V! `+ v w& V/ T% K
. o7 i4 b/ k% R& {2 Y/ \
5 M r$ @+ K% [2 K3 s( E1 ^+ O* b" ]: U
* w# b9 \: G& H. t8 U! V9 O4 Q/ o+ T
, F( l& ^; V1 W- l9 a2 q* I & E$ i3 m" ]- ^+ K0 o. Q
Page 46 & d6 b$ n6 E# P) b1 {
1 E# ~& P& E* }Copyright 2007 # B1 b7 D3 u5 g- B1 r5 N0 R
Aras Corporation.
4 u. A! }. t% c* d( y6 a7 {All Rights Reserved. & B. P: K( B9 L0 s( s
VB.Net
5 H& _9 N: ]7 g5 y7 z$ ADim innovator As Innovator = Me.newInnovator() 5 Q ~0 C# W5 v, {% X: c3 B0 \
# V2 E9 \$ H. \! U. L8 t* r
' Set up the query Item. ) n0 ]' q6 m7 d \ k
Dim qryItem As Item = Me.newItem("Part","get")
* V* g( r ~) Z$ BqryItem.setAttribute("select","item_number,description,cost") 3 u' e2 y" _: ] i
qryItem.setID(myId)
/ B8 `3 C# J3 a) W
" T% a9 w8 N8 V' Add the BOM structure. r B# f/ J; ]- x
Dim bomItem As Item = Me.newItem("Part BOM","get")
& s0 }( r& S! dbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
) a2 j! z5 L% [qryItem.addRelationship(bomItem)
$ @4 V2 L( Q5 j ; r9 R6 g \; y# {
' Perform the query.
2 O) \' P9 ]4 U6 t! ^/ vDim results As Item = qryItem.apply() ~# @- Y' m3 v1 f+ x1 u5 c5 Q( m
9 [' [! W3 b+ P3 z, [. z
' Test for an error.
: ^8 @! Y7 N& r+ xIf results.isError() Then # d7 w' H4 G7 a A9 ^5 \
Return innovator.newError(results.getErrorDetail())
6 Z3 ~6 l1 f! N; f3 Y* IEnd If 8 b" f& x: q7 \; M% S: G
- V; T+ W; h+ J, p
' Get a handle to the BOM Items. % q) v0 i. w& z: `$ N6 Y
Dim bomItems As Item = results.getRelationships()
0 I) G2 s( q" \6 RDim count As Integer = bomItems.getItemCount() ) n( K* B) N K% @) n8 g# d
Dim i As Integer ; \ s2 n) A+ F" J6 D% E
9 Z n' A0 x5 ?1 j* S; s; O, f' Create the results content. " B! K' [# l7 m. W8 K5 a0 Y
Dim content As String = "<table border='1'>" + _ 8 f& B" P, {: ~2 k. F& E- F
"<tr>" + _ - J+ Z, N( m* B; W* ~$ I$ R; O
"<td>Part Number</td>" + _ ' `: ^- ^. F3 V$ u1 V
"<td>Description</td>" + _
! L5 b* p* m6 c# }- C( V "<td>Cost</td>" + _ 2 b! N" @7 z% W5 g$ P `
"<td>Quantity</td>" + _
! B [* ~( ~3 `4 h. E "</tr>" ' O1 N8 }, U+ y0 t( v
0 N( y. M& v% P3 I% y4 u$ N' @ _
' Iterate over the BOM Items 5 Q5 Y% m- I; g4 }" Q
For i = 0 To count - 1 . O$ F$ {: |+ `+ P8 S4 }
' Get a handle to the relationship Item by index. 7 F8 Q# W6 J. x3 ?0 ~) `2 c; @% g6 Z8 J
Dim bom As Item = bomItems.getItemByIndex(i) , q, `/ E% n' U7 U! y' Y
% H- ~5 d! ~* d8 P0 Y) u! e# y
' Get a handle to the related Item for this relationship Item.
* n) `2 O8 g, M; K4 `, k0 ~ Dim bomPart As Item = bom.getRelatedItem() 4 C. V" `9 R& P
' [) @# C f7 w H content += _ ) W+ M) U7 C9 F5 v8 i
"<tr>" + _
" ^( b- p$ f. \- Z: @ "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 7 {4 o/ a) x% O9 F
"<td>" + bomPart.getProperty("description") + "</td>" + _ 9 K' m8 o% t& s) m: }& T. y9 P& P1 Z
"<td>" + bomPart.getProperty("cost") + "</td>" + _ / L1 ] g& x. K: u( R+ W3 n3 E
"<td>" + bom.getProperty("quantity") + "</td>" + _
6 g6 k+ }. V; p3 R "</tr>"
5 T6 |# l& p/ @ qNext
9 b2 R1 O5 D& g7 O4 ?- `content += "</table>" 0 Y a$ j! t' K+ J! F4 {! h: ?
$ c( _8 v& t8 T2 n2 l# g4 TReturn innovator.newResult(content)
9 n9 ~4 }( r( U7 W# k4 y8 ^9 Q4 j z
+ a# C3 @. O7 B- J1 { |
|