|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ! R6 p7 A$ B2 k- G
To query for an Item and retrieve its structure you build the query as the structure . Y& B9 r' h, u( s8 j
you want returned. Use the IOM methods to add the relationships you want and 7 K; q: T" I) c# E# ~
build the structure in the Item. The server will return the structure that follows the % {% q9 T$ g2 @: `- Z7 ?8 K
request structure. & V0 G" `/ l' Z
This recipe illustrates several related concepts together, which are how to get a set - t5 a- h6 S7 s7 ]
of Items from an Item and how to iterate over the set, plus how to get the related 9 x2 E" ~1 I( f& Z( m" {
Item from the relationship Item. , `* e) e6 p0 P6 g
JavaScript
- s# o6 W9 p# ^5 Z; mvar innovator = this.newInnovator();
* B5 a. g# T; s9 ~2 W
8 ^/ T( t. m/ z; _& ]// Set up the query Item.
& \% n) B% q+ ~% J5 j; Z: u: yvar qryItem = this.newItem("Part","get"); 0 C) @+ _) [) p8 O9 A
qryItem.setAttribute("select","item_number,description,cost");
' n4 C8 k0 { I3 p! E5 q7 W7 @' jqryItem.setID(myId);
2 z% W6 S* C. M' u
4 V, r# e; `$ s7 H. \// Add the BOM structure.
$ |$ Y3 P8 @) Z bvar bomItem = this.newItem("Part BOM","get"); 7 K9 q4 b' S- i9 v% N. Z) I' t$ g
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
5 x# \" @2 P, @) z& s9 y6 vqryItem.addRelationship(bomItem);
% i, D# a* `1 d. m1 u2 S- D" w
3 @) k1 x9 C" c5 |1 _+ i+ a// Perform the query.
* Y6 G" x! X; o% |, n/ C4 Zvar results = qryItem.apply(); ! y) s1 E, t8 }2 h) `! ~3 n. R
) s9 ], i' f; T( z; q) c+ h, c
// Test for an error.
! r9 P# L7 f: p, ]* ~3 z# `if (results.isError()) { # H `' d# \$ z9 L% B& R* @
top.aras.AlertError("Item not found: " + results.getErrorDetail());
1 v, z2 b, @% a" o/ V return; X) F& z$ z) b: t1 ]
} 4 c6 n% W! ?' C+ E9 D- t
& N( f% S% b" |/ A0 e R; D// Get a handle to the BOM Items.
. t: f! y, j: S" T" o9 w8 z0 [var bomItems = results.getRelationships();
, X0 ], a! b7 E8 xvar count = bomItems.getItemCount(); ( n. l( ]+ r/ U- L
) @2 E A) u8 K" o# _
// Create the results content. " ~+ e7 M1 R. t" S5 g! J Y E) t
var content = "<table border='1'>" + ; f3 P) X; f1 L, x1 Q
"<tr>" +
" E P' w" C: d$ L* X "<td>Part Number</td>" + 0 {; Y2 q3 ?! e* [1 e$ ?
"<td>Description</td>" + $ }3 r0 h4 n2 V9 Z+ u7 T
"<td>Cost</td>" +
$ R7 b- L3 U S( x "<td>Quantity</td>" + - r8 W! e" m- c, S9 e5 p
"</tr>";
9 x1 x: j( i: _
* e) _. D4 {+ A" U: T1 P// Iterate over the BOM Items.
% K. f$ M1 g1 Q8 V4 Z3 E0 Qfor (var i=0; i<count; ++i) 6 I& V8 p2 x Y8 g$ h8 ?
{
5 l& P' [+ U) \ D" l6 Y// Get a handle to the relationship Item by index.
4 t6 g, O4 g# C. g var bom = bomItems.getItemByIndex(i);
4 |1 l: f6 y. W: m" ~// Get a handle to the related Item for this relationship Item. `& b! u% Q9 e. C0 M j4 r1 W) z1 @
var bomPart = bom.getRelatedItem(); . ^0 m" r9 K( x4 Y9 [
6 b! G1 |9 A+ }5 z( }/ c, x7 {
content += "<tr>" + , z* A0 k& D' ^% A
"<td>" + bomPart.getProperty("item_number") + "</td>" +
: k2 b$ }1 ^) f7 y( m% R "<td>" + bomPart.getProperty("description") + "</td>" +
/ U* k7 Z" y% [ t1 H "<td>" + bomPart.getProperty("cost") + "</td>" + 8 |; g/ s# ?3 K, \
"<td>" + bom.getProperty("quantity") + "</td>" +
n9 ?5 g: U# n* e: m0 ? "</tr>";
! @8 J& H5 r& R1 L+ m3 O7 K} 8 I- Z! O9 W0 |7 Y: `. p. q% |: }
return content + "</table>";
! D+ b0 @, V) @3 [/ p4 t
1 c+ S- u s7 M9 l
2 a, ]( I0 t/ S7 b" S7 K- y9 N. l' ?8 ~9 G1 v8 q3 L+ J: W
q* o9 n; o. O' L# v
C#
2 V% k y8 P6 D1 [9 t. JInnovator innovator = this.newInnovator();
. A6 d- n9 S& v2 P 4 P, d& y( C5 e' i
// Set up the query Item.
_6 K9 C p% x$ T3 UItem qryItem = this.newItem("Part","get");
2 ^" ]- H A, Q; C [qryItem.setAttribute("select","item_number,description,cost"); # g4 u! i t( Z7 H" T; V
qryItem.setID(myId); % }! [7 ]3 A6 O8 `1 s+ f
1 b9 W- A1 ?4 | K# T6 F' j* j, g// Add the BOM structure.
, O% n5 M! @$ l% Y- k# b0 C" h7 hItem bomItem = this.newItem("Part BOM","get"); 7 k' J- W, |, ?( B- n" V# y
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 2 a0 O z* h. | h* `$ d! q
qryItem.addRelationship(bomItem); 9 z# ~- g: N4 d8 X; y& }% A
" u: V! W; c+ ^// Perform the query.
( Z9 G* n$ V) m; H, r! ^; FItem results = qryItem.apply(); % v, i' s a; c) A0 ^% u* |
) y4 p& Y8 [# H
// Test for an error. 1 ]5 T0 V1 V" F/ f5 E8 N
if (results.isError()) {
5 N& O9 E2 C6 ~# ?8 p3 N% m return innovator.newError("Item not found: " + results.getErrorDetail());
; I% F4 u* ^8 _. {}
$ Y; V% k* u" @6 {1 p 9 J- g& R+ X$ @
// Get a handle to the BOM Items.
+ D, }; Z* c6 N( t* Z- aItem bomItems = results.getRelationships(); / V" A }: Q, @3 F
int count = bomItems.getItemCount();
9 E9 v. a6 \, e7 mint i; % p; S. K4 v2 ~/ M3 E2 H0 A
( O; N7 Y# D( d3 t: K
// Create the results content. : l9 s5 c: I* c n
string content = "<table border='1'>" + & ?* t$ I8 E0 W7 W9 {! k9 U
"<tr>" + , G; _# A3 ~+ @2 P
"<td>Part Number</td>" +
% D5 i2 k* ?- h. |- Y4 ~7 B- U "<td>Description</td>" + , D7 t3 [- x" l* d( E- u
"<td>Cost</td>" + : U, S& [- \8 m. P
"<td>Quantity</td>" + 4 C' {( R/ i3 }9 ~5 `6 G- o
"</tr>"; 7 O; h* O5 u: V) H" Y' a8 _
$ l8 x4 ` [- d4 H! H# h) p
// Iterate over the BOM Items. 3 @# {! n$ \3 [1 S$ {; v: V
for (i=0; i<count; ++i) 0 c6 }. g$ T$ t7 w# Z- p: W. r
{
0 n/ ], v3 w* O9 K// Get a handle to the relationship Item by index. - |4 E4 t0 ]: s* f, N9 t i
Item bom = bomItems.getItemByIndex(i); 6 Y& A0 I2 k) G7 r
// Get a handle to the related Item for this relationship Item.
0 A' A. }! b5 v& n, I Item bomPart = bom.getRelatedItem();
4 e( E6 [" U% Y n( N( B8 G, t' V + s7 K; M0 J% O
content += "" + - m, d: s2 G/ |: D+ M( E, [
"<tr>" + 9 }% t1 m' V& T2 O8 t$ J
"<td>" + bomPart.getProperty("item_number") + "</td>" + & T5 _$ \ @' J, W1 \" Y6 s
"<td>" + bomPart.getProperty("description") + "</td>" +
& W( u' `, }( F" d' A "<td>" + bomPart.getProperty("cost") + "</td>" +
- k: @. K* C6 r. ~# O "<td>" + bom.getProperty("quantity") + "</td>" +
3 N9 e+ s6 ~# L* h. j/ V, L "</tr>"; # F9 G6 y& j! _5 B6 F3 {" h1 K
} & H: s& C& K. X
content += "</table>"; / q% H) h" Q, ^. o
/ Q* k' w6 w) e. ?3 J E) m
return innovator.newResult(content); % _% S8 v: i c
5 @4 ` L9 @/ b5 K0 H5 f
9 K3 x9 i, p' d' k
4 r+ V+ P B, U
' b ]8 O9 @( L% f
) T# t5 j( V9 f2 u. e
- L% G9 y, i# ?4 L y
$ a5 d% C: a( a6 a, k2 @
Page 46 0 ]7 n1 n0 [( j, z% l/ b
% x5 z7 X" `* H8 u
Copyright 2007 x$ _5 }) h" a; x4 G# p
Aras Corporation.
3 B) T$ W' D h/ p, a; @2 UAll Rights Reserved. & H& O t' P% w0 E B$ d0 E, E
VB.Net " n. H6 I" V% N& H+ x1 I
Dim innovator As Innovator = Me.newInnovator()
& a, i% Q) X4 V
7 Q- V$ `2 ^) z+ A' Set up the query Item.
& q- Y. }: ^/ t. n1 Y/ ~6 [2 zDim qryItem As Item = Me.newItem("Part","get") # ^# K g6 G h0 e0 q7 d) p8 [
qryItem.setAttribute("select","item_number,description,cost") 7 M4 ^" t0 Q! B* C$ N
qryItem.setID(myId)
1 O: ^/ s( `5 r. M% I, r ' p: E- z: h# B- {. P$ m& y ?
' Add the BOM structure.
9 e+ K( |4 R( uDim bomItem As Item = Me.newItem("Part BOM","get") / G& l3 G/ V% N6 k& J3 \7 V
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
t; U' T6 S* e# ^6 B" _- XqryItem.addRelationship(bomItem)
6 ^/ T, Z+ L( l; q2 ~6 b! I/ w6 `
" M3 q- P0 d( v8 ~2 N' d% O' Perform the query.
1 g& j$ _! g2 w; KDim results As Item = qryItem.apply() 8 k5 g: E' V0 Z) [* d
, H" S8 M' n" C* g' Test for an error. 4 l( O! P0 s% Z1 A
If results.isError() Then ! @5 ?* _! b: A1 ]4 ]4 y
Return innovator.newError(results.getErrorDetail())
" Y" y# P8 W) v' k+ I0 c/ FEnd If
& b* O6 T! w d- s4 V ( }2 A' L2 u% S6 K) S
' Get a handle to the BOM Items. , F+ C( m- u2 T$ a
Dim bomItems As Item = results.getRelationships() 7 t; Z$ A; P( y( Z
Dim count As Integer = bomItems.getItemCount() & j( r8 Q: h8 b, h, d9 g
Dim i As Integer 3 x; q5 Q, W& h4 g; S, I
; O+ {9 N0 J5 Q' Create the results content.
' z! ~5 x( ?+ NDim content As String = "<table border='1'>" + _ 5 f/ R" k; `: O' d0 y+ m7 @, |% G2 \" C
"<tr>" + _
, J O! p- N. g1 {! N- N3 ~ "<td>Part Number</td>" + _ # b& m& Y; t& R7 ?
"<td>Description</td>" + _
: w) k V. x, z "<td>Cost</td>" + _ ' r# }! u; x: |2 z+ {6 h
"<td>Quantity</td>" + _ 9 V" J9 ~, e$ V6 w7 ~
"</tr>" / d8 p) d4 H, y- k
- d2 w! i3 g/ b1 H5 E
' Iterate over the BOM Items ( E% k9 p8 W/ L; C
For i = 0 To count - 1
& R. a4 h: a2 }; h) S+ r! f' Get a handle to the relationship Item by index.
) Z0 U9 K1 \& k, h& P: g Dim bom As Item = bomItems.getItemByIndex(i)
7 L. E ]/ X* t; ~3 c & k1 C6 b; g r$ Q7 l
' Get a handle to the related Item for this relationship Item.
! ^) I1 a* m1 C/ Z' o Dim bomPart As Item = bom.getRelatedItem()
- f" a% D* x% C a1 l
3 H3 V+ \* x( Q- h2 s content += _
9 Q1 T" Y% c' L x) Y2 [7 G! ] "<tr>" + _ & ]7 @# ]4 W' C& Y* J( i+ x" R
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 4 W& {- N }" O0 C$ N- ?, Z
"<td>" + bomPart.getProperty("description") + "</td>" + _
' U0 R) A! I. o3 z "<td>" + bomPart.getProperty("cost") + "</td>" + _
+ w# V0 O1 n% U/ g, R# l) A* Z "<td>" + bom.getProperty("quantity") + "</td>" + _
0 \" u" y# d" i9 ^& k2 D0 { "</tr>"
4 h4 r) n/ `, x% X: {6 h8 b: @Next
5 c/ W3 U5 J- C& Q; u& v+ Xcontent += "</table>" 5 Y+ r$ I3 o" \* [
~. t0 v% n6 q* J8 S+ V2 g; S/ zReturn innovator.newResult(content) ' h5 ?' |9 V: e
: ^) k# L, {9 N& n |
|