|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
+ F* r7 ]' e/ N) n- R0 `: GTo query for an Item and retrieve its structure you build the query as the structure ! U2 t, F2 i! k
you want returned. Use the IOM methods to add the relationships you want and : o& V' ^0 r) q) [* z0 k
build the structure in the Item. The server will return the structure that follows the
. t; ]1 ^% r2 drequest structure. ( L! y* u# {5 M( Y1 ]6 p
This recipe illustrates several related concepts together, which are how to get a set 4 k/ N" H, Y6 h+ y' r" w
of Items from an Item and how to iterate over the set, plus how to get the related + X* J9 c9 K: C" C* q
Item from the relationship Item.
3 Q, H# g! S0 W6 {# q4 ?JavaScript
7 O5 ^2 v5 s7 C9 _var innovator = this.newInnovator(); 1 B* r/ i% x. n4 f0 Z
- l5 @- O+ A8 A. }" j* Z; E4 K% ?
// Set up the query Item.
3 `8 t; y0 t% V% `5 C/ p. ?# A. T# ?" `var qryItem = this.newItem("Part","get");
- V, C3 ?% O( L5 @3 |- D8 KqryItem.setAttribute("select","item_number,description,cost");
& `) ]# O, Y+ G. UqryItem.setID(myId);
$ n/ a5 a! |+ Y6 N
! |( F' X/ O0 m6 c// Add the BOM structure. 9 F7 c2 {) g' @ c( F! I
var bomItem = this.newItem("Part BOM","get"); 6 S% t+ K" F6 |* \. ` g3 s7 R/ n
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
% J, e3 @2 M$ R! Z# qqryItem.addRelationship(bomItem); 9 O! @3 o, X8 Q
& I w! W) @) n5 [
// Perform the query. . R* w, O4 i: f4 \1 `/ e
var results = qryItem.apply(); - y" O% G4 K+ P4 [- T6 z
6 k. _7 p) E' o8 ?$ u// Test for an error. & ?4 r, c" C: s1 a. J5 u( n
if (results.isError()) {
1 o3 U3 g/ E; B top.aras.AlertError("Item not found: " + results.getErrorDetail());
5 M. o! _+ M0 l8 a( I9 P' x return; ! J* _. S2 A5 J, \
} $ F8 Z& \1 z5 F% P
& o" e7 n0 A7 @0 x" M& w
// Get a handle to the BOM Items. : A" g' W, Y1 W. {8 z* N4 e2 s
var bomItems = results.getRelationships(); ; F' ]- A2 Z% l: h+ E9 ?3 k4 {
var count = bomItems.getItemCount(); : i; `/ U( u5 o2 N
( h- G+ x9 @! a8 X5 @0 |// Create the results content.
! \' @) ?- L; n7 yvar content = "<table border='1'>" +
- P- m q2 A# z "<tr>" + & ?5 v1 c1 w, R' G! l2 R% F R
"<td>Part Number</td>" + 7 T) T: c. X. O% B o( A$ ]7 E
"<td>Description</td>" +
# Y' p& |5 _0 c m "<td>Cost</td>" +
( ]7 [# c) D6 C' A1 @% ]1 z "<td>Quantity</td>" +
2 L2 b# S. ?* @6 G7 P/ m "</tr>";
0 H! ?2 _( Q' e0 s2 f f" m
: ^& ?* P7 x0 V+ X# k! J// Iterate over the BOM Items.
' Z1 ~7 s6 p* e( N/ [for (var i=0; i<count; ++i)
# A, w: ~0 ]( s0 s; l{
o1 R" S9 S* |( R// Get a handle to the relationship Item by index.
% l+ C- ~9 v! t/ h3 U j# p2 U/ ? var bom = bomItems.getItemByIndex(i);
Z- b: @5 Z- x3 n4 A5 k// Get a handle to the related Item for this relationship Item. 5 `) N% Y" L, P* w+ t7 ?
var bomPart = bom.getRelatedItem();
; r ~" _: z Q& k& k" `' w7 Y6 S D 1 c/ j t1 q2 o# ]- I
content += "<tr>" +
( \. y3 v6 Y" A7 g& U "<td>" + bomPart.getProperty("item_number") + "</td>" +
9 _& ?! M+ Q4 z0 e! ^ "<td>" + bomPart.getProperty("description") + "</td>" + J% B6 A3 _: L$ G
"<td>" + bomPart.getProperty("cost") + "</td>" +
3 b9 F$ R; j* ^' Z' u) q7 s+ N "<td>" + bom.getProperty("quantity") + "</td>" + ! } A; x: x* E2 g) o) N) `
"</tr>";
/ s- n+ b( @. Y; c* }# ~}
/ {" R# p; F: N. Ereturn content + "</table>";0 b( I' [. \! W9 J
; B& G, x, p2 A' z
9 q( y& [. d4 v" b
4 {: O" j' k5 b( y4 A$ d6 t+ ?" T) {* E( k$ E6 }" k) h
C#
7 p- n& ]& d |# u% q {* PInnovator innovator = this.newInnovator();
) ?0 v# R0 y! ^( D y1 y+ q( T* ~ , k% o) G( r6 T# X
// Set up the query Item. / G5 I0 y( T3 i" u. N" l. z* r
Item qryItem = this.newItem("Part","get");
, f1 m3 t2 }. A9 GqryItem.setAttribute("select","item_number,description,cost");
6 i6 J' g0 L$ b& tqryItem.setID(myId);
' \& ~, ?" }) [ % j% Z4 I# J6 g* S8 m
// Add the BOM structure. 4 ^, [! u7 \9 k* h, s
Item bomItem = this.newItem("Part BOM","get"); 6 _. ~& g( d# n1 y; l. v
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); & n2 b# f2 g( o: D, K
qryItem.addRelationship(bomItem);
/ s4 R# }* d2 P& ?" S. i3 |& @: K ' F/ ]5 |( D9 ^1 |7 V9 Z2 v7 g2 _
// Perform the query. " i) K$ D# a! S4 b( m! Z$ d
Item results = qryItem.apply();
/ I4 P7 ~* ~1 u1 s1 p
9 g) [& e" g" n; n0 Q// Test for an error. ) m7 K" n! P- e' H/ s/ L3 N
if (results.isError()) { 7 M/ F0 ~( v+ X% v
return innovator.newError("Item not found: " + results.getErrorDetail());
% `# R' a4 v! e/ J8 S, P" W2 o6 Q}
+ e) ?! g) R$ x* v
: ?5 T5 }6 O# I- X! T% O/ I// Get a handle to the BOM Items. + A, @; ~; O, ]+ M/ m
Item bomItems = results.getRelationships(); . V; |: B; B& V- |
int count = bomItems.getItemCount(); 7 ^! s# m+ H( b Z
int i; 8 C# }4 x+ A+ j: R6 U- ~( `
; n% C; @& G- j/ T// Create the results content. ) \# D$ e1 m- _6 V
string content = "<table border='1'>" +
$ D& T, q8 U- l' w& p9 G5 L "<tr>" + ' K$ `2 J @+ x6 Y$ [
"<td>Part Number</td>" +
6 Z' Z* k# N3 Y( A& R "<td>Description</td>" + 6 I4 u6 o% [* x6 k+ _- c2 j/ L
"<td>Cost</td>" +
- Y- B4 g( J8 O6 I9 T# ], @% [ "<td>Quantity</td>" +
% r2 q; K Q9 A "</tr>";
: x) t8 l* f0 Y# x+ n. |! R, | p' Y5 W1 q8 g5 F2 _5 ^
// Iterate over the BOM Items.
) @' t7 v5 Z6 {( M) X6 X( A" |for (i=0; i<count; ++i) 3 }3 [* W" h0 z% X, x
{ ! {- D; V* q# q) \
// Get a handle to the relationship Item by index.
4 [# x* B% v& _9 c Item bom = bomItems.getItemByIndex(i); ( Z- e x h5 ?' m8 G
// Get a handle to the related Item for this relationship Item.
/ h+ N: ?/ U, ~# K Item bomPart = bom.getRelatedItem();
# W" G( F9 }# \2 ~
8 W+ S5 p, j' H4 T content += "" + # V1 c: l/ W/ B' W: Q
"<tr>" + 4 J8 M4 X0 y" d' K5 l: J) P
"<td>" + bomPart.getProperty("item_number") + "</td>" + . N0 _# Y/ ?8 \6 D: |+ a4 x: ?
"<td>" + bomPart.getProperty("description") + "</td>" +
0 E1 _' L r; }2 g/ Y; h "<td>" + bomPart.getProperty("cost") + "</td>" +
7 u, T; o! D- m6 W8 C: x "<td>" + bom.getProperty("quantity") + "</td>" +
- T& [5 @$ ]' j2 \1 i "</tr>"; , A/ l* Q5 B/ K; s
} 4 B2 U! u. m" f( g3 u3 W1 N
content += "</table>"; 2 @8 K$ G& k+ T9 l. {* z4 u: B7 x
5 r. V9 w: R9 U
return innovator.newResult(content); + B" g& T' G8 M9 ~' N0 K
, _/ m# B8 }) Q1 b X8 y( ^. x% j8 E
" @1 |8 U+ Y: V- c5 X% r" w4 U. k% F
9 R; L- M4 w1 z* m, H1 c9 l/ A. c1 I4 o. V& I9 D
0 u9 p. _3 W n' v: L
w) D3 L) k. R# {- n
Page 46 $ b0 h7 D4 O) e( m/ E
# g7 v5 y. ?: \. [3 P: _5 B5 p* T
Copyright 2007
0 C+ l/ S7 d4 P2 T# }- hAras Corporation. ) y* w+ p8 P1 }7 D' t4 c0 L
All Rights Reserved.
0 c, ^. m5 ?1 g+ xVB.Net ! ]# j* G3 D0 B: h; r
Dim innovator As Innovator = Me.newInnovator() 8 ~" y* x U* B4 C
4 @ z4 u* n% q& e. A
' Set up the query Item. / l1 a/ T8 N* t. K# ?
Dim qryItem As Item = Me.newItem("Part","get")
0 R/ B- {( M1 l. A; g6 WqryItem.setAttribute("select","item_number,description,cost") . a( B2 n" V" s. g
qryItem.setID(myId)
9 i1 {( |; {; K. q2 w , ^, N+ z9 y+ G7 [' [
' Add the BOM structure.
' g8 _% j: b+ ~1 `9 i+ TDim bomItem As Item = Me.newItem("Part BOM","get") 4 V& l9 h2 S" U# \
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
7 z3 J5 O9 J0 p! K2 S: L* I$ @qryItem.addRelationship(bomItem) . |, {; m+ U! u6 x/ G5 u# ^# j
" x" k( E& m) D- v- V' Perform the query. / \. c1 x9 J; h, x
Dim results As Item = qryItem.apply()
, j& n- L& r8 e/ O 5 E+ I" M3 h1 r4 I
' Test for an error. 4 G+ J# p( r/ ^
If results.isError() Then
1 c) z: P" i! r% {6 {$ B. ~2 ]0 [9 ` Return innovator.newError(results.getErrorDetail())
2 Y! C6 u# j: }* Y W) }End If 9 z5 W7 Z, O7 H# v/ N! e" E
0 b* G4 Q: }, L, M5 _9 L q
' Get a handle to the BOM Items. 9 |0 q8 t* T1 y' b* \( e
Dim bomItems As Item = results.getRelationships() 7 r- z- H1 T o' H2 i
Dim count As Integer = bomItems.getItemCount()
/ Q+ N% ?% n0 s( @5 gDim i As Integer
0 j: n1 ~: i1 U7 y3 q 1 k9 W3 O3 o% b: O
' Create the results content. ! |9 n" Q$ ^2 y9 b; d. p
Dim content As String = "<table border='1'>" + _
# T: [* Z$ L6 p+ |2 X# a. i$ ] "<tr>" + _ : @" m q0 L8 V; @) \* T
"<td>Part Number</td>" + _
5 b" [! \" O; v "<td>Description</td>" + _
! }( z5 R1 a, E* f: s8 t "<td>Cost</td>" + _
: u N# P; L, y1 [! k. Y "<td>Quantity</td>" + _ % h6 e/ T3 q' k; f
"</tr>"
4 K6 g" w3 |6 u+ h1 A& ?7 I
4 J9 Y4 T1 {& r4 V! M8 W, ?' Iterate over the BOM Items
" p( Q$ u1 B! U6 T1 m1 |# JFor i = 0 To count - 1
5 M d5 ?! }* h8 q2 P' Get a handle to the relationship Item by index.
& A/ t' {. C- ~ Dim bom As Item = bomItems.getItemByIndex(i) . @# g6 Z! G/ C9 X8 o1 g
3 u- W5 x4 I0 w$ C" o: O2 C- l' Get a handle to the related Item for this relationship Item.
& Z: S" `2 K. r/ Q( h' j1 ^ Dim bomPart As Item = bom.getRelatedItem()
3 d; K( k( ]6 O# b5 a2 D
; t0 _% l; [, i1 A content += _
/ f4 Q: N [$ p( ^1 o, ^ "<tr>" + _ i2 B" I" M5 `1 ?
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
# k1 X+ t, i8 L7 O# a0 p! w) y "<td>" + bomPart.getProperty("description") + "</td>" + _
4 g q9 [- H0 j9 Z6 r3 U. R b "<td>" + bomPart.getProperty("cost") + "</td>" + _
% i$ z# C7 [# P0 i1 [( g7 f "<td>" + bom.getProperty("quantity") + "</td>" + _
8 f6 y0 A8 Y1 ~4 v" G "</tr>" 7 j# H$ m/ ~/ {% d/ |
Next ! H1 \. N; q, i. M/ Q( x% t& o0 j. R
content += "</table>" - G3 I( P E1 e+ j C' \
! g6 p# \ ^* y- C8 a
Return innovator.newResult(content) $ \, o: {! x* [6 L: L; r( X
3 s' g1 ?5 H7 A+ Q |
|