|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
, V) `) E4 e7 `! F2 l5 WTo query for an Item and retrieve its structure you build the query as the structure
) u" k; ]) r- Dyou want returned. Use the IOM methods to add the relationships you want and
5 h9 H) M) ~3 x) \) sbuild the structure in the Item. The server will return the structure that follows the
% [! U [+ u4 r. Rrequest structure. - q0 }) K6 l! p9 y* Z1 J* H8 F
This recipe illustrates several related concepts together, which are how to get a set
8 ]; C: M2 {, Y3 Uof Items from an Item and how to iterate over the set, plus how to get the related
( _, X# t1 w* P9 A9 ]Item from the relationship Item. 0 Q! H9 C& T6 q* U4 Q* l
JavaScript / V4 O3 D( Z R5 x% ~
var innovator = this.newInnovator(); 6 D+ v X% b: c9 d) P9 A$ Y. w7 p
0 z: A: q* Q: ?* I" o, t, ?$ \// Set up the query Item.
{3 b$ S' |; uvar qryItem = this.newItem("Part","get");
% [8 Y3 q# k: m; |qryItem.setAttribute("select","item_number,description,cost"); 1 l7 d: c& p3 K8 D# l, z" X. V* B% o
qryItem.setID(myId);
3 f6 G- B9 M* Y! J( O
- X I* O9 R4 N* f// Add the BOM structure.
' t5 K3 `; _8 j5 u3 w. Pvar bomItem = this.newItem("Part BOM","get");
6 G: r2 L' m' ]+ Z+ fbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
# V: N+ |: b8 x' v5 ?qryItem.addRelationship(bomItem); 4 @! [! C4 o6 b- |$ R: ^
: {' |+ f6 Z G/ I* o' i+ G
// Perform the query. * m: `( F8 m" T, @8 e( t: t2 F
var results = qryItem.apply();
; b$ y: {& |( }; V* Q2 ?9 C
/ n* T5 _2 K C. z# v% R* i: u// Test for an error.
+ t( c7 a5 i% y* @if (results.isError()) { t! C& Q' r: h8 L& x5 n# A0 r
top.aras.AlertError("Item not found: " + results.getErrorDetail());
/ r2 W- t/ n! k" `* Q) {2 ~ return;
* F, Z. u% L* [7 K& @! j}
! C1 p3 A5 ^3 K$ Z( [
- M0 S0 U+ J% Z. r// Get a handle to the BOM Items. & E2 [5 Y7 |! h& u) z
var bomItems = results.getRelationships(); / K6 K7 V' v+ _+ L0 \
var count = bomItems.getItemCount();
4 C `6 S4 d d- X$ }4 D5 g
: G3 z3 Z# m* c' x// Create the results content.
m7 v1 F! b6 k) ~( z- _# xvar content = "<table border='1'>" + ) ` B/ ]+ F. K7 X" \
"<tr>" +
/ J9 u% j& ^; u( T4 m% C$ A "<td>Part Number</td>" +
3 I& z9 }2 X1 V, D "<td>Description</td>" + 8 W" q2 b7 j0 b; z, E
"<td>Cost</td>" +
8 w% `2 l& q/ B4 c9 q "<td>Quantity</td>" + 3 w& C7 g3 L' Z' H w( _4 a
"</tr>"; : e2 ~6 d: b5 j& o
y" g% B# k5 _8 b2 y// Iterate over the BOM Items.
8 ?9 c4 M% w/ N$ y/ Y0 Sfor (var i=0; i<count; ++i) # x+ ]" _$ W* x: S7 T
{ 6 `8 q- a. G! k/ r
// Get a handle to the relationship Item by index. 7 p E% L, }) T! d+ b1 X! [
var bom = bomItems.getItemByIndex(i); , U0 X+ G0 z. b
// Get a handle to the related Item for this relationship Item.
7 O; e, ]$ X5 q' ` var bomPart = bom.getRelatedItem();
: v9 e9 \4 h+ }0 H - E- ^4 Y; R. h1 k; S
content += "<tr>" +
3 @" g0 N, y4 P" M2 ? d& \1 P" R$ f- B "<td>" + bomPart.getProperty("item_number") + "</td>" + $ a3 u# j8 e7 O n0 l3 l }
"<td>" + bomPart.getProperty("description") + "</td>" + 2 f: v# Q4 m _6 o; r
"<td>" + bomPart.getProperty("cost") + "</td>" +
* z" Y2 E6 a/ q "<td>" + bom.getProperty("quantity") + "</td>" +
% ]& i- W. {0 n: W' M "</tr>";
& @9 \" Z% l8 U! m- Q} / ~ o* w6 E7 N, W9 k& F6 E
return content + "</table>";; e" q5 x0 F# G' K$ X
5 e8 m6 R( y: b+ ~' ? F6 E" b
. b' P4 e3 @! h" j- b' A) ~+ f
& N5 B! u' T0 L- `4 ?' v
' g0 Q- y. @2 g; A4 g6 nC#
5 ]) A* o% [, {1 h; rInnovator innovator = this.newInnovator();
+ F( u* M' g# }. ]* h# ]/ U & B9 ]% y* `- j3 |
// Set up the query Item.
+ X- t3 V7 w# l" r3 Z6 F2 V+ l* o/ IItem qryItem = this.newItem("Part","get"); ) `7 o' W' S( ^
qryItem.setAttribute("select","item_number,description,cost"); 1 _) T* W$ c" M! S3 I. Z: Q
qryItem.setID(myId);
" x! U, t" y+ E; G
% ^- y& U9 |! Q% S0 V' _' q// Add the BOM structure.
. V9 H3 C: ]% e& tItem bomItem = this.newItem("Part BOM","get");
6 _; @' e, ?( j" h7 O8 U: Z0 n, hbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
; ~7 I5 V* N9 e e( s; d0 E) SqryItem.addRelationship(bomItem);
, K+ B4 \ v; o/ ]9 x2 J
+ l/ {/ H5 Z; P3 T; R+ f) A* q( e( [// Perform the query.
) G/ {& x' u9 h% a) p1 @1 EItem results = qryItem.apply();
+ E7 A. y) Z3 r8 }9 S* T
, E1 d7 [# y* a: X! h// Test for an error.
% e: }; w) l" a3 V. y3 Aif (results.isError()) {
/ l( K2 Z4 l& }* X* q return innovator.newError("Item not found: " + results.getErrorDetail());
. D: e4 W' v5 g& j; Y} ; F. W' M) L, p5 G9 p- E* h i. K
f/ Q3 s3 j9 a/ g% U// Get a handle to the BOM Items.
% {2 u8 {7 S7 ^8 R5 ^2 P1 j6 KItem bomItems = results.getRelationships(); - h8 N" e8 z Z9 z$ c: X
int count = bomItems.getItemCount();
4 C! b" y& B0 rint i;
, z1 S, _0 ]. X/ S- ?$ J) ^
; x# b3 c" f; e8 M1 e// Create the results content. 5 d- @' J1 ]# S0 x p3 d8 a% X* t
string content = "<table border='1'>" + ! ]8 G' ^0 s/ t( i1 I
"<tr>" + 2 J& l- K0 q% O1 z: _9 d
"<td>Part Number</td>" + 6 l6 X; h7 U! f9 y
"<td>Description</td>" +
0 b5 [6 [- Q' Z, | "<td>Cost</td>" +
0 h8 P* Y* U& B' |6 b, U+ P "<td>Quantity</td>" +
$ h7 l7 s* H9 c/ `7 a9 t "</tr>";
0 A/ r/ g/ M0 `# J0 @ " Y1 T- w4 I* `4 |
// Iterate over the BOM Items. . f: [0 ?; [& w) A
for (i=0; i<count; ++i) ' y, e$ D; T" ]. z: s! b& e2 d
{ $ r' L. R) o( }' s
// Get a handle to the relationship Item by index.
' c+ s% C1 [: l Item bom = bomItems.getItemByIndex(i); 4 M( @2 A6 v7 c% f# y6 Z; c
// Get a handle to the related Item for this relationship Item.
; m, V; a1 Z# l4 L" s K Item bomPart = bom.getRelatedItem();
9 {; S G( s" X ` P& W! L ' d+ C4 z4 A' ^/ [% |2 A' J5 v
content += "" +
1 |, w' W( u5 [+ P$ I+ O- O "<tr>" +
1 ?! Z+ Q) H# _+ { "<td>" + bomPart.getProperty("item_number") + "</td>" + / X' v/ n% H% o, e8 F' R6 ~
"<td>" + bomPart.getProperty("description") + "</td>" + 1 y5 J1 e, L2 K4 g
"<td>" + bomPart.getProperty("cost") + "</td>" + / n0 U% _/ q6 n! W/ \( [# A" w# S
"<td>" + bom.getProperty("quantity") + "</td>" + 4 @5 T8 ?2 m" s4 c
"</tr>";
1 T/ U7 Q& y+ G( [% u5 ^}
8 w7 i6 Q2 b6 ccontent += "</table>"; ) S, F" T4 A; Y4 t8 |) P( K8 Y
! s) t7 l. N; b' s, M
return innovator.newResult(content);
2 w" u1 x1 f" y; G+ ?2 S% a
4 \$ R3 T& t/ y7 Z2 d0 y) \ D+ B) E2 L b3 g& V: @ M
7 P+ e3 o: ~$ e4 q7 {
$ A' h- Y X* F6 S0 s7 x% M% r% x! m9 w! L! u o
$ i7 X7 ]7 x3 M% M% j
$ k/ K* p5 ]0 m# C+ { Page 46 . `3 p$ c$ U) |0 `! O( g
4 C5 Q! `2 |5 O% Q* W
Copyright 2007
2 n2 G: \0 d5 o; K1 X$ V2 qAras Corporation.
+ ^: Y% m2 N; E( |# MAll Rights Reserved. . I4 d9 \, U0 n+ j
VB.Net 0 q. _, P" s- D- i# [( C
Dim innovator As Innovator = Me.newInnovator()
4 E. j3 Z+ @+ Q; q" L
W2 b) O# T/ a T; V D8 I! Z' Set up the query Item. 5 h" `0 t# v8 @, J/ }
Dim qryItem As Item = Me.newItem("Part","get")
& t3 S2 @0 _' n, u. ~( I; `( V2 ~qryItem.setAttribute("select","item_number,description,cost") ( l" x* G5 J6 V- Q( _& ?$ x
qryItem.setID(myId) " C* K% p/ N, T0 Z: }1 ?1 G
! ^$ z5 [( h- ~8 z# z0 u3 \8 A
' Add the BOM structure.
0 e* k- X6 Y; y3 o" dDim bomItem As Item = Me.newItem("Part BOM","get")
' a( _7 A h8 w5 [& HbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
8 d) h: s6 u- ]: t; C, v D+ [, wqryItem.addRelationship(bomItem) : N; A0 c8 k; D9 [' ^6 Z( p
! v1 ~1 G% r2 \- Z+ k# m" o2 k7 F
' Perform the query. 3 ?6 C1 l3 d! w# f1 J% b
Dim results As Item = qryItem.apply() 2 Y' X/ A( ]4 p5 M- m
* p' ?4 t* j, M9 d5 a
' Test for an error.
/ Q+ i3 H# ? T$ n: ~, jIf results.isError() Then
9 k# d7 c' l b" A' w& g% ^5 E Return innovator.newError(results.getErrorDetail()) 4 T6 G0 g! n/ Y- d! a! M8 J
End If
( E* C: o$ [8 M6 x) i9 S+ Z3 @
$ S0 W/ A8 k3 q( k7 j) e* _' Get a handle to the BOM Items. 4 Y" _ h C* D8 _) `0 T
Dim bomItems As Item = results.getRelationships() , Q0 N3 }# l. v! d% P, E# U4 H: [
Dim count As Integer = bomItems.getItemCount()
$ J, \/ A" w: J3 f: {Dim i As Integer
; p' W% o c9 k& g. j 0 z4 x1 l4 x. D) E, m2 Y
' Create the results content. : H- [1 a( i( Q9 s
Dim content As String = "<table border='1'>" + _ ; @/ a3 d: D, ?/ k8 d1 R* y2 C
"<tr>" + _
{$ ~! I9 s" p- `" h i "<td>Part Number</td>" + _ 4 I) l) d( O' G/ ^3 Y+ u) j6 _
"<td>Description</td>" + _ 7 y% \8 M+ b- {
"<td>Cost</td>" + _ . ?( x* |2 a" X. {9 D# L4 ?
"<td>Quantity</td>" + _ 8 U N x7 B/ l* P
"</tr>" , a! i* `' a& h
# c7 R m# G4 k
' Iterate over the BOM Items
* E* G- o" s4 x+ PFor i = 0 To count - 1
/ m& ]& A% Z, Y, G' Get a handle to the relationship Item by index.
; I/ c/ P' C/ l. |* b* n Dim bom As Item = bomItems.getItemByIndex(i) 1 @; g% m! e( }" k. n
7 U, a. y) U; u! l- I8 w
' Get a handle to the related Item for this relationship Item. ! x/ G* R, b; t I
Dim bomPart As Item = bom.getRelatedItem()
; k N, g& f/ r# M, t. F+ d- n
) W1 J, _! V9 o4 ` content += _
` ]1 ^% W, w7 g8 k "<tr>" + _
# W, i3 O; b3 C6 E "<td>" + bomPart.getProperty("item_number") + "</td>" + _ \/ c$ V" j* \) E9 [4 h/ ?5 r
"<td>" + bomPart.getProperty("description") + "</td>" + _ * J' ~3 {8 T6 W9 p- T. ]& f* R
"<td>" + bomPart.getProperty("cost") + "</td>" + _
3 J; Z, p) W0 A" n0 m "<td>" + bom.getProperty("quantity") + "</td>" + _ , y7 ]& o# z. U* u9 K
"</tr>"
3 ^; w- i: B1 sNext 7 l( |! w2 w9 E2 ?: e) [7 l! y
content += "</table>" 8 @* H1 o1 C( ^5 f8 {
^' ^0 @% n: N9 K7 s( a9 g7 nReturn innovator.newResult(content) - m0 T3 a7 ~/ R
' z' K" M: K: h8 ~( A8 s! w" ]
|
|