|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique . E" R0 V1 M' G
To query for an Item and retrieve its structure you build the query as the structure + e/ A7 ?7 y, k
you want returned. Use the IOM methods to add the relationships you want and + }# `' N+ b$ L7 B& [9 [2 v! r: U
build the structure in the Item. The server will return the structure that follows the & D" J5 g" }' D [) t
request structure. , `% G$ c: j* c, S+ k7 G' d/ V( r
This recipe illustrates several related concepts together, which are how to get a set : B: i. `1 s$ t) o# X O( D
of Items from an Item and how to iterate over the set, plus how to get the related 3 O7 M" [ L$ v8 C
Item from the relationship Item. # j# Y* p4 O* G1 w" q |
JavaScript 4 [3 F& W1 n# {! T
var innovator = this.newInnovator();
5 j% G0 Q$ E" b
. t5 H# a' t3 x8 {# G// Set up the query Item.
# \' [" K( y |( J. _var qryItem = this.newItem("Part","get");
5 K* v9 Q4 }6 l/ L' C2 \+ s3 jqryItem.setAttribute("select","item_number,description,cost");
/ g3 V7 H- S1 R) |" rqryItem.setID(myId); 2 |6 m# U# J# F* N5 i. ?5 [/ k
. [! @, _% z7 p1 N2 m8 Z* {
// Add the BOM structure. d1 W2 e2 p! y6 C$ K' s; ]* r6 \
var bomItem = this.newItem("Part BOM","get"); 7 W; O5 f+ Q0 r7 z$ O' o
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
' H7 V& Q( ]3 m% H" g/ {qryItem.addRelationship(bomItem);
( B: k$ G! i) P- \2 B) d3 N2 i+ } 1 }' c& z F( ^% d* w; x# K
// Perform the query. ( Z$ t1 m8 K2 a! H$ H5 Q1 T4 L
var results = qryItem.apply();
& F. U5 K$ n4 n! N& t - i/ l& ^7 l$ R. f/ N
// Test for an error. 2 W1 r/ I% r K3 A$ x
if (results.isError()) { z: C& W! S+ G3 U6 [! z
top.aras.AlertError("Item not found: " + results.getErrorDetail()); . d5 Z# J$ }' @( J
return; ) t6 x" f7 ]) B; p" H
} . i2 o. E; W) V% U5 ]
+ p- g% L0 {5 \# s1 p- N
// Get a handle to the BOM Items.
& f) C; O9 y# Z4 ?3 C5 Qvar bomItems = results.getRelationships();
% p; c. l( N, [2 _. ]var count = bomItems.getItemCount(); - y: Z4 Z% b$ e. v
% @, R9 [3 U+ U3 p9 f
// Create the results content.
: l) F, I8 F% Ovar content = "<table border='1'>" + 9 d0 }3 _4 |" d1 L
"<tr>" + * }7 n l# V w2 c
"<td>Part Number</td>" +
5 p8 C( R( P; s2 Z" J$ j, R "<td>Description</td>" +
2 a3 Q* o, |; Q0 ]* C "<td>Cost</td>" + 2 Z- l% `5 _2 C8 l; m) G- A2 `
"<td>Quantity</td>" +
/ q& Q3 I2 d! F "</tr>";
3 t7 ?- L, _7 `$ X% i
$ w8 A5 a/ Z- p5 ?) P// Iterate over the BOM Items. & Q) H) b) ^% j0 W- e
for (var i=0; i<count; ++i) + t. G6 i4 H: T+ R
{ * c7 b3 B# B9 d+ @* K, o
// Get a handle to the relationship Item by index.
+ X7 i/ U- w+ x" r var bom = bomItems.getItemByIndex(i);
0 q& n% b0 i# P8 w3 h// Get a handle to the related Item for this relationship Item. & q- l0 C( a, p) J
var bomPart = bom.getRelatedItem();
, e* U! D& t: y/ a1 h5 K' y* } ; M# G6 H) ?. ~ \7 \' A
content += "<tr>" + 1 F: i- B+ Q" m0 b9 S; u
"<td>" + bomPart.getProperty("item_number") + "</td>" +
# `" q! {/ c- }& n- w "<td>" + bomPart.getProperty("description") + "</td>" + 0 t$ H) o, J& ^- V
"<td>" + bomPart.getProperty("cost") + "</td>" + & U* I) w m' b- M" B
"<td>" + bom.getProperty("quantity") + "</td>" +
; I9 a9 | w8 ~6 R "</tr>"; ) e* J0 ?$ I3 I9 f3 \! b5 z# l8 v3 R1 T
}
9 S/ Z" e& R1 Q' @, X5 \return content + "</table>";# t) _$ F3 u B
6 F4 m, C7 V4 D! P1 R
( J3 b1 F; z. F5 ~* g
i6 i$ ] G# \ {5 Y; U' n4 [/ _2 n8 V2 n( k4 c
C#
: [8 ^% a! D' p* i# k/ j* ~0 Y# pInnovator innovator = this.newInnovator(); 4 x+ X( G) o+ b+ @5 q/ Z' e
( y% g9 E7 ?3 h- o+ z9 b// Set up the query Item. 9 w( Z* [; @! o, n d/ f/ J
Item qryItem = this.newItem("Part","get"); 1 r1 f M! w" A) m( F* H
qryItem.setAttribute("select","item_number,description,cost"); 9 i: s! I4 v6 S6 Y8 |: Z; j9 W1 ^
qryItem.setID(myId); - f* l& C0 l3 i' I6 q, H
+ p8 Z2 C1 J) q3 g% {
// Add the BOM structure. - ]0 q3 k; ~" _, T
Item bomItem = this.newItem("Part BOM","get");
( A; X5 t" R. G P1 a" R' JbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 2 K: R' @2 i1 p7 q# A' G$ u
qryItem.addRelationship(bomItem); # g/ m* u3 r F9 ?% D" J6 s6 d1 z
U2 n; G+ Q% N4 a# B2 D
// Perform the query.
; P" g0 u6 G% J1 b) d$ l$ @) ?Item results = qryItem.apply(); ' V5 K0 @" l- N# x! P
* Y* b) D/ c5 ~- M5 `// Test for an error. ; K$ l, y5 W: C9 X4 p! @
if (results.isError()) {
% t' ?4 f5 O2 n9 p! S return innovator.newError("Item not found: " + results.getErrorDetail()); " D) ]0 w1 l7 O m& z* I# R
}
2 t+ D; Z/ M: }6 m# O9 A4 Y
5 i" w- c8 [$ o- n8 a- l3 e// Get a handle to the BOM Items.
( r1 _, p+ Y' c' [Item bomItems = results.getRelationships();
% Z+ k4 j3 S* V5 ]) J* @) Bint count = bomItems.getItemCount(); 0 Z( ~. P/ q- m7 D4 y
int i;
+ d- r9 A- J! }- J
, w( y5 p' l% G, w// Create the results content. % Y! @4 B8 x' y4 Q6 P, }, D2 c. Z% T
string content = "<table border='1'>" + ]' m3 k. T$ C! G: W
"<tr>" + 2 f6 _ F7 Z+ ]5 h. Q" {
"<td>Part Number</td>" +
5 |- Q- T) @1 m* | l0 j' ^ "<td>Description</td>" +
2 g. y7 |& q; |4 p1 ^- V "<td>Cost</td>" + % v2 _; o* l. t+ k. c7 g2 o
"<td>Quantity</td>" +
7 _# j$ ^! f- g& a; S "</tr>"; r; b) s, ?7 t- N
# J: c8 R) P% F/ q// Iterate over the BOM Items. # l$ |9 H# l6 u4 M! v# Z
for (i=0; i<count; ++i) H" Y* l% w N1 ^- i
{ 3 V. t6 ?2 k, f6 M6 s6 D
// Get a handle to the relationship Item by index.
" J- }9 K- G( H Item bom = bomItems.getItemByIndex(i);
5 K* J& \% G/ b/ r; o// Get a handle to the related Item for this relationship Item. * x" c5 [2 P) b2 ?+ p: W( p
Item bomPart = bom.getRelatedItem();
0 u) p5 X1 _* L* _5 L
& M q9 R# e. P content += "" +
8 o; L) A, D% F5 ` "<tr>" + 2 o% \& z, r7 m$ R3 F6 G( [" z" p
"<td>" + bomPart.getProperty("item_number") + "</td>" +
5 H. M% v; O0 O" ~: S* m5 u8 q8 Z3 I "<td>" + bomPart.getProperty("description") + "</td>" +
+ V& F3 G0 I4 a6 l% \7 e$ x. G "<td>" + bomPart.getProperty("cost") + "</td>" + 3 c' O' @1 j" D. `. j
"<td>" + bom.getProperty("quantity") + "</td>" +
/ M) g# n5 Z& g$ Z "</tr>"; 5 w$ R, ^0 X! F5 X q9 p7 l5 {
}
1 e! _- b7 Z" lcontent += "</table>";
3 C% R; m' s, {* y; G $ o3 I' X* t0 A% J6 `& h
return innovator.newResult(content);
- ~& |* l6 f( o8 b# Y" c
" L% n3 j; B! ]. r% D3 R
! \# E8 v/ H: q' h: U \0 ?) b
& |$ L" `. W3 v) z' L$ e
: G; U/ ^# p# M. O6 u$ h8 O( v+ D' k
% w4 `. U% I! q0 p& `
% }* h( J1 X8 m; X q Page 46
/ V* F' U! r" y: ]: d
5 K: E, M5 v. h2 G6 KCopyright 2007
: o7 L' U$ M; XAras Corporation. ' y+ \$ n8 O1 q( J$ n4 r
All Rights Reserved.
7 ]0 f3 ^1 q) Q4 m7 bVB.Net * d# Q( a; x) L, T; g
Dim innovator As Innovator = Me.newInnovator() + {" E" C# V! k) d7 R8 X, `2 H9 m
4 |: i; S# Z1 l% h- w# M' w' Set up the query Item.
$ d! `/ x, Q, ]' P" ]3 y) T/ hDim qryItem As Item = Me.newItem("Part","get")
: r! O& V9 L- S2 y! RqryItem.setAttribute("select","item_number,description,cost") 6 ?9 X2 R" @) ]
qryItem.setID(myId)
, X; W$ O2 `- Q* j& c) x + t% x, a3 `, b, M% D$ v% s+ O$ I
' Add the BOM structure. 9 Z- k( O7 g9 @$ f8 i1 S
Dim bomItem As Item = Me.newItem("Part BOM","get")
9 a' ]2 M' \! ^( Q, m6 {- C; FbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
2 x; s4 }) T, @1 sqryItem.addRelationship(bomItem)
% v% A; V9 ^& ?& _9 K8 i
" }2 v' [$ o( F. H" z/ p( F0 F' Perform the query. 2 ^5 o5 s. d, X$ m( W
Dim results As Item = qryItem.apply() $ Z7 A9 X ]6 {2 |" w, e9 n
1 I6 M+ a" Y. Z9 i0 @$ G' Test for an error.
: `' z& b+ `3 b% U# hIf results.isError() Then
7 Z' l# h. t5 o- _5 M* u- m0 y. c Return innovator.newError(results.getErrorDetail()) 0 W U+ m4 E/ S. G& S
End If
( }* G9 O* `; m4 g
7 ^' q7 J7 y( O7 Q! l) W5 x! {! v' Get a handle to the BOM Items.
! B7 m$ X% d& g- SDim bomItems As Item = results.getRelationships() $ j3 ?1 R# G1 ]7 q+ H. m) `
Dim count As Integer = bomItems.getItemCount() 5 X! [" g/ p1 B
Dim i As Integer
" u/ g# {3 r% Z & O5 z+ {6 W* R5 U( P, U
' Create the results content. ' ]( T* x6 A% q/ x- y' R! ]( }' F
Dim content As String = "<table border='1'>" + _ : P' d" _( o3 }" l5 m
"<tr>" + _ 6 ?/ `/ L Y- [6 E$ P) V
"<td>Part Number</td>" + _ 6 j0 B4 ~3 c" `/ W, t: i4 U3 G
"<td>Description</td>" + _ 2 N3 n+ ^6 b5 d( k8 {" @! X
"<td>Cost</td>" + _
4 K5 o! c+ p; U- E3 V "<td>Quantity</td>" + _
0 j: O. C4 _# Z7 h4 q "</tr>"
( L' |" u+ D' g* d+ J9 e" ]- }. L |* ^3 J0 Y3 X& ^7 _7 P8 _/ W
' Iterate over the BOM Items
4 ?- n; w& L# z. I' h& u2 e" w# |$ iFor i = 0 To count - 1
% ^& o. g) o9 W/ N5 k' Get a handle to the relationship Item by index.
. z N$ o) R$ ?1 f, F" Z) T Dim bom As Item = bomItems.getItemByIndex(i) . \: F3 I4 k/ h4 C# H! f$ r
9 P& {6 G- F5 g! X+ D& e1 q. U: O
' Get a handle to the related Item for this relationship Item.
. B& a% H% d$ @' ] Dim bomPart As Item = bom.getRelatedItem() + Y! S6 ~: p* H" T& M2 m4 G! u
- B/ Y5 S# A) d0 a* X: G4 b0 P) V content += _ * Y+ `3 A9 }( n) |7 H
"<tr>" + _
6 I2 z T6 M& o7 Y" g, [ "<td>" + bomPart.getProperty("item_number") + "</td>" + _
4 q1 H" ^0 v8 V9 J9 G1 s6 g" T! [0 t "<td>" + bomPart.getProperty("description") + "</td>" + _
# k0 ~6 z B- ?3 Z' `/ n' A0 I "<td>" + bomPart.getProperty("cost") + "</td>" + _ ; y( J* t9 s* d5 e% E! a1 O1 m
"<td>" + bom.getProperty("quantity") + "</td>" + _
. }7 g2 ]7 k1 K' A) v; T& f "</tr>"
V8 v/ u( M$ _$ b4 D: \Next
1 B. ]" e5 e1 {% v: Q9 jcontent += "</table>" - s5 T0 A( B" H" ]! x# E- l
; Y5 C& W0 R" N2 bReturn innovator.newResult(content) 9 ]. H; ^% A" T0 \7 T2 {
! G4 E4 M7 o6 _
|
|