|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique . [$ M# n1 A( l+ Y- B) l$ N% |
To query for an Item and retrieve its structure you build the query as the structure , o1 b' ~6 u: [$ `9 G, E; H( S$ k$ u
you want returned. Use the IOM methods to add the relationships you want and
: C o, t& }! E1 E7 T% q" Jbuild the structure in the Item. The server will return the structure that follows the
6 g9 I" C V8 X8 U4 erequest structure.
( z8 d7 L8 o/ v. x1 d4 }This recipe illustrates several related concepts together, which are how to get a set % s/ r8 |7 F2 t. s9 D
of Items from an Item and how to iterate over the set, plus how to get the related
x! l+ g- f: |Item from the relationship Item.
( L! T2 h7 _8 }2 T5 n3 Z% ^' r4 LJavaScript
# K( p! v; v4 S6 V! u% Hvar innovator = this.newInnovator(); 0 N9 P3 Z. g7 E6 K' K
+ \4 I! }, `1 J9 a3 C# Y2 ?// Set up the query Item.
$ |$ d2 {+ G0 L* i" @. w# t5 [var qryItem = this.newItem("Part","get");
) U0 a! T1 l" R7 o" r9 c: y- mqryItem.setAttribute("select","item_number,description,cost"); ! v3 _& V0 P. o( t! W8 G+ e6 c
qryItem.setID(myId);
) C( a) Z' S0 i* B2 U , ]& O" t' _( n, {8 ] v" ^0 G
// Add the BOM structure. * N) u4 ?% b1 U3 V* ]2 R
var bomItem = this.newItem("Part BOM","get"); ) H# V/ n# ]* ~( v1 @: I% l
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ' a0 {; g R _7 _
qryItem.addRelationship(bomItem); : \! b( j9 G$ K/ N/ w# i% e
+ L i: `! x5 m. [8 s// Perform the query. 3 c O4 G; ` F8 k
var results = qryItem.apply(); ! w- g) O; u* U7 z' X0 F1 H8 R$ ]7 r
& I# a1 P1 f; L. E1 M2 m// Test for an error. ( Z2 t% x1 \: ?% v2 o
if (results.isError()) { 3 o* `9 j9 p, T8 y W
top.aras.AlertError("Item not found: " + results.getErrorDetail());
( p( g4 [! i0 P9 E* i/ A$ V4 X- F0 { return;
( E. J5 }7 ~2 Z}
\- _, Y8 S( R
- N: g0 r+ d# I. m3 W* ~// Get a handle to the BOM Items.
3 D& O4 A E- `var bomItems = results.getRelationships(); ' M9 a5 e; W+ C; s \6 ?7 R6 M
var count = bomItems.getItemCount(); & }' j- k" |* W! J: t1 i, v
5 {( Z9 p( K" |- o// Create the results content.
6 s8 T4 x7 p$ w9 A+ b! s" N9 Gvar content = "<table border='1'>" + 7 ^2 i' v+ f/ |8 r- I* a" x5 O% m
"<tr>" + ! c9 c F2 d: C' g' V: v
"<td>Part Number</td>" + # ^6 t0 \* G( N8 Y+ t3 q& \# Z z
"<td>Description</td>" +
; G9 j$ J4 P' t2 ~; L+ [. F! t "<td>Cost</td>" + - S1 U; E. }. g/ c+ s/ E$ r
"<td>Quantity</td>" +
5 y) v- K! r' o- B* ]5 l "</tr>";
# Y. ?( k7 n8 A9 K' Y( p) t
" ^, V( E2 H& R4 C// Iterate over the BOM Items.
/ t- Z7 \- W3 Lfor (var i=0; i<count; ++i)
! z0 `- O4 K% T, v4 k! s, P. r) \) v. L{
3 f; t( |& v0 F. \4 Y// Get a handle to the relationship Item by index. - E$ u$ J; d0 U. K
var bom = bomItems.getItemByIndex(i); , Y' o _6 m( ~- E& X$ W
// Get a handle to the related Item for this relationship Item. " X' j$ ~$ i5 x2 l
var bomPart = bom.getRelatedItem();
/ h% [& O5 i7 e: o
; U7 h. w$ c$ l9 p- M; a content += "<tr>" + ; f" B- t! D9 N! T
"<td>" + bomPart.getProperty("item_number") + "</td>" +
. m' [0 a. K6 G) i1 S "<td>" + bomPart.getProperty("description") + "</td>" +
& h( u, e, M4 G$ J3 s7 g+ l5 d) t' q "<td>" + bomPart.getProperty("cost") + "</td>" + # D6 P4 v0 w" P3 w) x+ q1 h
"<td>" + bom.getProperty("quantity") + "</td>" +
1 a9 i b% L# X4 X; T/ I4 E "</tr>";
0 T; f2 ?0 i2 U! q( L} + M$ p; U$ S4 k. h8 V
return content + "</table>";
. H& w- K, L! f8 k( x* W/ l6 j& E- h; g' h
, r- `$ z4 W: I( n1 z3 B0 r
" f5 b( w- C* {
3 P) o8 M7 d; t) A5 X& gC# 8 P8 q8 f( T3 J0 }% b5 B
Innovator innovator = this.newInnovator();
8 ]3 ]$ k: T/ ?- R2 M
F$ P( f; t& d/ ~' {( S' s// Set up the query Item.
$ p9 i; d+ a9 J0 oItem qryItem = this.newItem("Part","get");
5 z6 J( z0 w; h9 g3 ^qryItem.setAttribute("select","item_number,description,cost"); ! J$ N7 D2 C8 Z1 q f3 E: [
qryItem.setID(myId); , H9 i8 c* `2 m' T. a2 ]
" u3 j1 p. d- F: Y; v, u: u
// Add the BOM structure. 2 a* R9 e7 }- P
Item bomItem = this.newItem("Part BOM","get");
! @6 a8 N4 S' u" I/ pbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
5 v* S" N, O1 O, ~qryItem.addRelationship(bomItem); l _* ~$ L: F* ^7 C4 T! r
. X) U' Q( y# s, o; O7 z/ ?// Perform the query.
2 {( g6 L+ V! {4 k3 mItem results = qryItem.apply();
6 J/ J, b, S. r5 X* S
5 f7 M& v6 K3 A$ X; c// Test for an error. * ?; I! }2 K3 H ]
if (results.isError()) { 8 P5 D; x" {4 D
return innovator.newError("Item not found: " + results.getErrorDetail());
* v) ]5 o( M. i! f& z9 V}
0 l3 Y/ m% l- |( n: C; c2 f2 X4 d : x0 Y7 G9 G. S' ?- Z7 a* x( c7 X% G! N
// Get a handle to the BOM Items.
% q: Y9 o3 o$ M$ I* O1 Z2 qItem bomItems = results.getRelationships();
% H, Q& H* z. X) [int count = bomItems.getItemCount();
& I& T$ b+ k9 a8 m0 u( a: `$ [int i; 2 l, D u$ H$ c( g% G0 K
+ i! i% C H: a' I) k
// Create the results content.
' _. s( j. d0 K0 vstring content = "<table border='1'>" +
' {6 j. b+ d* s1 b- U" f% p "<tr>" + / i. ]( c$ D. C9 @) e
"<td>Part Number</td>" + * d# B; B9 i3 i5 K- `* s6 Z7 G7 ~2 ]
"<td>Description</td>" + * U$ l6 O0 I' W0 x8 V+ V$ e& T. [
"<td>Cost</td>" +
6 D) h$ }+ O6 G7 ?# N "<td>Quantity</td>" +
; E5 b/ d, w6 k# ?4 d$ j+ F: t' T "</tr>"; ! L/ W% \6 G8 Z' O' B" F+ ?
8 `% Q, _; K8 m) E& f2 w/ S! I y
// Iterate over the BOM Items.
% {1 C0 c7 |2 Q/ c# c {' o: [for (i=0; i<count; ++i)
( p( x4 F0 c7 a/ \" x{
, D+ ^3 I9 u) L& p3 Y. Y// Get a handle to the relationship Item by index.
2 N" X. T) F$ f2 p& P9 ] Item bom = bomItems.getItemByIndex(i);
# d; ^- K/ x5 g+ h// Get a handle to the related Item for this relationship Item. 7 z% b* c0 b$ U! }
Item bomPart = bom.getRelatedItem();
; v A P: T9 L2 ]) ] . f0 c- G4 ?) c) \: h1 x# k0 p
content += "" +
" K& i6 U6 b: i% s X# z/ q" t% C "<tr>" +
* r& F+ s( Z5 \8 _8 T. y' z "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 l, G) {& S: ^6 b$ x "<td>" + bomPart.getProperty("description") + "</td>" +
0 u5 W: o, R* l' | "<td>" + bomPart.getProperty("cost") + "</td>" + - N }" m7 S/ {3 o! _
"<td>" + bom.getProperty("quantity") + "</td>" + " [6 I K) _( Y+ `' L4 [; U+ ^
"</tr>"; + P* q: B; |6 o, H7 R
} 8 S( n. l: N1 n& W" V( ~, d
content += "</table>"; * V! R$ J5 B6 b m+ z
7 R! K/ b- a5 _# _
return innovator.newResult(content);
( R P* { F( Q( Z6 v. d7 R
0 b7 ]) r. w# ^9 p2 i9 e
8 Y7 R$ x) H- P3 p; x8 D$ k) S6 s! o4 S! o2 d! B; x
& [0 [0 x9 n7 l& S* k
7 C$ M+ x9 O3 n
" A( s7 s( z+ K" i: {* I" ]
( e' P( j7 e/ M+ P( O9 S8 n Page 46 8 |$ S x+ R/ h$ l9 d8 B* C
5 M: l3 A- M# W6 x- T% K" cCopyright 2007
) w$ Y" Y, F' E: u$ B% {Aras Corporation.
$ R# }6 g" l* E8 Z: W+ cAll Rights Reserved.
% e1 a) z7 ?' o3 s$ \; ?VB.Net
! J7 L4 w+ T8 A0 RDim innovator As Innovator = Me.newInnovator()
! a& w0 d1 d$ A0 {
+ I$ n( p6 e. f8 V: T' Set up the query Item.
' u! f* R; G5 n8 R) QDim qryItem As Item = Me.newItem("Part","get")
8 E9 Y; k9 O) c6 P! ]* i: HqryItem.setAttribute("select","item_number,description,cost") / g& E) P; ]- X! C
qryItem.setID(myId) 8 b; E9 x/ j+ @! d$ ^: g1 v
) r+ s& q$ o! ?
' Add the BOM structure. - e1 |# d- @" j' _/ \/ N& P. k
Dim bomItem As Item = Me.newItem("Part BOM","get")
) G$ W9 w8 L hbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 0 e" q4 ?4 y3 v! e+ h
qryItem.addRelationship(bomItem) 0 U" _7 f4 _! t4 ~8 z$ _
" }8 \/ b$ p: o, h, s' Perform the query.
7 A, }2 S9 I7 q7 FDim results As Item = qryItem.apply() + Q. n6 ~* c" \, @' D) ~5 u( ]' V' e
$ O# j, @, w4 s' Test for an error. ! W$ R5 X1 T( f
If results.isError() Then - X$ T: C- {) B; q+ [' O2 v
Return innovator.newError(results.getErrorDetail())
# m. ~5 `# P1 s( N9 f+ L2 G d' U3 n; }End If 0 q; ~* c) c6 R% q! X
3 A' B- z; u6 e* u V
' Get a handle to the BOM Items.
' R: O2 h( o+ JDim bomItems As Item = results.getRelationships() c, L9 L0 ^' ]9 I, {6 U `3 p
Dim count As Integer = bomItems.getItemCount() * D0 |3 k8 e& b! D
Dim i As Integer
$ C7 {1 C0 c; S9 U3 }- H5 S0 Z
4 X) Y( o$ P, P8 P i2 g' Create the results content.
% |/ I5 D% P8 d( K; _7 {3 h% t0 {Dim content As String = "<table border='1'>" + _ " d3 F' \# P- c# C1 l, Y) C
"<tr>" + _
; n4 i4 X& p# s, P1 j2 f "<td>Part Number</td>" + _
% E1 {6 y( e% W4 w7 u4 T& g- h "<td>Description</td>" + _
8 Y2 A0 J9 p! Y, x# v2 y( E "<td>Cost</td>" + _
1 r& w: w( J" d+ _/ S: X "<td>Quantity</td>" + _ 9 d9 v1 c1 w- a
"</tr>"
: G+ l6 Q9 }' j: m- d6 W
" ^2 g" Y1 h9 X% X' Iterate over the BOM Items 0 s9 C- j6 a0 h" [/ w/ A
For i = 0 To count - 1
+ ]3 ~" u, Q. R# [7 _' Get a handle to the relationship Item by index. % g, a1 I1 s5 W$ {- [* k
Dim bom As Item = bomItems.getItemByIndex(i)
4 D5 o Q* g" [. ^ - Z- m" D7 M( d5 p
' Get a handle to the related Item for this relationship Item. + M# N% V: f( `! n
Dim bomPart As Item = bom.getRelatedItem() 4 J0 S7 D: g/ D3 h
3 e) `1 ^, d5 d+ t/ N
content += _
8 a! Y, R, e# Q "<tr>" + _ 9 Z& q# W: r/ [, \, H
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
. P# K( n- ], Y1 R "<td>" + bomPart.getProperty("description") + "</td>" + _
- x2 Q' A! U% [; X# m "<td>" + bomPart.getProperty("cost") + "</td>" + _ * c" h5 M9 S) {% O) q1 Q1 y) L, t
"<td>" + bom.getProperty("quantity") + "</td>" + _ # f$ v/ {+ b6 f/ {6 l: p) O. F
"</tr>" . |+ H+ i- ^7 v% f" ^$ R% \
Next + w5 U& e8 p' [& C7 G
content += "</table>"
' {) P. O4 l- h# h. \
0 B( z8 p, u! UReturn innovator.newResult(content)
3 Y4 ~' Z' N& }1 b, ~
# t9 V" G) o' A; i |
|