|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
/ G) m6 W0 w* i' y! aTo query for an Item and retrieve its structure you build the query as the structure . u* |% j- d% `1 ^* z# h4 Q0 k" [
you want returned. Use the IOM methods to add the relationships you want and
; w6 R: E; Q y6 h( g1 t3 Vbuild the structure in the Item. The server will return the structure that follows the $ e8 S6 q0 `- [
request structure.
& o0 v; L: {6 v- L: [4 n9 [8 XThis recipe illustrates several related concepts together, which are how to get a set * N. d+ Z# Z9 V T2 w7 ~
of Items from an Item and how to iterate over the set, plus how to get the related
4 U5 U( p( ?6 j" c, Y: r& EItem from the relationship Item. 1 h$ h! A: o% t3 H Z2 P; }4 _' i$ ^
JavaScript
4 r; q! v0 w' M& l# C; qvar innovator = this.newInnovator(); . d- M: X# k8 b# m
4 Z3 u9 T8 b! B# Z// Set up the query Item. A L/ A, I* S
var qryItem = this.newItem("Part","get");
8 r8 v4 _- c: w! K2 n1 lqryItem.setAttribute("select","item_number,description,cost");
+ m! t& J% J4 t+ z7 w. ], L5 U8 D+ |qryItem.setID(myId); " b* K U4 B7 l4 i+ V" q
$ l% ^! x7 x \$ T& A+ q% a// Add the BOM structure.
# F- _" H1 j9 _+ Q- pvar bomItem = this.newItem("Part BOM","get");
; g: f' K& H9 M1 V" F; ]9 F% }# NbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ) P7 r) k! S7 I, \4 I9 y
qryItem.addRelationship(bomItem);
+ n/ {8 m9 K( h1 K" f" {
- r5 ~4 D" i. ?// Perform the query.
/ I3 L* K6 A) U* _( N0 ?! Nvar results = qryItem.apply();
0 x' W6 P( f* Z1 {! Q
! y) G7 Y8 v. }) {, I% y9 V* P% ?// Test for an error. ) [7 R" A: |7 ~, m7 S3 ?- c: L `9 I" L
if (results.isError()) {
( C# u1 A. ~" W' X7 r top.aras.AlertError("Item not found: " + results.getErrorDetail());
7 @: p% t1 h3 g# J% c return;
/ F/ ~" y" i/ m# n; u9 [}
- F( Z- w2 u! y" T
8 @& H8 J& N/ V' {// Get a handle to the BOM Items.
( c9 g, x# e; l! d svar bomItems = results.getRelationships(); . j! ~3 E8 {( v5 P
var count = bomItems.getItemCount();
- z- B4 V. P! J8 }
; I b; K4 m6 w1 ~& {; @. u5 j7 _// Create the results content. * \% ^9 D/ @' {( N
var content = "<table border='1'>" +
% E0 \ }* ?1 Q "<tr>" +
' z( u. X5 ^: S6 H "<td>Part Number</td>" + 8 Q/ Z0 O3 ?& h9 b5 k8 u
"<td>Description</td>" +
+ }2 U7 U2 Z, n5 O7 q# K8 ~ "<td>Cost</td>" + : l& y% [. h# {4 [3 U6 h- a
"<td>Quantity</td>" + 4 N8 Z! R7 ^- g$ I: U' Z* v
"</tr>"; * x# W( y+ T% [6 z7 ~
- `/ L( Z: D/ D+ {+ U// Iterate over the BOM Items. . I! x @5 K6 B% w- ~/ P' `! j
for (var i=0; i<count; ++i) 3 H( U1 _7 H* K
{ + C8 r e! p' b
// Get a handle to the relationship Item by index. * P( `( Z7 \( o
var bom = bomItems.getItemByIndex(i); 6 y' N$ F# F9 c; D, j" g) }% A
// Get a handle to the related Item for this relationship Item.
|7 q# I9 s/ Q) Y/ O5 B+ S var bomPart = bom.getRelatedItem(); / |5 y% n, v m2 v3 G5 l: m
- `: X% @# \4 K( E% L) A V content += "<tr>" + ( _; ^8 a8 x- F. t
"<td>" + bomPart.getProperty("item_number") + "</td>" + + n! {2 j' i6 t+ {! }: y
"<td>" + bomPart.getProperty("description") + "</td>" +
/ l+ a2 `/ K3 \4 J$ ^ "<td>" + bomPart.getProperty("cost") + "</td>" + * N9 k6 I0 Z6 f, F: n
"<td>" + bom.getProperty("quantity") + "</td>" + ) k6 o. u# ] J+ X, x
"</tr>"; 8 J( S5 |) X8 J+ Q& ]( Y
}
5 g. {. y+ N8 h* Creturn content + "</table>";$ ?, W/ h3 d3 A" m9 i5 }$ G
* Z7 p3 n$ T, }2 X
% w( R+ \) \7 m4 t0 N
+ z4 B/ c4 ]& `. o4 ^/ C3 p. l4 t5 H5 `9 `0 Q5 s' a5 v2 ~: \
C#
0 i, h8 o) n8 ]Innovator innovator = this.newInnovator(); : V( |: u0 U0 q8 q& s+ ?
4 V/ ?. R8 f+ f9 A" E) S( P$ Q% t
// Set up the query Item. % d2 ^% }! R4 o/ Q1 o( w+ f
Item qryItem = this.newItem("Part","get");
B4 a, r. h! J; @qryItem.setAttribute("select","item_number,description,cost"); 2 D1 Z9 ^) o- G+ A4 B7 D
qryItem.setID(myId);
( D" B! ^% Y' o% D* A1 B0 z+ N* x % o$ F, @3 E. u. Z A6 D
// Add the BOM structure.
. t" @ ^* c5 I. i2 C# wItem bomItem = this.newItem("Part BOM","get"); ; l! e) U' W4 z3 }/ B( |5 ~ M) @
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
& d6 U7 e/ S& ?$ j# Y, ]qryItem.addRelationship(bomItem);
1 X; Y4 V a4 O3 T5 @ 4 K" s) L9 z; ?! s. y' g ~9 C
// Perform the query. $ X8 g* k) q: g; L
Item results = qryItem.apply(); , ]$ ^/ F; T/ r$ o: @
$ X7 ]7 l4 ?/ N& t5 M- ?
// Test for an error. 3 k2 f+ i+ w2 n2 R. N' g
if (results.isError()) { 4 y$ ~4 x5 f$ f/ U- e: D" z) T6 k
return innovator.newError("Item not found: " + results.getErrorDetail()); * d9 e; i# \0 q6 L# s
} & m5 d. ]$ ^5 C' i
' U# Y6 d6 @* K" t$ h& J
// Get a handle to the BOM Items. 0 v3 D4 B" U7 |3 e& D: ^$ \" e. \
Item bomItems = results.getRelationships(); 2 ]$ g& a% g9 |; t( U6 s. I& U6 B
int count = bomItems.getItemCount(); 7 O+ ^: @* Y& t! j) Q
int i; 8 n: _4 L, G6 v/ ?) o/ N
4 q( J: l4 T- D' E) O: @- b. I// Create the results content. ' q. z: B9 Q3 Q/ S
string content = "<table border='1'>" + 1 h* a8 h' t2 m. [2 y* }
"<tr>" +
, {6 g: ?3 [( T* O5 W7 T "<td>Part Number</td>" + 4 z9 e5 ~3 K# p+ q1 y$ x1 j
"<td>Description</td>" +
/ F* c% K7 T5 V; l' O# p. J( R2 k! u "<td>Cost</td>" + 1 n8 k; }3 _7 [! o# m0 K
"<td>Quantity</td>" + * @+ `- ?$ d) D, V3 E2 m- f+ ~( A
"</tr>";
B% g3 i- f. V- l
5 n; c5 U$ W& t: K7 c// Iterate over the BOM Items. ) k, S0 X! G2 H) a
for (i=0; i<count; ++i)
! {8 E) R) l3 C. C: e{ E& }: }) W! P4 ]( M. E, [
// Get a handle to the relationship Item by index. ; f$ G0 F K+ o# A5 V8 o
Item bom = bomItems.getItemByIndex(i); 7 q( p+ m8 h0 C2 Q/ \3 ~
// Get a handle to the related Item for this relationship Item.
, P4 }! I5 w* \/ H3 j) @- ]6 |3 b Item bomPart = bom.getRelatedItem();
, l x9 d0 h4 E' ]! |, U6 Q: [
' U6 U5 k" ~/ a content += "" +
$ L% E: F5 j( F* ` "<tr>" +
' f m+ k- C8 E5 U. }4 R- j" @ [ "<td>" + bomPart.getProperty("item_number") + "</td>" + ! A3 ?: _: E' X
"<td>" + bomPart.getProperty("description") + "</td>" + , {9 L6 e8 x, ~
"<td>" + bomPart.getProperty("cost") + "</td>" + # T7 o8 i3 n/ z' B) a
"<td>" + bom.getProperty("quantity") + "</td>" +
7 @; O8 ~5 k, S4 A4 G$ ]6 i$ K "</tr>";
. Z$ \6 g. j+ S6 e% ]}
$ N% F2 n1 J; Q) q5 p! icontent += "</table>";
$ n0 V3 K6 M" p0 U: ]
7 P2 Q7 d7 g4 d4 F6 m4 Mreturn innovator.newResult(content); ! _) Q3 R% N, v7 }
1 p& n' f# ?7 O+ b* C. ?3 q% c$ e- I" \& R* [+ u; l9 y
' O1 t- s! T; [ `: j4 S
3 k3 s. s1 g7 [
8 Q- M7 Z$ H% w, Q" l
' Y7 T, k# `! t: G
# ]( S) Z4 ?: b$ y, W Page 46 , \6 Q9 I g: T: n: F5 k8 ~
; D: |3 L" Z: ^) _; w- W7 i
Copyright 2007
. B) p3 [7 u3 qAras Corporation.
F; |0 J/ e3 T, i/ F! y- IAll Rights Reserved. 9 _0 ?/ Y5 Y/ d* l
VB.Net , |$ V+ u: O7 y0 a. \ |
Dim innovator As Innovator = Me.newInnovator() % ]. J! W" X0 b+ T4 {5 `
" z _8 m5 v% k" o4 ` Y' Set up the query Item.
$ k0 p5 n7 ~ h5 l+ i9 z: nDim qryItem As Item = Me.newItem("Part","get")
7 M& G7 q9 g2 s, pqryItem.setAttribute("select","item_number,description,cost")
2 \, W, X$ {2 w3 XqryItem.setID(myId)
7 b$ Q' S. s5 X+ c4 r$ L1 [
- v/ L$ {+ R; C' Add the BOM structure. 2 X) \* f1 V7 u- |8 [
Dim bomItem As Item = Me.newItem("Part BOM","get")
8 _) }4 D# a9 s# Q7 lbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") / e8 x9 U: [5 b# j' G& ~" H6 H# Z, i
qryItem.addRelationship(bomItem)
9 Q7 R2 Y, M: l; F) |$ N9 ~
( Y% e, [7 H# w) T' Perform the query.
; ^' I$ B# h. D- RDim results As Item = qryItem.apply() " P C$ h1 j2 l- v0 y
0 d( O: [4 F+ j1 Z: @! Q' Test for an error.
$ ?& m" O$ o# N! c. d" TIf results.isError() Then
K) D( u& z+ x: r$ H6 P. z Return innovator.newError(results.getErrorDetail()) , L/ j. n# j: ^2 j# p$ Q0 l7 q
End If , Z p$ O6 M& L; S
; s; J7 N* ]% j. J
' Get a handle to the BOM Items.
' P! H; O+ U, b- l; z0 D( LDim bomItems As Item = results.getRelationships()
4 V( o9 k6 z) n" L( [2 ADim count As Integer = bomItems.getItemCount()
2 r1 ~% X7 H* mDim i As Integer
- q5 I. P6 k0 F+ Y& u 3 L: ]& Y& F9 U0 L$ N! q
' Create the results content.
) `2 k9 P! @; j9 Q( U4 {" zDim content As String = "<table border='1'>" + _
! e4 M: R& l/ `3 {8 R6 R "<tr>" + _ ( U, M! G0 [1 a, z
"<td>Part Number</td>" + _
- d$ [* A7 C. F5 c, C) [ "<td>Description</td>" + _
. [9 J ~* i0 E, R6 B9 ^1 S "<td>Cost</td>" + _ 6 @! O5 r' H" U
"<td>Quantity</td>" + _ + h% e) v2 g% C9 s- r
"</tr>"
4 _" H/ F: ~1 @% [( \; _1 a
. U$ v& W5 C) B# m6 e' Iterate over the BOM Items ' i$ e* P- D0 w5 F* K" z" ?
For i = 0 To count - 1
" {+ r2 I3 J( ^4 G5 ]. p' Get a handle to the relationship Item by index.
7 l$ s3 f0 y) u7 G8 O Dim bom As Item = bomItems.getItemByIndex(i) , P: k' i6 h9 a+ x( X
* } x- H. O7 f' B' Get a handle to the related Item for this relationship Item. * q, p% M' Y0 G. M
Dim bomPart As Item = bom.getRelatedItem() 4 g- w2 ] q( q C
+ E8 m! z# k* _ h( [' g$ }6 R content += _
. W! {3 Y. H2 M& I! ^ "<tr>" + _
2 `& M0 @0 d5 ^% G" z; @' _) m& E( ~ "<td>" + bomPart.getProperty("item_number") + "</td>" + _ & P2 o# F) [# |
"<td>" + bomPart.getProperty("description") + "</td>" + _
% U: _/ F. E* C: `$ r3 b "<td>" + bomPart.getProperty("cost") + "</td>" + _ 0 q4 m+ V O7 N; V0 u
"<td>" + bom.getProperty("quantity") + "</td>" + _
0 i( \4 J7 s$ _- X' m8 u "</tr>" 3 t7 G* R9 v( z) Y( U: }) u
Next
) e. I% F @6 ycontent += "</table>" % a% D0 F0 A% f( I
: E# ^1 r8 Q; P4 aReturn innovator.newResult(content)
$ ]9 U a3 k- t% |: ^9 Q8 u" s3 i2 q3 T$ [6 N P
|
|