|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique 7 C1 J1 e, }; F" v0 T
To query for an Item and retrieve its structure you build the query as the structure
( [4 X2 _/ @" xyou want returned. Use the IOM methods to add the relationships you want and
1 @" K+ o) Y" wbuild the structure in the Item. The server will return the structure that follows the , F% r4 r3 F& L2 f& m4 |1 `
request structure. 5 ]7 |9 q2 t* Z) {8 {$ V
This recipe illustrates several related concepts together, which are how to get a set
- k/ z* }. {5 Mof Items from an Item and how to iterate over the set, plus how to get the related
* n4 T/ S- O1 TItem from the relationship Item.
6 Q4 K* ~+ U- vJavaScript
1 H+ a+ g! o# ^3 I( mvar innovator = this.newInnovator(); 7 K* S+ z6 D' O i2 b3 Q
# }. R6 y! G4 N1 G/ F5 ]
// Set up the query Item.
" N4 D# m- |5 d2 Q- V0 s. s4 A4 Xvar qryItem = this.newItem("Part","get");
9 f- B" ^/ C7 r4 v9 w7 q) q6 UqryItem.setAttribute("select","item_number,description,cost");
9 E2 ^* D* P' w, RqryItem.setID(myId); " @6 o. j! r" N7 ~; c: E9 v) F9 F
0 b' K2 e7 V& Z2 {. x$ P
// Add the BOM structure. ) P( s9 a9 T0 j& h7 r* E
var bomItem = this.newItem("Part BOM","get");
6 A6 P a* r+ f* \# SbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 6 Q2 |- G" q: R0 |$ m8 r
qryItem.addRelationship(bomItem);
% m7 V/ A0 ~) `. D6 ` ) _% {4 L8 ~. Q- X8 S- g
// Perform the query.
1 k. @/ C; L7 N ^6 R; Mvar results = qryItem.apply();
! g4 e9 @. x: U; v- G
& K( X5 Z% S/ U2 l// Test for an error.
\/ O# m, [! X/ e' m1 A/ R% dif (results.isError()) {
@7 L$ |: K9 M, ^$ G. M& P top.aras.AlertError("Item not found: " + results.getErrorDetail());
# H1 x2 O3 R' l; n return;
0 J; v& l8 s5 a, l& u0 G}
5 E- u K( B( {1 Q* ?
7 Z% O$ S; W6 g+ Z// Get a handle to the BOM Items.
: @7 Q7 I0 |* b' f; ~; P; M! Dvar bomItems = results.getRelationships();
3 F9 Y: Z. T6 t7 |2 r% ]8 W! G) Vvar count = bomItems.getItemCount();
0 X( e$ `; l$ u! ? . L, F) o3 s Y i6 d
// Create the results content. G+ \; I. Y& a& p }9 c5 C6 \
var content = "<table border='1'>" +
! S: \7 E8 p9 K( m& p* D! {/ A "<tr>" +
5 |) p4 Z# |5 ]3 J9 { h "<td>Part Number</td>" + + x; u* H. q; G" J6 _$ e$ ~
"<td>Description</td>" + : C. I# s# d* Y! t
"<td>Cost</td>" + - _$ L1 C/ g* p9 e' w Q
"<td>Quantity</td>" + ! m+ E. O' H8 p$ S$ y
"</tr>"; 4 l4 y8 v, e. I! h. Q
! G% r. y8 }' ?# f, d8 I, x2 T4 I
// Iterate over the BOM Items.
# C/ L$ o/ ^) i0 \1 o @% rfor (var i=0; i<count; ++i) 3 e4 E8 w) H" r0 U( G) y
{ + r# r2 s6 Q3 K5 K) A' f- Y
// Get a handle to the relationship Item by index. 7 J7 [- P/ e' |/ X* y, Z: t
var bom = bomItems.getItemByIndex(i); , Q' M! ^* e; ^0 e/ U7 B: B% J5 | t
// Get a handle to the related Item for this relationship Item. 7 b# g% t3 X0 V* |- i/ y
var bomPart = bom.getRelatedItem(); 9 O! R; r9 c) {, Y4 p
' Q- [& C0 F4 i0 E, w, g/ L# ^8 D7 S
content += "<tr>" +
; b8 R: g+ ^+ ^( [9 i+ G/ N) S: Z "<td>" + bomPart.getProperty("item_number") + "</td>" +
7 S1 }3 D/ T' Q8 _. w" Z "<td>" + bomPart.getProperty("description") + "</td>" +
, G% L: F1 O1 G2 `- p: [ "<td>" + bomPart.getProperty("cost") + "</td>" + $ s8 a2 o9 }$ t# r0 M! U8 l
"<td>" + bom.getProperty("quantity") + "</td>" +
2 R) _7 ?0 |5 y "</tr>"; 0 H+ l) N! D7 C. F( Z
}
5 t6 V/ I/ h* Y1 ], d$ ]4 treturn content + "</table>";% W7 ?* ^+ b- W9 P
7 [0 k3 R3 l) ^6 b8 K# R
% `4 \% }& r$ _$ G& a
6 B" t- P" D4 Q4 L2 L7 X) E0 O9 J* B* q. O; z. ]3 L
C# $ V A! p4 k) c
Innovator innovator = this.newInnovator(); . B9 C W0 E9 o, z
$ W. X5 N) A! ~" Z" i! T. H* a; e
// Set up the query Item. / h) G K3 A. z
Item qryItem = this.newItem("Part","get");
3 X' I, r4 S( `* x$ Q5 lqryItem.setAttribute("select","item_number,description,cost");
8 h0 |' L% z9 _qryItem.setID(myId);
1 X: c0 v/ S4 X; x+ B$ i $ S ?$ u) Y7 i7 d
// Add the BOM structure.
& X/ _6 Q* I! [$ t8 Y6 J) {Item bomItem = this.newItem("Part BOM","get");
" X9 H" Z- ]. V. R, C# ~. Y5 ~bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
" D7 U& }% g- sqryItem.addRelationship(bomItem);
& O4 L0 b! z& N! V6 {+ B+ Q ; `) G/ s; D, |' c. m; R, _
// Perform the query.
2 j2 H2 i1 U0 ~. m3 K0 `% EItem results = qryItem.apply();
8 @7 y p) V# ? C8 X. ]& s) {
x d+ H0 s/ E. C- t// Test for an error.
$ }& x, }. V1 D; q& X5 B9 }if (results.isError()) {
. Q) p, f& ~9 p6 |! r' m1 l$ F return innovator.newError("Item not found: " + results.getErrorDetail()); 1 T$ J/ ^7 I/ f; [
} u6 o1 Z4 G) [! f) Y4 o# F
; C2 p! H' S4 E! p5 V2 o
// Get a handle to the BOM Items.
+ X% B# e3 X% L6 I# hItem bomItems = results.getRelationships();
' |# T) w# k8 q; c7 I6 |6 y' S6 O vint count = bomItems.getItemCount();
) Y3 M: z0 C* l2 l+ T- T cint i;
) N @$ s @' T. ?: G9 H5 P
6 J& T) v- I0 L// Create the results content.
% E0 E# }& \' T5 }' {2 Y' |string content = "<table border='1'>" + # D# h) i X1 [6 Q
"<tr>" + 3 ^+ b1 D6 K; g+ _# m- ^
"<td>Part Number</td>" + / G2 Z( D: o$ J% W+ S: x! Q7 J" a4 x: p- P
"<td>Description</td>" + ! p0 [- W' o: A- }
"<td>Cost</td>" + & @0 W7 a# o/ N, P% I5 |- G
"<td>Quantity</td>" + 2 _. P% S* k, D7 I* e# G
"</tr>";
3 q6 ]/ u9 _4 T
$ q- n3 W- g! a& @0 c9 \// Iterate over the BOM Items.
8 U, K) A/ b0 y# a( I& vfor (i=0; i<count; ++i)
! W# h9 }! S: M! d. Y) C1 F2 b{ 5 l6 O/ ~1 P" ?5 S
// Get a handle to the relationship Item by index. , l$ g" n% E7 L
Item bom = bomItems.getItemByIndex(i); # K# x( Z/ h& r$ b2 P0 O; @
// Get a handle to the related Item for this relationship Item. , @8 |/ \: b0 h. E1 o; j- _3 q
Item bomPart = bom.getRelatedItem();
7 y+ b q4 w( u# t5 g4 z5 c ; R$ R! X2 s6 }4 X7 j
content += "" +
4 M+ l' W& K" P+ } "<tr>" +
, e. u9 U3 ^ C "<td>" + bomPart.getProperty("item_number") + "</td>" +
/ y* e6 c# f% Y& F( E7 Z6 a "<td>" + bomPart.getProperty("description") + "</td>" + & v% u+ O: H3 n5 m3 H
"<td>" + bomPart.getProperty("cost") + "</td>" +
0 e2 \% M; d5 i+ M+ {+ t "<td>" + bom.getProperty("quantity") + "</td>" +
+ b3 l! @; I# m "</tr>"; ( k+ X& q4 c5 x% S0 X! D0 k
}
% c) C6 Y/ n: w6 E2 {content += "</table>"; 2 j3 n- S" l# J2 C; s. p z# Q( x. x
8 v7 [& ` ?( W+ b
return innovator.newResult(content); % a, N/ h& p: O7 \8 s1 s. p
/ b i) N6 [" T7 e
4 c+ O1 p! D4 e; e2 [+ J/ e& w" v
! G" R4 |: a( j# J
( s3 P! S( ^* v8 c1 |, X* N- g: ]. v9 I6 ?) F
! z' y; Y9 N+ l+ W % |2 R! w5 k& N6 X9 |1 ^
Page 46
) h. M$ F$ C, G : p" r v: a3 H I0 R* h r
Copyright 2007 C5 G+ i& d! B4 Z
Aras Corporation. / X2 m: {" V D( \
All Rights Reserved.
' c. k, V5 f3 r5 OVB.Net
& m E# l1 u/ R$ q" h3 FDim innovator As Innovator = Me.newInnovator()
: Y) }! V6 `" ^( Y4 O0 @ C; l1 f/ }/ V
' Set up the query Item. - Q# c) M( a4 c/ W" H
Dim qryItem As Item = Me.newItem("Part","get") * P3 q4 t2 z1 @& k; _; Y' g
qryItem.setAttribute("select","item_number,description,cost") & y; e8 t+ W# t
qryItem.setID(myId)
( g! g/ K, `5 T$ M * I/ O7 h( [" H
' Add the BOM structure. 4 V. K H3 ^' ]- a) ?+ j
Dim bomItem As Item = Me.newItem("Part BOM","get") . L( w; S, i( k& u
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ( ~) k+ Z; b: b$ f% G0 ^' N
qryItem.addRelationship(bomItem)
$ q I! {* H5 L" \% x8 C1 B6 t 1 X: P; p2 ~' z# U
' Perform the query.
" g1 f, v' @% cDim results As Item = qryItem.apply()
3 s" m' W9 Z3 P+ l; s6 y% V # r0 K# J. W4 o4 C9 E
' Test for an error. 6 X/ D' V1 R, [9 w) p2 Z
If results.isError() Then
* u8 _; m# U6 X& v Return innovator.newError(results.getErrorDetail())
P/ E' n1 q1 ^3 @, G5 R3 pEnd If : p. j) i1 L7 U+ t. m
c* q4 F+ A: N! _+ w8 Z% @, r' Get a handle to the BOM Items. 8 [. V$ |! I9 l
Dim bomItems As Item = results.getRelationships() ; {! F- p9 B# F' r
Dim count As Integer = bomItems.getItemCount() 7 e8 Z& r, R( y" ^
Dim i As Integer
% S# M P r8 A: n9 c1 T2 W3 g $ A# w* M4 |& `
' Create the results content.
( A' R: J5 H: u2 }- V6 l- zDim content As String = "<table border='1'>" + _
# v8 I @9 Q/ T "<tr>" + _
, |: g5 C; W G- r "<td>Part Number</td>" + _ / E; o, N _, g! s) [" b6 {$ Z
"<td>Description</td>" + _
; J- B3 F4 `1 D- O e5 S% H "<td>Cost</td>" + _
% {) E J* l% Z, Q5 }! ^: D "<td>Quantity</td>" + _ & W0 Z/ d+ r# ?- R3 `; s- _
"</tr>"
! x9 H+ g4 a8 d4 s+ [& D; h
+ s5 H8 C9 s& v. [' Iterate over the BOM Items
3 S6 p Z0 Y% K2 [! L2 FFor i = 0 To count - 1
# _3 g8 C& \ G1 z' Get a handle to the relationship Item by index. & Z' x+ e5 ?+ y
Dim bom As Item = bomItems.getItemByIndex(i)
' I; s0 |8 b$ h' z6 L# c ( }9 |: w! ~5 [7 s6 X
' Get a handle to the related Item for this relationship Item. 4 M) Q$ \' y9 L7 s
Dim bomPart As Item = bom.getRelatedItem()
# L3 w* `/ b7 W4 N0 T! l6 v5 M( b) g ; Y8 T. t+ S, Z2 c: j
content += _
+ l7 u- C$ N: J+ b4 c) Z: X "<tr>" + _ + _: S7 L) I) g: m% n
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
: I4 v- P% @5 U% U: }+ L D: } "<td>" + bomPart.getProperty("description") + "</td>" + _
$ c; Z+ `3 j0 N5 q1 G "<td>" + bomPart.getProperty("cost") + "</td>" + _
, F: w K; `( O$ m- k! n, d5 |9 r "<td>" + bom.getProperty("quantity") + "</td>" + _
' a7 A4 {! U2 Q* O "</tr>" ; {( E& }/ h+ N) V0 {
Next
( `2 l3 H7 ~ ?5 d lcontent += "</table>" ' A9 n1 C9 B) ]: u( _
$ i& S' A3 P$ Z' b% oReturn innovator.newResult(content)
. n, {: ?, L8 m( ~; \: T( Q4 e9 [9 x0 o8 z4 O
|
|