|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
- s8 B5 I! N2 BTo query for an Item and retrieve its structure you build the query as the structure
2 c, A, F7 s, C. Y% W0 @4 Wyou want returned. Use the IOM methods to add the relationships you want and
4 `' x: f3 \7 K9 e( o4 u) r' ubuild the structure in the Item. The server will return the structure that follows the
2 L" n( ?, _. ^ J. Q K# p3 orequest structure.
: C% Q$ S j( {3 r! [' B4 X0 {This recipe illustrates several related concepts together, which are how to get a set
+ c) u3 ~6 E. g; ?/ f0 mof Items from an Item and how to iterate over the set, plus how to get the related & M( z3 y( G3 o1 B) U% E' k. E
Item from the relationship Item. 4 P9 V3 R0 L0 a9 J0 G, b! N! {+ Y
JavaScript
3 p7 G" x. J+ e J# e `var innovator = this.newInnovator();
. b" E1 S* q% ] / m9 B2 ~3 W8 x, A, L" G7 q
// Set up the query Item.
' c# [* h, C0 ^6 k! D8 h' v/ lvar qryItem = this.newItem("Part","get");
" Q3 L1 c: L" d& x7 z+ @1 ~ iqryItem.setAttribute("select","item_number,description,cost");
5 B5 v& ^( M# TqryItem.setID(myId); 8 `) P, A7 Y) m
1 a. o7 _5 D) h: @
// Add the BOM structure.
+ x# {; f# o2 u7 avar bomItem = this.newItem("Part BOM","get"); 9 \8 ^5 w/ P: L1 y- `" T: U- ]
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); * D' s. A. X9 F$ d9 @
qryItem.addRelationship(bomItem);
+ G5 |2 O; a0 s- M8 \$ E/ E ( f2 G# v# l2 e' e) j- Z, j
// Perform the query. " {" ]* K! n/ K |# W3 b
var results = qryItem.apply(); # u6 z& g2 n5 x" s* P7 c% q# k
r. T+ I8 {' |; e
// Test for an error. ( f( E: z9 R$ ~- U7 O" r e+ @1 S4 r
if (results.isError()) {
9 R9 g6 r" p a4 j3 m. I top.aras.AlertError("Item not found: " + results.getErrorDetail()); 7 c+ A2 Y0 C. o( y$ D s% e9 O
return; 4 E# K7 b) i& H" \
} 7 b: h0 S% K/ Q! M9 w" K* W5 h
5 n' `4 b! F' j- a% Z
// Get a handle to the BOM Items.
" S I% L; g! \$ X6 N# Z* Dvar bomItems = results.getRelationships(); ! N9 i# l* }/ H9 k! w8 e% H- N0 S
var count = bomItems.getItemCount();
' u3 M5 J8 U" Z- \
) B+ x/ J1 T6 r3 ?! h* S// Create the results content. % K! E, J" w8 `
var content = "<table border='1'>" +
+ z- Y: B; Z# i8 l: O- @ "<tr>" + , P" t' d. J$ c4 e/ Y) J+ r
"<td>Part Number</td>" + 2 q \" {$ F9 d3 n
"<td>Description</td>" +
# W& x7 M# P) ~ "<td>Cost</td>" + % w: k Z5 n/ p% K4 Z
"<td>Quantity</td>" +
6 {" t. I! O) [! N) |: k+ u "</tr>";
* Z: P- u1 Y' f* W5 S . }4 Q# P, _: q1 V. U F; Q: E+ m
// Iterate over the BOM Items.
+ `4 }7 v, _, ], F( o; Lfor (var i=0; i<count; ++i)
( R' p' }! P C{
' d- T( m+ Q; p- [// Get a handle to the relationship Item by index.
6 C8 ]/ {. C( A7 n var bom = bomItems.getItemByIndex(i); 8 a' e6 S0 p, x
// Get a handle to the related Item for this relationship Item.
' g5 g& r) H: M+ N4 O var bomPart = bom.getRelatedItem();
" _& [0 o! k) h/ [% U; @8 B
7 ~# q3 W3 w: `' D* V0 u) m6 Y5 U content += "<tr>" +
5 f' R1 Q. n" _+ ?4 O% W/ W# N) P "<td>" + bomPart.getProperty("item_number") + "</td>" + % p, {( u6 d# |+ {* I
"<td>" + bomPart.getProperty("description") + "</td>" +
?) k0 f# a7 b$ z "<td>" + bomPart.getProperty("cost") + "</td>" + / X$ N. H; o; |/ f
"<td>" + bom.getProperty("quantity") + "</td>" +
7 S) \8 Q" J ~& o, i7 y "</tr>"; 2 i, n; l; ~: H
}
' g8 k6 X. m, b! \$ s, ~return content + "</table>";& b) S% U: s" r) ~
2 X: n, ?% F! e
/ t$ M# W; o1 Y0 P- }1 m. a: i& y" e9 I5 H
/ _+ x' s0 C' s5 e$ \1 D3 H: O
C# ! e2 [' y1 a) j7 M, j4 e9 o
Innovator innovator = this.newInnovator(); # U9 o. \3 m' F' D% H( x
$ m& O3 N' \' k
// Set up the query Item.
e) n; j. Y& Z5 RItem qryItem = this.newItem("Part","get"); 3 m0 B s; c1 q
qryItem.setAttribute("select","item_number,description,cost");
2 N6 Z/ h( e. t9 H) g7 n, ^qryItem.setID(myId);
5 C+ A6 R/ f' ? 3 b- t/ L* a& e( p; v) Z* S. B
// Add the BOM structure.
4 T/ c- ~8 X! ~( TItem bomItem = this.newItem("Part BOM","get");
8 J8 A8 ?% Y( C2 V3 fbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
3 c3 i! ]9 n# {4 r' SqryItem.addRelationship(bomItem);
+ X9 d/ s* K1 k- ~; c( Y7 |
+ x% z0 X: O: W( M" ]// Perform the query.
4 t" N# I! \1 ]. S9 E% ^* bItem results = qryItem.apply();
5 ?5 F, Y& L; M9 I5 M( ?
1 A7 `: c8 X6 j# Y! v5 e// Test for an error. ( c& E& C1 x3 |, Z) m
if (results.isError()) {
% Y( S# M" V1 P return innovator.newError("Item not found: " + results.getErrorDetail()); ) L3 O, E" f- r/ P) @
}
' t# _; `- j8 R4 t8 p0 b
* `, S1 `8 C- s: i/ v: k# g// Get a handle to the BOM Items.
( q, n( Z! f" d* i: hItem bomItems = results.getRelationships();
) o1 L( D( h# I( Y4 Vint count = bomItems.getItemCount(); 7 f' Q) l/ O) [/ N/ e0 U
int i;
& h3 ?6 x( ^! a# ?' e
0 Z1 i& ^# K! t; ]8 N0 A// Create the results content.
4 \0 o0 C3 l" p" `string content = "<table border='1'>" + 8 |0 y, t3 Q; f' }, H
"<tr>" +
9 k5 U n' ^& O; y "<td>Part Number</td>" + 5 N, W5 M8 L6 O# y8 z) M
"<td>Description</td>" +
* L M8 x2 `2 ^ "<td>Cost</td>" + # i9 x0 _9 |6 ?9 ~/ ?2 v
"<td>Quantity</td>" + / ~9 Y2 r+ Y$ P e- Z5 \- Y
"</tr>";
" l8 {* q/ \$ h 9 a( L- U6 g2 d6 l
// Iterate over the BOM Items. ' p b% x: W1 _6 U0 w+ r$ V
for (i=0; i<count; ++i) h4 E3 @+ ]# W4 S& q' ^. t
{
* r6 q* P1 Z2 F s// Get a handle to the relationship Item by index.
% O! J# I @- G7 D Item bom = bomItems.getItemByIndex(i); ' V+ _* f7 L& z, W$ w
// Get a handle to the related Item for this relationship Item.
. ]9 h6 h# |# m Item bomPart = bom.getRelatedItem(); ( R: U7 Q! f, w9 J+ w5 \) ]
0 }# w' X) O, @3 \) N8 [% P h9 i
content += "" +
) d% e, s0 a5 @, k "<tr>" + 2 w5 P7 L, i2 `% V5 L
"<td>" + bomPart.getProperty("item_number") + "</td>" +
+ u" \7 k2 V& Q. U2 D6 ~ "<td>" + bomPart.getProperty("description") + "</td>" + 8 x7 A# I% B$ Y" D) z |
"<td>" + bomPart.getProperty("cost") + "</td>" + 7 x5 k- Q9 c( h5 {' u: E( c
"<td>" + bom.getProperty("quantity") + "</td>" + 3 ?: k1 Y6 v }, T- `
"</tr>"; 9 z a$ p5 j+ t: v
} ( G" u& y$ b5 i/ t9 m. Z
content += "</table>";
0 X! i' _ v6 k" [8 z- L: D . f6 W' c* P% M6 _
return innovator.newResult(content); . I# a2 ^4 i/ G' H0 n- s
- c6 R) ?7 K" P" Q5 r7 M3 b& u8 D8 Q9 Y j) F( R* S. t& @
# o, ^& V2 y' l! H9 j' F+ c7 ]
0 a2 d) {2 O3 f( a" ~+ J+ U- J( W; c) d5 G j
4 O( _; K7 g+ a$ R4 c; v A) L
9 B: r; `+ S @' r; v5 u, A Page 46
1 {: R* D6 d% s$ r, Z- G
5 u7 u% H9 q0 ^* w1 d' B" L; K& QCopyright 2007 ' F: N& C0 u. L7 ?2 Y+ K, T
Aras Corporation.
& i& N3 n2 J6 }2 ]# P) |. aAll Rights Reserved. 3 |# I: e$ p4 M( }4 V; t
VB.Net / h$ Z; R2 H) }+ q8 k# }/ m
Dim innovator As Innovator = Me.newInnovator()
/ z# g c/ D) \6 o' q
0 l4 L1 c2 W# ~2 d3 [# g: T: h' Set up the query Item. : B! v" t g$ ~8 ]$ \
Dim qryItem As Item = Me.newItem("Part","get")
4 w. U8 r+ p, t- C. ?, zqryItem.setAttribute("select","item_number,description,cost") - H. S7 T! x% T- ~/ ] G" h; f
qryItem.setID(myId) ' e7 _5 N( M: u$ e* l1 \; n
; k, H# F3 K8 I6 y1 a' Add the BOM structure.
6 T3 B9 y# [; kDim bomItem As Item = Me.newItem("Part BOM","get") ; J9 D' ^2 r( k" w# b
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! [ [8 w G( f5 y d( KqryItem.addRelationship(bomItem)
0 X5 t3 v ~6 A
6 j# z# [$ v6 G% ?' Perform the query.
' N7 K1 N8 }1 h3 b& CDim results As Item = qryItem.apply() - E0 m( l4 S" W
) B( X, q5 I6 N- u, Y! ?+ \' Test for an error.
5 I' b4 `8 x$ u/ GIf results.isError() Then # O. G+ f. i# d$ j0 h0 V. ]
Return innovator.newError(results.getErrorDetail()) " l! F3 z9 V9 m& ~, k
End If
W4 m; V7 x' L+ w) Y4 n
2 B' R, |$ p: N8 Z0 l1 p' Get a handle to the BOM Items.
/ x# {2 s/ y# o! y4 t2 yDim bomItems As Item = results.getRelationships()
% ~% p) |1 I5 w6 H8 W' z9 qDim count As Integer = bomItems.getItemCount()
2 p1 n" Y- q4 S# C! c- z3 X& fDim i As Integer
# L# {' d i# X9 y6 Y+ S0 ~9 b % O/ J& |; l G% C
' Create the results content. * X' E& U) `! C& w) r
Dim content As String = "<table border='1'>" + _
+ W5 c& H3 l. c5 O" a# \ "<tr>" + _
$ h* v5 _8 _; S! u7 Q "<td>Part Number</td>" + _
) h) I9 x$ E# c "<td>Description</td>" + _
h" [) i! ^* [: Y [7 [3 B2 K "<td>Cost</td>" + _
l+ q- h" `- y m0 y "<td>Quantity</td>" + _ : G/ W |5 N( ~; ^7 m; W. |
"</tr>" ! J C+ A4 C' ?5 @
/ l7 p, F. X- m( M5 c
' Iterate over the BOM Items 4 S* A3 b$ ^1 G
For i = 0 To count - 1 # j1 [/ `. ^# \7 y, p. ^2 N6 g8 G
' Get a handle to the relationship Item by index.
1 F0 e5 E5 M0 i0 q. \/ ^+ c3 W Dim bom As Item = bomItems.getItemByIndex(i) " V& [: L4 D% O4 y
+ U6 Q8 t0 @* k$ e, u! L' Get a handle to the related Item for this relationship Item.
0 g4 X# X* Y- [/ }: ~$ v Dim bomPart As Item = bom.getRelatedItem()
; r7 @* N0 u0 X% B* L3 y# l
; m+ o( Y: u6 b# M3 _0 f content += _ - E* y/ ~' d8 c- U1 A
"<tr>" + _ / z9 l S- u) Z% r
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
5 t& p* \% B0 i "<td>" + bomPart.getProperty("description") + "</td>" + _ : v' a9 P- m0 n A* g3 C8 k
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ' ^3 R6 j3 c C8 ^
"<td>" + bom.getProperty("quantity") + "</td>" + _ ! _- a$ V; \# }$ W
"</tr>"
% K% ?0 s6 A3 B, t8 N, ~, ~/ cNext
% u: b4 `: M% H2 W7 vcontent += "</table>" / C" X) Q" \. N
. @" }$ F0 M* ^. y2 _" QReturn innovator.newResult(content)
1 e" E z& q9 ~6 \- z* i5 d
: X' w- b! @% ?& u9 {, K |
|