|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
% Q9 W7 `1 j, |3 pTo query for an Item and retrieve its structure you build the query as the structure
5 u7 R& H4 n! C3 l, L* Lyou want returned. Use the IOM methods to add the relationships you want and
6 G p7 t7 T8 ]& H2 {build the structure in the Item. The server will return the structure that follows the 2 R% j2 R0 Z- z% c4 k2 ]+ {
request structure. . G# m% F' m/ c" `. W' B
This recipe illustrates several related concepts together, which are how to get a set * U6 n7 x8 f* e( ]9 h ~; J3 E
of Items from an Item and how to iterate over the set, plus how to get the related
& {/ o" x% \$ \( NItem from the relationship Item. 4 T6 s, _) ^3 k" C
JavaScript $ `) p5 c) S$ s$ [: T
var innovator = this.newInnovator(); ! X/ [6 R: G9 }0 M& ?
7 S2 j. d$ Y; O% f& _, S/ H/ D! j7 f
// Set up the query Item.
% @4 F2 ]/ J9 ivar qryItem = this.newItem("Part","get");
) ]% }+ A- L% W4 i: _% hqryItem.setAttribute("select","item_number,description,cost"); $ e3 o- J( c8 Y
qryItem.setID(myId);
( S g* I/ u' s0 W _
5 G4 F2 ^* W: e+ E! Q6 E// Add the BOM structure. 2 u4 [; ]! _6 S
var bomItem = this.newItem("Part BOM","get"); / T0 ~9 ]0 `* ]5 A. q
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); , \. t' p' w1 ]! |/ f* d
qryItem.addRelationship(bomItem); 5 |7 K- t& O2 Q# y, S7 s/ s$ T
; Y4 [4 s0 s% h
// Perform the query. 1 [7 ~1 D- L% E% q* _4 r
var results = qryItem.apply(); 6 r1 U# W# d5 i( `+ V/ M
+ u5 k1 F6 g2 R! P8 R// Test for an error. & N, M9 @0 z q% N
if (results.isError()) {
N) J5 J" O. G top.aras.AlertError("Item not found: " + results.getErrorDetail()); 2 j0 }! [& M0 h* X2 G9 R$ V# f
return;
^) |! X# u- _" o6 R} 9 j3 }% N8 F/ q- g7 c7 @
. z# M4 L) U8 L" L' _
// Get a handle to the BOM Items.
" Y" S$ ]5 v9 Z; i9 k z3 fvar bomItems = results.getRelationships();
' [% ]! ^% {1 r. a; Cvar count = bomItems.getItemCount();
" v8 X& E; m7 Q, I9 R) A3 g
* ]- M* {7 O' E' J5 Z& ]) V! s// Create the results content. . V; m3 N+ o z7 @! H/ j
var content = "<table border='1'>" + ' m: j/ ~2 C; w& T2 A0 v
"<tr>" + 5 q+ Y" n9 w0 ]1 }( g! A- r! j; R) x' w3 R
"<td>Part Number</td>" + - D4 a7 S. K7 @: n
"<td>Description</td>" +
4 q: V+ C& k5 B9 G4 ? "<td>Cost</td>" + / b+ t+ e: V; a1 g3 |# P) D
"<td>Quantity</td>" +
6 m: o% z/ z5 P; ~" ]9 r1 B "</tr>"; 2 |* e' X6 U0 L" L! T7 \8 m
7 Y* K( ~( b/ X// Iterate over the BOM Items. $ t. d, F/ J9 w1 p+ B
for (var i=0; i<count; ++i) ; n" o3 L8 q: d) a/ w( u1 z
{
; q- Y6 }0 d4 |5 g// Get a handle to the relationship Item by index. ( u4 f( \- `" R' r3 }/ J7 ~
var bom = bomItems.getItemByIndex(i); ; J! B) u1 t( C5 g: u# D6 S
// Get a handle to the related Item for this relationship Item. . r1 P" g- Q7 [2 f1 U; `# h
var bomPart = bom.getRelatedItem(); / E. I& C( D, C( F6 Y3 s2 V5 ~5 u
" P+ H/ V5 I8 i% s. B: \ content += "<tr>" +
7 f4 n3 r$ L# O3 C& q/ K5 F z "<td>" + bomPart.getProperty("item_number") + "</td>" +
. E, D& r6 G% V "<td>" + bomPart.getProperty("description") + "</td>" +
' j& o) P7 z/ |' H" s$ i "<td>" + bomPart.getProperty("cost") + "</td>" +
8 E, ^: M4 v* q1 E( u$ D "<td>" + bom.getProperty("quantity") + "</td>" +
( J, N1 A6 z( V' v& N2 P, o* p "</tr>";
3 X" S/ G9 }$ G}
, s, e& f. }5 Q2 xreturn content + "</table>";
# W( J% P( T j9 u. w/ ?" Z: `; \5 M
# I6 q9 @/ ?5 n9 C7 B7 E
4 U* Y- q; i+ v" _" @. q3 r/ k
, g6 Q+ `" ` ^' g0 d0 eC#
7 i z% t: c+ K. q' ]" GInnovator innovator = this.newInnovator();
: u, k& B( f. S r
. S- u, _7 G3 s7 p" m$ U// Set up the query Item.
9 u+ b" J W3 X3 e ?Item qryItem = this.newItem("Part","get"); + H) z/ F; O) }9 K9 o P
qryItem.setAttribute("select","item_number,description,cost");
, c% X3 q; |! @. g6 kqryItem.setID(myId); - y4 X' F3 V/ S3 y
' W3 i1 U! \ m% a9 d// Add the BOM structure.
4 `4 M' T+ h/ D, [( R( R1 D. o. gItem bomItem = this.newItem("Part BOM","get"); . X* {5 _$ T, k. r9 A$ y
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
* P* G+ t9 ]- g3 D. S( J; QqryItem.addRelationship(bomItem); H. w6 S/ f% H
$ v4 t; Q) Y6 U* H7 f! H// Perform the query.
: V5 _% l }# i* J; ^" ]6 HItem results = qryItem.apply(); / O) Z( A- I0 |9 \- X) J
% ` }; D0 x; ~: \2 B4 B/ R; }// Test for an error.
* c7 s7 u( o6 a! d1 g% C/ t' Yif (results.isError()) {
/ }1 w! y T. z0 s, g+ W return innovator.newError("Item not found: " + results.getErrorDetail()); ( N. [. p+ s9 c2 r
} " u9 q& m; _' e) [8 @! q
% Y$ B8 U0 C) |( o
// Get a handle to the BOM Items. 9 G5 x* W$ p" q: }- B! H
Item bomItems = results.getRelationships(); / J) H0 x( n" Z0 a3 C
int count = bomItems.getItemCount(); 3 m* N) v6 W% [0 S9 X4 J/ Z
int i; % g% p* h; O7 D* z
. c: G' n! E0 t4 O. D' q
// Create the results content.
5 W3 r! c7 M9 ]+ e* j# U% wstring content = "<table border='1'>" + / I y- p' X5 \$ B% `; o7 Y' N/ g7 V
"<tr>" + 4 L4 A! |+ M5 W% \1 j9 o3 | ^
"<td>Part Number</td>" + ; P& ?7 h' g& n8 G6 Y
"<td>Description</td>" +
# B7 U; O9 F/ A "<td>Cost</td>" +
2 v/ E$ _6 @0 L- i4 j b/ H; ~ "<td>Quantity</td>" + " v& w1 j. h7 j- k# ?9 A8 b
"</tr>"; , n9 {; t1 P C e
/ K7 A( S+ W% [// Iterate over the BOM Items.
/ O q) J% ]' F- U. C$ x: m2 ^for (i=0; i<count; ++i)
+ x, z* G" C1 f y3 _. f{
7 C1 N8 e$ i% y A: a// Get a handle to the relationship Item by index. - z2 u3 w; @2 z; r" R
Item bom = bomItems.getItemByIndex(i); # L, F7 w9 o0 S
// Get a handle to the related Item for this relationship Item. + Q' T7 y6 a) X! t7 N3 P: |
Item bomPart = bom.getRelatedItem();
$ U6 _( l7 `1 x: @$ |9 K
- G9 d7 a- z/ m1 ` content += "" +
: Y6 U" i0 k6 z0 f [$ b "<tr>" +
7 G7 L. e! g0 @, Z+ ^. e. j' Y "<td>" + bomPart.getProperty("item_number") + "</td>" +
% \2 A9 K7 M* w; B7 W( s$ I "<td>" + bomPart.getProperty("description") + "</td>" + 8 k' B! h2 N) B
"<td>" + bomPart.getProperty("cost") + "</td>" +
" T( q; Q/ Y9 n. ` "<td>" + bom.getProperty("quantity") + "</td>" +
6 u; T% ?* k0 ^3 q4 f% {5 B" n: ^ "</tr>"; & o" R! S4 F! _( ]* Z' k0 ?
} 6 s" Q6 F7 P( A! Y4 Q/ ?1 g4 ` y
content += "</table>";
, f3 h' z8 c/ t& u, H
8 I4 w6 _3 P2 zreturn innovator.newResult(content); ( ]5 \, e. P( u% E
. \/ K: W M+ x1 W# o r- @" |. Z" T- N ?3 \
( }* H; m* ~8 ^5 Q
" ~3 Y! f: G l( u& r8 S* I% u) I, V7 F% M8 p6 j0 D
9 Z% r" o% S9 h6 s' T1 y 4 B7 C/ r4 C2 ^ C x2 `
Page 46 7 I- |0 Q1 s" X# ]; W0 v
2 C" ?0 T3 s' u; h
Copyright 2007
S! S6 L/ r1 j- F! TAras Corporation. ( [" ?9 G: `; _$ Q
All Rights Reserved.
% i. z% ]# R! {# h# `VB.Net M& I% a+ j4 |# B- g$ X4 K
Dim innovator As Innovator = Me.newInnovator() " g8 S4 j) o- a' x3 {8 k4 V0 Y
0 @# m- W1 I* u4 n, [. ^
' Set up the query Item. ' h2 Q" R x3 }" ~# v0 e
Dim qryItem As Item = Me.newItem("Part","get")
" B3 ^. t: _+ B( V5 Y/ H- F' lqryItem.setAttribute("select","item_number,description,cost") " P- M* E7 R0 B& \* I3 y( b: @
qryItem.setID(myId) & m: @, v3 O0 n$ g3 y e+ x4 x
8 V5 G9 B$ F& a9 \2 W- U' Add the BOM structure.
6 u' }7 x- A; |/ NDim bomItem As Item = Me.newItem("Part BOM","get") ' F! ^; I. v; b% C' h+ O
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
& u+ B- G0 L. y2 g" `, f* ~qryItem.addRelationship(bomItem) \* U! F; X+ c/ |+ ?
: u. }3 \' P4 }( p& e
' Perform the query.
6 G# j; S Y. ~) w/ dDim results As Item = qryItem.apply()
( C# h- K; t- ]. @( A6 _5 a$ W. W 7 K/ f% x, W) \
' Test for an error. 1 h* e+ U- }* W9 [0 N& }
If results.isError() Then 4 I7 Y, j U) {2 |! F9 O* d
Return innovator.newError(results.getErrorDetail()) 7 w4 Y% N5 J" G
End If
( {4 ^- _0 t2 V) [6 X ( ]6 D1 [* w5 H7 X [: d
' Get a handle to the BOM Items.
+ ]! s: l( O$ N7 \6 C& g# tDim bomItems As Item = results.getRelationships()
* F) I/ U5 u' B' ODim count As Integer = bomItems.getItemCount()
+ _9 H1 a# T& j$ _Dim i As Integer ; g9 j' m9 _/ M* F/ L+ w
' {0 o' P# T* L c3 w0 G( m- B' Create the results content.
# U- m5 m# `# b/ o! {, K/ Z% IDim content As String = "<table border='1'>" + _ / {% m5 g( o' Y" l
"<tr>" + _ 1 W) }( C" Q7 T4 [8 ]
"<td>Part Number</td>" + _ : P1 G6 u a) @2 s- d
"<td>Description</td>" + _
- S Z0 j2 \/ ~( j0 J, a6 i* |6 P "<td>Cost</td>" + _ ' S# b* u/ G0 r
"<td>Quantity</td>" + _
( e0 H2 U' a8 Z% @! d* I "</tr>" : j5 P# D3 O. j0 {! G
* S( w3 R6 |) ]3 K' Iterate over the BOM Items
5 p8 P' Z- A0 E! e2 B8 xFor i = 0 To count - 1 ' x" C8 N) |& U- c( p6 {
' Get a handle to the relationship Item by index. 2 ^7 g8 {8 `4 L9 E3 u: s9 U& w( n) @
Dim bom As Item = bomItems.getItemByIndex(i) + P: t1 b6 B9 |' u& L
, W8 I. z$ e5 F) v7 }/ {
' Get a handle to the related Item for this relationship Item. ( g8 K# a, A/ L6 d8 \9 _1 [# `/ ^
Dim bomPart As Item = bom.getRelatedItem()
% g+ H; z7 R1 A & H! c" L- k$ V2 A
content += _
5 l) z' A+ ]0 T' i% g5 g "<tr>" + _ + \9 q1 M A0 S9 i7 [6 m* {
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ - c( G T) \! i8 n* D
"<td>" + bomPart.getProperty("description") + "</td>" + _ 9 G# I- h5 }% q0 u
"<td>" + bomPart.getProperty("cost") + "</td>" + _
' H: v1 d- h+ y# p# Q1 R; ~ "<td>" + bom.getProperty("quantity") + "</td>" + _
* R9 G5 o! t3 G5 I: g1 R "</tr>" 4 I+ R2 W, H7 P
Next $ z: n' j- R: H! r" y1 `9 J3 g
content += "</table>"
3 D/ ?$ O" a, G( I* d0 I! ^2 y( u
% v" `; [6 W$ h$ e; sReturn innovator.newResult(content) : c/ o3 g" k6 V$ O3 t1 _3 o
4 A6 X8 q" ]6 f, |) L! L4 R |
|