|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
$ j1 @( P* d- z# k5 Z; hTo query for an Item and retrieve its structure you build the query as the structure ( d4 t- l! K, W; ~& R
you want returned. Use the IOM methods to add the relationships you want and ) x8 p9 |' X6 h1 E2 i
build the structure in the Item. The server will return the structure that follows the
K' \: B* L( c7 v7 N3 }% A) }request structure. * V% o. A9 N/ s' W$ {( [
This recipe illustrates several related concepts together, which are how to get a set $ O8 H% g/ `- h) N' q# n
of Items from an Item and how to iterate over the set, plus how to get the related ) X2 H x+ A2 U- X
Item from the relationship Item. 1 \0 Z7 b6 b/ F3 h8 c. K+ V
JavaScript ) } w7 y/ E2 T$ B& m+ a
var innovator = this.newInnovator();
4 ]8 G& j6 j* t4 P
5 z! r$ _, T* T& a7 v2 s// Set up the query Item. 6 y% m* n7 ?9 W7 u9 P
var qryItem = this.newItem("Part","get"); ; y' ~9 s( g. ~3 H; m# v! j
qryItem.setAttribute("select","item_number,description,cost");
4 W, l1 q% e8 d. Y: U$ l* O6 LqryItem.setID(myId);
. J0 O6 B9 e4 N! X& i) }5 P . O6 C& A, b+ }7 }3 {
// Add the BOM structure.
2 W9 S4 X0 A/ S R6 mvar bomItem = this.newItem("Part BOM","get");
% h! P! [- b5 PbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
4 {% N5 p# w5 v$ X4 m. ^, v; xqryItem.addRelationship(bomItem);
2 ^. ?' H4 Z6 c% g2 d, I' ? * T- J5 n5 W9 U. K
// Perform the query. 1 g6 e+ e9 R, O5 R; p
var results = qryItem.apply();
/ A# t1 B$ e3 M
9 `. r% v: w/ _// Test for an error.
: m9 G: R) A vif (results.isError()) { - y% c5 s$ Q5 H% c
top.aras.AlertError("Item not found: " + results.getErrorDetail()); 3 C0 k" I% q5 j/ v! l; ?
return;
+ e0 E3 B; \2 f3 t" h" h) |9 {. F} 9 q6 t X" ~. E6 j# A7 I
3 U( t4 W% H* m/ A
// Get a handle to the BOM Items. * H5 Z- ?) ~# l
var bomItems = results.getRelationships();
# |" g$ @" f3 W- B5 P. b; fvar count = bomItems.getItemCount(); 4 r' S8 ?4 S8 z
3 a* b6 H" T' |2 [
// Create the results content. / E& l& f. m2 }
var content = "<table border='1'>" +
# L# V* K3 s( C2 N7 B "<tr>" +
9 I& _4 D6 T8 G& c3 Z "<td>Part Number</td>" +
3 g, C' i* L7 y; l. U+ D7 k "<td>Description</td>" + . l* @$ j6 r" N- J: R6 s% l
"<td>Cost</td>" +
+ n. z1 K" u F+ Q6 | "<td>Quantity</td>" +
7 l/ Q( C# f o8 ?6 B+ c' B+ C "</tr>";
: V5 ^! r7 ^4 I* Z2 w% x * M$ F# J6 ]0 ^' T2 |
// Iterate over the BOM Items.
7 E, z1 m1 V4 c& Cfor (var i=0; i<count; ++i)
' n1 L8 @3 V9 {9 k5 w{
. D h1 m& ] f# n/ l) ?// Get a handle to the relationship Item by index.
8 c4 F' T5 L) |4 P var bom = bomItems.getItemByIndex(i); h7 e7 d" B0 t* D( ^) q
// Get a handle to the related Item for this relationship Item.
7 w, l5 g' T1 |5 V# h var bomPart = bom.getRelatedItem(); {, Q/ M7 l) ?2 ?2 P' `/ X3 d
8 }. \$ l4 j. A+ X, Q0 Y: ]" V content += "<tr>" + % T2 H" t) B; L8 X* |& H# D# ^0 x7 v
"<td>" + bomPart.getProperty("item_number") + "</td>" +
3 { N6 b: a; u. T( ] "<td>" + bomPart.getProperty("description") + "</td>" + ; ~' C, ]& _9 }3 k! ^* ?# Q
"<td>" + bomPart.getProperty("cost") + "</td>" + / g6 q6 Y" y% _. w: B# I- U1 |
"<td>" + bom.getProperty("quantity") + "</td>" + ) }" c1 Y" |* a1 |1 t0 F; B8 H: W
"</tr>";
$ F/ M4 Q+ r( G- \} ! o9 n0 t% p! A9 C
return content + "</table>";
2 a' P; C$ [& D* m! Y
5 @1 v* N, b( ^9 `6 \
9 L, x) l3 w9 X% ?$ Y# k/ x
- \) @. Y2 s' m1 N S7 u E# y7 {
& k: t- n& n1 a# p# V6 `) RC#
7 \( J, M- R. A2 ^! _Innovator innovator = this.newInnovator(); 7 w5 k+ k, v. X7 F9 f4 q
; M' A1 @8 L% _. G
// Set up the query Item.
3 O0 n' z7 X& e9 f2 S5 N" rItem qryItem = this.newItem("Part","get"); # G( W: y1 J7 P2 C# d+ a
qryItem.setAttribute("select","item_number,description,cost"); 4 f0 e8 o6 [- V2 Y$ ]$ M; e# F3 j( Y
qryItem.setID(myId);
! w2 w. ]5 }& f) Y' q - t% Z& b* d# z1 P. @) v
// Add the BOM structure.
% }. s$ V; V% |6 `0 qItem bomItem = this.newItem("Part BOM","get");
7 b& C: S; z" {+ V4 PbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); - a% a7 m" v9 |3 I
qryItem.addRelationship(bomItem); I6 U" j p" s. V! P
4 O3 e1 O1 m7 M# v ]// Perform the query. ! ]" a/ ]) E% w. K7 S' i
Item results = qryItem.apply(); & o3 P, L- z. d' T$ E
& c) |6 t m8 k- ?/ ~7 J$ k
// Test for an error.
( `& _/ N6 s' Y6 tif (results.isError()) { 7 \( B3 p' J) O; ]# x
return innovator.newError("Item not found: " + results.getErrorDetail());
8 P. ]! H5 v. X, f}
H5 E" j1 E3 }& Y6 f- f [ `. N, W4 H. M9 y
// Get a handle to the BOM Items. & L) k% p+ e6 S$ t2 Z
Item bomItems = results.getRelationships(); 6 g1 K) a. u! ~9 Q; z
int count = bomItems.getItemCount(); - S8 d5 s+ @, e4 d
int i;
: k8 k. N6 z5 v" S7 o. K% j
8 t: c. x1 ?, U4 H, C// Create the results content. $ U9 G6 @1 N' X* P# G# [; W- E4 c! S- \
string content = "<table border='1'>" +
1 i7 Q! T4 l- W "<tr>" + / R+ N P% q/ {
"<td>Part Number</td>" +
X9 z) i8 p9 t8 ?$ h "<td>Description</td>" +
/ P ^4 A. b4 H, G6 H& @8 b8 t) ~ "<td>Cost</td>" +
_0 i( o2 ^3 K( E "<td>Quantity</td>" +
7 o3 e* H8 T5 f "</tr>"; p2 H8 n1 u3 d
' L |+ Y1 [- M
// Iterate over the BOM Items. : J+ q) e( W/ S$ T% X$ F. x2 `
for (i=0; i<count; ++i)
5 P: x$ \4 j& M# }( i) d% R1 p5 |) _. p{
1 t8 Z9 t0 [1 w) i* F// Get a handle to the relationship Item by index. 2 Q3 y _) x" Y8 I0 M
Item bom = bomItems.getItemByIndex(i);
* G1 Y. V0 c* `8 `5 l// Get a handle to the related Item for this relationship Item. / F" [) d/ J" M' h( b# e
Item bomPart = bom.getRelatedItem();
9 Q' A, x! L+ u9 g7 z* A2 p ) S, [" F( a- C
content += "" +
' u" q& [" v; d8 O2 [$ x "<tr>" + , S) z6 ?# Z7 _0 T; P7 A+ u, D
"<td>" + bomPart.getProperty("item_number") + "</td>" +
4 f# G( ]' y1 ] Y% ?, W5 `. H, H "<td>" + bomPart.getProperty("description") + "</td>" +
2 o& R) F% O& X7 R& G4 @; N1 o "<td>" + bomPart.getProperty("cost") + "</td>" +
- S) Z& M* s+ C "<td>" + bom.getProperty("quantity") + "</td>" + $ b5 L G3 S7 {8 T0 J8 M: {0 N% w
"</tr>"; 1 `1 Q* ?* ~# ~( {# C) Q$ y" `8 J
} * c" Q \" J3 ~; U. ~# F" i
content += "</table>";
: z% b8 h4 N% k8 C( q ( {9 O9 g; L/ Y4 c6 ]3 J( q) J
return innovator.newResult(content);
9 ?& U% E" S0 W+ m2 O( D8 {7 V/ L# U8 Y2 t- ^
$ k2 H: e2 s9 t3 l0 z6 j( O9 u) ?
( Y8 x$ X: z& X& k' a, p' e2 D3 g, t1 K* u' @* h
/ W2 a# Q; t2 l/ o; }5 U0 G
) I& ]5 P- T; T. [ 2 s) L: x) \. M& h( r5 H' ]$ g
Page 46 # \) E6 n+ j h0 L8 x3 p+ p
: [7 ]! {% g* X* X4 s4 n' Y" m
Copyright 2007
8 o& x: s" W/ j) t7 E) o c8 p8 QAras Corporation.
; i$ q1 |1 l/ W% |! VAll Rights Reserved.
5 W& Y9 u: f. c. k/ O6 gVB.Net
5 {2 Q# m4 a& ~Dim innovator As Innovator = Me.newInnovator() 6 B" }5 I3 n* F$ |! _
3 W; L2 E$ M4 U- s" a' Set up the query Item.
$ }$ B" ~) D% mDim qryItem As Item = Me.newItem("Part","get") @+ M* A8 D8 h1 V4 q8 V2 }" g9 l
qryItem.setAttribute("select","item_number,description,cost")
7 W( \5 C/ h1 Q) ]8 q# N$ PqryItem.setID(myId) ) T9 F% |% z& t5 ?2 w& S
# N$ b8 y* e4 o, ^; P0 J' Add the BOM structure.
3 _& v0 l2 t1 HDim bomItem As Item = Me.newItem("Part BOM","get")
3 l7 c" u; m" v/ HbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 6 i0 i1 X/ }1 x" a0 ]6 h+ _
qryItem.addRelationship(bomItem) * p# U2 f" O' }4 z% c3 l9 z
; f5 }0 V3 L: P+ O; c M+ o; a6 S' Perform the query.
6 \0 ^- y7 N) W& K0 N8 J9 \% z0 jDim results As Item = qryItem.apply()
) t# [: I2 ]$ d! }* h# g" X
/ u$ F9 |/ Z0 R/ p" o! Z" C) w' Test for an error. 7 k$ {& X7 S; B8 Q" T( i0 \& Z$ b
If results.isError() Then
; H6 P: w' r" Q6 Q4 ~/ {8 j* q Return innovator.newError(results.getErrorDetail())
( L6 P5 [4 Q8 w2 }& a) @9 Y( DEnd If ! B7 z7 ?# S3 f- y
; q5 q6 i3 a0 v- V
' Get a handle to the BOM Items.
, s! O; Y9 W! i1 b+ U) mDim bomItems As Item = results.getRelationships() 8 X6 Y$ E* t! C& G2 M, s
Dim count As Integer = bomItems.getItemCount()
" F2 D( Y% h8 Y" E, z" lDim i As Integer
& S! ?; n' Z1 |3 L+ S & Y5 }# @5 L3 D5 _ z1 l. A, Y
' Create the results content. 4 N! U; X8 L: T f5 t$ E6 b, a# r
Dim content As String = "<table border='1'>" + _ * ]6 |8 J& A; c. P/ Y% _) d. C! B
"<tr>" + _
6 X! y# z {+ u4 O( |" \) Q& C "<td>Part Number</td>" + _ 8 B. T7 z- @6 T6 Q
"<td>Description</td>" + _ . ]2 i% }: P. s! ]( z& |
"<td>Cost</td>" + _ 8 E- q# q C& p) { s
"<td>Quantity</td>" + _ 6 C" G$ e2 v0 x) {* ~
"</tr>"
3 B i1 S( t+ z! v- i5 R/ i* b 0 z# V0 T/ B" w6 o# s
' Iterate over the BOM Items
" K! S) T: Y0 n3 [; E- AFor i = 0 To count - 1 % m" _" i9 _0 q! P7 g5 H
' Get a handle to the relationship Item by index. / ~& Q b6 S, N" u- |! \
Dim bom As Item = bomItems.getItemByIndex(i)
* F' w7 N8 Q. w0 w7 m- [1 @8 j3 k1 m/ z3 O ( l+ H/ y1 a% |, @
' Get a handle to the related Item for this relationship Item. - K2 y0 m* f- J. R
Dim bomPart As Item = bom.getRelatedItem() 8 I0 ~) B. D) m
7 V' O3 I' q, K1 T! P/ d E# E content += _ 8 U9 R7 L" O3 |+ d" P$ H! C( N
"<tr>" + _ 7 _0 a) S# c$ n" G
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
; P3 x$ j3 Y ~6 X5 t. y "<td>" + bomPart.getProperty("description") + "</td>" + _ % X' A8 |" l ]5 ^7 x, m" j O
"<td>" + bomPart.getProperty("cost") + "</td>" + _ " N/ q, b# A% H0 V: N. m
"<td>" + bom.getProperty("quantity") + "</td>" + _
) G9 c- s7 ~* ^- S& |1 j "</tr>" 3 g' K, z0 [! H' H
Next / R) T: h M" k e9 k3 \; b
content += "</table>" ; V, }8 q' i, v: z8 _& K
! v0 e3 b9 o3 `' xReturn innovator.newResult(content)
# d# i6 X9 ?$ F4 M( x: A( [( m$ Y$ x) E6 A3 a
|
|