|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique : o- Q; H1 C) Z& C
To query for an Item and retrieve its structure you build the query as the structure
. g9 f# R: S& |you want returned. Use the IOM methods to add the relationships you want and
# `$ q% W1 V$ m( |% `2 j. l% @build the structure in the Item. The server will return the structure that follows the 0 X1 [8 Q; o Q% y6 I0 s
request structure.
" i( o& h4 A( i; k- k$ N4 @: z% ?This recipe illustrates several related concepts together, which are how to get a set * R1 P* s( w( h8 ^ x$ H
of Items from an Item and how to iterate over the set, plus how to get the related
" B t! H" s( h. R) r; F* s* ^Item from the relationship Item. 7 S0 H9 R* t$ e" t% e/ N
JavaScript ; J1 U* `. T! V7 k6 ^9 q
var innovator = this.newInnovator(); * p) W, ~) |) G% J% n1 I' p6 k
/ w& T: n c1 I+ [
// Set up the query Item.
0 |1 B ?5 x1 i5 u2 z7 kvar qryItem = this.newItem("Part","get");
4 n" X2 \9 a+ a$ Z5 KqryItem.setAttribute("select","item_number,description,cost");
2 q1 `0 S+ q( v; nqryItem.setID(myId); % v7 W, x& e# f; ?; q( q" D
, a p9 k. b& c6 i$ G9 Z* D$ H
// Add the BOM structure. ' v8 {) K8 x1 C
var bomItem = this.newItem("Part BOM","get"); % {# C' j4 R$ m% k
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
P1 _2 h, C+ j$ }2 ~. L& fqryItem.addRelationship(bomItem);
?& ^8 m2 r: ?) @# K: j, J
; N2 L3 c) b! H9 a+ J- v2 m// Perform the query.
2 F3 y/ U( v, vvar results = qryItem.apply(); - l8 P, T7 x; Q7 J `7 Y
! h; W/ _ s" e4 W: d
// Test for an error. ' ]8 F9 [: P; T3 ~6 c$ B
if (results.isError()) {
1 ~8 e0 V/ ~, \9 A( z top.aras.AlertError("Item not found: " + results.getErrorDetail()); 2 p* `+ P) Z# C2 h+ S5 Y. f, R
return; 7 x5 D2 {1 g5 j* k' v9 [, c
}
/ D/ e# Y/ M' ~5 w2 h9 \% S 3 o! I$ s& S z8 f1 [3 Y
// Get a handle to the BOM Items.
; `& ^2 r; C9 o; K* ~/ P, M( d/ Z% Z. Ivar bomItems = results.getRelationships(); . n* ~. F5 c: _: [
var count = bomItems.getItemCount();
6 K/ {$ j* w0 b: K' J1 @ : D6 k+ u' {# I9 S2 U+ l) p4 I
// Create the results content. ; z( h. Q5 K2 ~( [2 J
var content = "<table border='1'>" + ' x7 t4 c% U7 \
"<tr>" +
% C. X( J$ X+ p "<td>Part Number</td>" +
5 w* X$ e3 O8 U "<td>Description</td>" +
9 e+ N- `- L2 A& u. O% z "<td>Cost</td>" + 7 S h) ]: D/ e( e
"<td>Quantity</td>" + 4 V( I8 ^0 n( u8 V0 y% K2 w8 o
"</tr>";
9 e; V) I% H [ ` N: m 0 V0 N: K' t+ P# `+ T. u
// Iterate over the BOM Items. 2 O1 {# F) B) N" z3 u* Q+ U' c
for (var i=0; i<count; ++i) , ?- y6 C' C' V: t4 `7 S
{
, b. N7 B; y( r( W6 `. j// Get a handle to the relationship Item by index. $ l: k$ {$ A9 `: I4 E. ~% c
var bom = bomItems.getItemByIndex(i);
) r6 [* T9 n0 Y# k$ l* q) K- s) P// Get a handle to the related Item for this relationship Item. ! @! w* ]6 @6 y- @& h8 w
var bomPart = bom.getRelatedItem(); 6 o3 _ t+ h& U4 E+ Q
3 _0 j' M4 t3 ]& P6 k9 O% f
content += "<tr>" +
* L8 b; Z1 M3 U$ }& W "<td>" + bomPart.getProperty("item_number") + "</td>" + / s2 Q* F: e" {$ v X
"<td>" + bomPart.getProperty("description") + "</td>" +
' ^2 `9 d7 z9 T0 h& j "<td>" + bomPart.getProperty("cost") + "</td>" + 0 _' o! J" u+ f# b1 v. @# x
"<td>" + bom.getProperty("quantity") + "</td>" + 1 t8 r4 v3 U1 X+ O: K8 @5 ]4 }
"</tr>"; r% r# H7 C* R! G& Y$ c
} # K6 D7 Q" z- g8 K
return content + "</table>";- J1 K+ l0 Q1 z9 |0 z
- E3 _- n/ F, R% F( u( w$ `5 F5 ]$ ^! Z- k, ?) Q
4 l7 g2 b+ c6 |& A
' D4 u% y6 [+ {, C9 b" zC#
& U" A& X8 y" Z" W7 QInnovator innovator = this.newInnovator();
7 @ e! e- B1 f/ b" ]
+ R; H1 H8 d; o- i( L9 u// Set up the query Item.
B' c# e, b I4 C4 ~Item qryItem = this.newItem("Part","get");
3 y/ V# C$ _ G6 D7 y" gqryItem.setAttribute("select","item_number,description,cost"); 0 q- q1 ^6 I! D, ~
qryItem.setID(myId);
3 O& F) l% Q! S9 j. E& `; c' C' o $ V) K7 j3 z2 p7 S) j
// Add the BOM structure. : s! d; t& }8 l1 u6 b4 V: Q
Item bomItem = this.newItem("Part BOM","get"); 2 {' d3 ~5 v5 W, u$ |; \
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 6 u4 H8 e, e" J0 P
qryItem.addRelationship(bomItem);
! o7 P$ m6 P0 |9 k3 Q% d
! A8 D( }8 y! Z" o+ u- ?// Perform the query.
5 }$ v+ ]1 x( Q; S5 }" q ?Item results = qryItem.apply();
3 p6 ~; v) u. _. q! l9 y * A5 G" \& j3 t1 _5 `' L" b
// Test for an error.
% f4 h8 N& f0 N1 pif (results.isError()) { + x2 B: t, ~! R; w. Z
return innovator.newError("Item not found: " + results.getErrorDetail());
( L+ u" O8 J, @% }+ R} 5 ]* r, F# o, T: q! U
+ t6 g g- e2 P+ w
// Get a handle to the BOM Items.
, e9 P/ X, K# T3 K( q; h S9 jItem bomItems = results.getRelationships();
5 R3 x1 g% m4 Q; E* ?/ Rint count = bomItems.getItemCount();
: D% T8 o i& U- a7 Mint i; 3 t6 L3 E: x) Y1 r- q9 O+ n* |
. u3 {. O; N; t
// Create the results content. % D3 a$ ^* t# n; Z7 R
string content = "<table border='1'>" + : }& L5 t. u3 U# \* p' u3 I _6 x
"<tr>" +
+ P$ F( g' [1 V ^' w4 u2 L2 {9 v "<td>Part Number</td>" + 3 ^* t/ V; d) O+ b. p: p: ?
"<td>Description</td>" + 5 _4 L" p G- x* P: j: \
"<td>Cost</td>" +
; O( ]1 B0 o- G! f4 z+ b7 k "<td>Quantity</td>" +
8 c* F1 W+ S; w "</tr>"; ( \! c' ]3 l: f3 }6 o
& s9 m2 c% T8 P M% V$ v7 @// Iterate over the BOM Items.
0 R/ X, I! A% }; X4 o$ vfor (i=0; i<count; ++i)
/ g- H2 _- }/ T2 B6 ^+ N( Z{ ! f" \& D( c5 t) Y0 S8 L5 c" Y
// Get a handle to the relationship Item by index.
' T5 t+ S( Q" U; O5 Q Item bom = bomItems.getItemByIndex(i);
% j# S$ p. A: }2 I) f& G0 s$ V* Y// Get a handle to the related Item for this relationship Item. 4 h$ u n5 [; F' [: {6 ]: U5 u3 p
Item bomPart = bom.getRelatedItem(); ( k9 q8 x: W0 r
7 i, w3 L1 Z# q" l6 S, D6 e, I: l/ q
content += "" + ; e; v' Y, {6 B; b% N. t
"<tr>" +
8 f: |$ v8 n: B$ z) u9 B4 e "<td>" + bomPart.getProperty("item_number") + "</td>" + - S! e' K, b) t- Y9 p. ?1 ^
"<td>" + bomPart.getProperty("description") + "</td>" +
& P) s7 j. |( P( M3 L7 a; D+ A9 e "<td>" + bomPart.getProperty("cost") + "</td>" +
" o9 ]4 Y( K7 F1 S4 } "<td>" + bom.getProperty("quantity") + "</td>" + . V, M2 F: S$ a. m
"</tr>"; 8 M( U$ o& s# N
} 5 C! D, i2 W; [, p5 D" L
content += "</table>";
0 m) m+ D) j* K) m
: Y5 d( f& Z. U" O) dreturn innovator.newResult(content); 1 t& c. ?5 e" r1 q2 M- N0 c0 X: g
: e% E* i4 C' Y' O5 l2 ~
^5 t! ?. @( F+ @# E) {1 F* d$ a3 P- c; W9 ~( y; E3 x
: K2 m4 B P5 S3 D; G8 I
5 `2 L' J/ _. j! C1 K6 L# P/ L/ J6 B
3 t; j6 J2 O/ H
Page 46
7 }6 J( L9 u( [. r5 `0 x$ N
9 n6 O z0 c n$ {Copyright 2007
, F% F% `, Z. Y& y' K8 u4 M2 F3 TAras Corporation.
5 p& V2 N" F1 u2 Y# r0 ~* JAll Rights Reserved. 0 b& Z3 F5 m+ K2 D ]
VB.Net 0 |2 J& P: T P5 [+ E4 ^" c+ Y
Dim innovator As Innovator = Me.newInnovator()
1 ?6 Q* r+ d- ^' N, M: u6 r " Y" j7 Q4 ?8 C
' Set up the query Item.
+ K! C) C, P A! rDim qryItem As Item = Me.newItem("Part","get")
# ?! J1 E* b j; z7 xqryItem.setAttribute("select","item_number,description,cost") ) L' m& P. A, i0 ^
qryItem.setID(myId) : T" X% {6 M) v* K& Q' ?# n% i3 {
$ T. z1 [5 H6 U( I' Add the BOM structure. ! Q% A9 s' B, ]! c% T
Dim bomItem As Item = Me.newItem("Part BOM","get") 2 Y' {' T% _7 @' h9 _9 }; Y
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 8 Z0 m) S9 b8 ]) m" j& _
qryItem.addRelationship(bomItem)
O5 L. X6 W' f9 Y9 G* t
5 Z4 y; c5 T' U7 t' Perform the query.
2 {. c$ Z* Z6 m5 x [Dim results As Item = qryItem.apply()
* V2 w# O+ k2 Y# O" n A
$ G" i; E5 V5 q' Test for an error.
) H0 H |* e" e" ]: h, Y3 `2 CIf results.isError() Then
8 q6 i. o* y* T6 ^) d9 G Return innovator.newError(results.getErrorDetail()) : y* G. z! Z% T! F A7 ^5 w/ V- H
End If , `' M+ |# v! ^# t3 p6 O Z2 Q0 ]
5 T: {3 Z* j! ^. v# r' Get a handle to the BOM Items. 2 v; I( H# p: ]1 S; e. B' Z
Dim bomItems As Item = results.getRelationships() ! Q7 i9 j$ E$ m! I8 I
Dim count As Integer = bomItems.getItemCount()
( g. Z- m& P% i% ~1 _8 a1 ZDim i As Integer
1 z7 V$ @ L4 u ' \' X* n: G9 N/ t
' Create the results content. 9 q& F& J8 E( x
Dim content As String = "<table border='1'>" + _ + \& Y4 f- s; [% N
"<tr>" + _ 8 \, b( Y# U" N2 u2 Z* l
"<td>Part Number</td>" + _ " `# h$ v$ J2 u! w$ r2 b
"<td>Description</td>" + _ & f' B, z \) o7 v. m
"<td>Cost</td>" + _
6 N1 u$ A2 W; Y "<td>Quantity</td>" + _ 6 q3 v; H! J, G3 S' B
"</tr>" 8 s& k7 {4 o: w9 i# l9 x) C- w
- [. b+ t+ G& Z8 m/ h, T/ I' Iterate over the BOM Items - N+ Q9 m' h" K
For i = 0 To count - 1
$ y# m% h* Y! i" @' Get a handle to the relationship Item by index. " d5 g6 h( L' H2 N
Dim bom As Item = bomItems.getItemByIndex(i)
, J& M) I0 V! ~; w' Q2 I ) n4 A& f+ s" v/ R
' Get a handle to the related Item for this relationship Item.
& t. [$ K# B) m/ r4 f Dim bomPart As Item = bom.getRelatedItem()
1 E3 ]+ g8 E; S2 `/ H( t 8 }0 B, y5 w; X4 A# n! l( P
content += _
: @2 ?' {- m* x* K1 ]0 n7 c1 @+ m9 } "<tr>" + _ % x( h: m# K8 [0 M N' F
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ o' {5 D* V1 E0 O# H# L
"<td>" + bomPart.getProperty("description") + "</td>" + _ ! ^* m) O$ o, }& R ~
"<td>" + bomPart.getProperty("cost") + "</td>" + _
; P- l$ V7 H' ^+ [4 L/ v "<td>" + bom.getProperty("quantity") + "</td>" + _
* t0 _) S( Q! [. g, r2 o& T& ? "</tr>" 8 x' D, g* p* ~9 Z9 P0 I: x- Z8 D
Next
8 Q5 w r3 j& R, d: \. e* ^. U# Vcontent += "</table>" / G3 S0 a8 K/ N- d0 I; j
& J; N. g( X! M2 b0 O) g+ `
Return innovator.newResult(content) 1 x5 K( D8 Y8 A
, h4 R! f, c; ^0 S4 q6 S
|
|