|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ; H5 @) Y# Q# |; y) H
To query for an Item and retrieve its structure you build the query as the structure # f+ k* T" D' E6 h, n; J( [
you want returned. Use the IOM methods to add the relationships you want and
8 { C. j8 p6 ]0 r% e! C% {build the structure in the Item. The server will return the structure that follows the
( [* }' [* J: F% h6 x4 Orequest structure.
H8 i: l7 _7 v3 W" E M% bThis recipe illustrates several related concepts together, which are how to get a set % ^; j5 ~; |) s Q- S/ }0 s6 v) c
of Items from an Item and how to iterate over the set, plus how to get the related
9 O) @ m' u& O0 j, {. V c. ~Item from the relationship Item.
; W) e* B; |" UJavaScript
* H3 n' l5 @! b% q9 @& j: n$ E6 V; uvar innovator = this.newInnovator(); 9 `/ m* U! g$ }# U
6 m9 _) M% b* M% W// Set up the query Item. " p" l2 z# B, Y. U7 F
var qryItem = this.newItem("Part","get"); ' `! D' p; B+ p0 f6 i4 O
qryItem.setAttribute("select","item_number,description,cost");
; g- j# |) L3 y" r; Y6 D) y, qqryItem.setID(myId);
# n5 Y0 ?; v( b' h8 y& E 7 c; I' U/ {4 @7 g! u) c/ ^7 T
// Add the BOM structure.
! r: ]8 e" r7 V% x: d- H8 P; ivar bomItem = this.newItem("Part BOM","get");
& O) `6 l$ F+ e* S& f2 jbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 6 R+ Q, f( `: e2 }- E |/ _4 ~
qryItem.addRelationship(bomItem); 3 I6 ~; a, @ ?3 f$ O
* V" M, s' @% v8 D) A. s! [# r% D// Perform the query.
% L# R2 q$ i2 O6 i p4 pvar results = qryItem.apply();
$ _4 `( Q: w8 o9 l
1 D$ V1 k) e7 a( }% ~' F' W- f// Test for an error.
0 y0 h9 ]: f- H# _if (results.isError()) {
! Q; f% v; N+ W, ~ top.aras.AlertError("Item not found: " + results.getErrorDetail());
' @4 B& y$ I$ U5 L5 {6 V+ ]: Q return; 8 H8 ^/ t/ O/ [
}
$ H6 n+ t7 y3 Y( u- |6 Q' F
( f+ Z1 l9 q* x; u9 W% Z3 J// Get a handle to the BOM Items.
' @: I0 D" j7 j. T" P/ R; m+ L& ~var bomItems = results.getRelationships();
9 ]- ~( [* l6 s. |var count = bomItems.getItemCount();
8 v0 p# P2 ^; ?- B3 i/ v ) q- I7 d4 U. o4 z; P
// Create the results content.
: K/ O/ \3 `! d# Xvar content = "<table border='1'>" +
/ I8 C9 a, f0 n$ a "<tr>" +
; A+ E7 y+ d# @, `! i: F "<td>Part Number</td>" +
% [! `9 d( h# y/ X g8 i "<td>Description</td>" + ; X K# P' Z( l" I3 E; f0 Q) o
"<td>Cost</td>" + g: {" E) ?5 `, J4 `
"<td>Quantity</td>" +
9 l; `) [+ }- d/ {" v "</tr>"; - _6 H& w- M" M' O! E( u
1 X+ R( v/ h, L, t# o// Iterate over the BOM Items.
+ O1 [# ]; a- Z, Cfor (var i=0; i<count; ++i)
; w2 @& x: ^) J9 ~! x6 R0 P/ S. j{
2 }& H- l% Y0 b& L* r+ n! i// Get a handle to the relationship Item by index. % X: S0 e4 I: U. U$ l- ^( d/ R
var bom = bomItems.getItemByIndex(i); ' d* p2 H9 \& a/ Q- @( R0 k
// Get a handle to the related Item for this relationship Item.
8 s4 [" i5 n% _* I7 d var bomPart = bom.getRelatedItem();
, G! ?* v# N0 |$ k; X; H' b 7 N2 D$ }. Z3 T, F- w# {/ Y H8 p
content += "<tr>" + 3 ] ~/ ?/ a$ ^
"<td>" + bomPart.getProperty("item_number") + "</td>" +
8 z" w8 |- Z' z/ ^9 D2 K& \7 T9 R "<td>" + bomPart.getProperty("description") + "</td>" + 2 }) W0 n+ h7 ?. N* k
"<td>" + bomPart.getProperty("cost") + "</td>" +
$ F3 c. s) b2 n8 L- z9 Q "<td>" + bom.getProperty("quantity") + "</td>" +
5 w# C" s; e/ E "</tr>"; ' [" \0 _' x }! a2 `
}
! g, D, I2 n' i: Y7 n2 Jreturn content + "</table>";
1 l# V$ P7 y' w" Z3 P: ]
( N' E; J0 {- s5 {/ E i; h. T4 V! I
% c% y7 ?. {' Q8 Z9 d& h- l! V
& F V5 d. r5 n2 {/ |& W( q! sC#
" I7 @1 h4 V, V0 r9 CInnovator innovator = this.newInnovator();
, m( I' o& z. { c8 O- A, P7 Y$ b
/ R2 `/ u- R0 r; {% z8 y# g// Set up the query Item.
8 F* F7 |( v8 f) u5 r) mItem qryItem = this.newItem("Part","get"); * |9 ^$ x" l. t' d
qryItem.setAttribute("select","item_number,description,cost");
4 J* Q# U: a1 Q4 ^6 V. ] s/ U, UqryItem.setID(myId); . y, [8 o8 m' R- |
" O) a! W. G0 V; p5 @* C% G
// Add the BOM structure. 8 ?2 }) c% p5 s3 E! x3 n% k' M
Item bomItem = this.newItem("Part BOM","get");
+ E& ~( {! {3 R$ h7 pbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
9 E9 @8 j5 q! D6 s0 bqryItem.addRelationship(bomItem);
9 ?+ S! Y! W) T( f- t ^# h 6 [4 N9 W" P$ N8 p, V" z/ Y& o, C
// Perform the query. 1 r9 T% Z0 p& ?
Item results = qryItem.apply();
1 J7 d7 W6 i. p4 p k; I o. l" C, ^7 M; g" M, I2 H
// Test for an error. * \6 a% \+ E* c- \* c
if (results.isError()) {
& P! ~# w7 Q6 g8 ~) f return innovator.newError("Item not found: " + results.getErrorDetail()); . R s/ g' E6 f0 k- W+ ~
} 9 V2 V' l- u) u
7 C* n( k, f1 L& K/ q- f// Get a handle to the BOM Items.
9 R, R( E3 f! U+ rItem bomItems = results.getRelationships(); 6 H; }" I/ \$ ?( p7 I
int count = bomItems.getItemCount();
! _+ k i$ S5 i* k3 X ~" Z2 ?int i;
" x; D; k& F; ?- _ ( S' B& U( _. z% K8 f- Y# I9 b
// Create the results content.
2 H2 u' W8 R3 Z2 Z# [# ostring content = "<table border='1'>" + L- R1 {' e+ h1 U: O
"<tr>" + : d5 b1 j# S0 L" H
"<td>Part Number</td>" +
% j# B$ W" w+ d% U7 u "<td>Description</td>" +
& r" |+ A% n3 Y4 d "<td>Cost</td>" +
" d& P, P( \4 [7 ?3 S- } "<td>Quantity</td>" + . n% b) B9 }6 }( D
"</tr>";
+ H% c6 ?+ V- O4 ^- v
6 M) T" |% V t// Iterate over the BOM Items.
- P. c1 ^9 S+ h5 c: P: w% x8 Zfor (i=0; i<count; ++i) . v- X# T# ]) w
{
8 |1 u/ A7 W) H% P// Get a handle to the relationship Item by index. 0 F) T/ j' Q" w3 y! }) k$ L3 P
Item bom = bomItems.getItemByIndex(i);
2 @1 ~+ C8 `, N$ M! U2 ]// Get a handle to the related Item for this relationship Item. * P2 F6 o4 S: e: H+ F
Item bomPart = bom.getRelatedItem(); 3 D3 T. D1 i" N8 \7 D
& p7 [$ k8 [( Q/ n. o! }. G4 F content += "" +
: N9 U! z6 X. c' o* R, Y, o "<tr>" +
) [) b' n% Z6 e9 | "<td>" + bomPart.getProperty("item_number") + "</td>" +
2 G( o {1 f( F5 w7 ~ "<td>" + bomPart.getProperty("description") + "</td>" +
8 O" y" {, U# i& R5 P6 O "<td>" + bomPart.getProperty("cost") + "</td>" +
) o a, z2 v6 [& H7 k "<td>" + bom.getProperty("quantity") + "</td>" +
9 z( y. }, N/ M6 \+ G2 I/ l "</tr>"; 3 Y2 ~$ r! p2 p: A9 `
} 9 A5 U% W2 z6 |/ t0 L. w
content += "</table>";
2 v# n7 Z1 w( J# K2 ^$ {. z: r/ t
1 I$ p8 q4 r8 a+ C$ ^- Q& S) Jreturn innovator.newResult(content); * n; G0 ?3 e' w9 O' X) T
6 M' G0 e4 k0 q# d& Q
& C' x2 i% U8 v( t" ]) K- N4 i
6 {; t3 _+ V1 k- \ }" |1 x; t! u* g' i
) h4 d+ p- F9 ?3 x' P
% }+ ?! [( M. }* i7 N0 v- c9 q' z1 Y2 h1 j- M2 e
2 g4 ?- F+ ]/ m: O; x5 i% E* }! e Page 46 , _5 q' N; m M9 M* R; x+ z
$ n3 T, l* n2 P: R& d1 f9 @* \
Copyright 2007
9 Y+ l8 Y- T" ]1 h1 ]Aras Corporation. % \8 `* R$ ]# Y+ v6 D# I( h) F6 c
All Rights Reserved. ' C5 t, F; J5 U# d- `* M) V3 Z ^
VB.Net 1 v' w/ ^2 D2 ]; b
Dim innovator As Innovator = Me.newInnovator() ! S2 G6 C3 x- V
/ f) _( Y" E/ ^6 w% M5 N% N* U' Set up the query Item. # {; ~' j6 s& A3 _4 }- W2 M
Dim qryItem As Item = Me.newItem("Part","get")
S5 t3 V: d* M4 V2 vqryItem.setAttribute("select","item_number,description,cost") # @# ^0 ] n4 R7 j* y
qryItem.setID(myId) 6 b4 F% @# `) V8 S( i7 R. t7 l
4 g# e2 x2 d/ T. M, J' Add the BOM structure. 6 w6 R3 K& ^+ n" I& s9 R7 C
Dim bomItem As Item = Me.newItem("Part BOM","get") 8 w6 E: X4 r, V6 i- c7 z
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
# S$ ^: d4 u% X N+ W; s4 sqryItem.addRelationship(bomItem)
# {+ R/ z: B& m C2 d T, u8 m) k# W7 N9 ~; F2 Q
' Perform the query. ( g% k1 P2 A% h# D! [9 U6 g% |
Dim results As Item = qryItem.apply()
: J' \$ s+ F' W8 \" Y ' W/ n) Y" _ x+ x7 i6 Q5 Z
' Test for an error.
* A6 k, `, c( {5 SIf results.isError() Then 4 D& J$ G6 s8 W6 d
Return innovator.newError(results.getErrorDetail()) + }' B- T0 \0 U
End If
8 }% ^2 K& \& t0 e$ Q' R7 X0 e * n* m6 n% d0 q3 `* S8 |' \
' Get a handle to the BOM Items.
" ?6 @/ ^7 K& J- `0 H4 Z) bDim bomItems As Item = results.getRelationships()
% K+ R& b& ]0 u! d6 T3 l9 iDim count As Integer = bomItems.getItemCount()
3 r7 ]" E/ P1 ~ f7 B7 i: N4 {; t- ?1 ^Dim i As Integer 2 [: f3 x1 \: R4 O- n3 j
2 E+ c* d6 _" L2 F- G
' Create the results content.
5 G% M# H( u! b; t LDim content As String = "<table border='1'>" + _ 6 l! l0 O( m5 g. q9 Y5 R" D( d5 f. M) ]* F
"<tr>" + _
( ]4 o8 @( H: w3 ` I1 Y$ S: o "<td>Part Number</td>" + _
8 M$ M$ d. n* G$ c, k "<td>Description</td>" + _
1 Y* y: y* ?5 j, U, O: X! s "<td>Cost</td>" + _ ! ^/ T+ \3 x6 f& v* f
"<td>Quantity</td>" + _ 0 ^9 Q5 e' }6 `2 T5 A, P9 K
"</tr>"
9 i: W4 b$ Y8 l' A" H; p
, b: j* @3 J& d; T" W1 D( u" w# `% K' Iterate over the BOM Items 9 @( \# U, H; C. u4 j# M2 o; B+ y
For i = 0 To count - 1 ( K3 r+ R0 c' R& U+ H
' Get a handle to the relationship Item by index. # ]4 u) D) r4 b1 g2 u8 Y9 X9 G, Z
Dim bom As Item = bomItems.getItemByIndex(i) + [& s1 E( X9 j: M4 M
- p! q/ [ _: h5 G( r$ r
' Get a handle to the related Item for this relationship Item. : M& G- t1 H B2 r
Dim bomPart As Item = bom.getRelatedItem()
0 i& B- J( C- {4 N) x' A Y 9 l! X* C5 a; }/ ~5 T1 O: A2 A) k6 E
content += _
, {' V/ W/ |) n+ Q/ C: |! y "<tr>" + _
' t( @1 v" q5 }5 r. j! S6 w6 E; @ "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 4 B! z _! n# X! ]8 V# L& O3 r3 d' M
"<td>" + bomPart.getProperty("description") + "</td>" + _ ( `! @9 [2 ~3 Y; [
"<td>" + bomPart.getProperty("cost") + "</td>" + _ / o3 U* i/ T) U4 u
"<td>" + bom.getProperty("quantity") + "</td>" + _
& l- q5 A+ i8 L, @' K* y "</tr>" 4 {# C% F2 }) F3 D/ d3 r, T1 m
Next , ]4 i, V$ m" h6 G7 ^9 h/ w% b# `8 F
content += "</table>" 5 p" d! R( i2 K" ?& R; q& s' @
; X& _& |( ?; [0 G
Return innovator.newResult(content) ! _# r ^' b+ V2 p# c5 f. g. u
3 q: L q. I. |" E3 X |
|