|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique
2 T/ w+ [. ?7 `) s& q+ HTo query for an Item and retrieve its structure you build the query as the structure
% v$ |3 ]- Y6 h7 B$ E& D2 Q) l9 Cyou want returned. Use the IOM methods to add the relationships you want and . e) H9 z8 V7 Z9 L
build the structure in the Item. The server will return the structure that follows the
2 N/ z/ K7 z6 J* B: y; `2 j- f1 Yrequest structure.
) n! }3 l# G H5 uThis recipe illustrates several related concepts together, which are how to get a set
" \, {8 p9 e8 Q3 A0 n% B/ O. Pof Items from an Item and how to iterate over the set, plus how to get the related
) q! @2 x' U7 {* o; [6 iItem from the relationship Item. - D' q5 m; Z2 L! }, Z
JavaScript : @5 X2 p. j3 P, {8 ]1 x
var innovator = this.newInnovator(); ( U/ C3 g6 b7 L# `6 ?& H y4 g! i
. x& u! B2 z* n$ J" y0 g
// Set up the query Item. , S' W8 p! I9 S& l; W" D6 h
var qryItem = this.newItem("Part","get"); 5 U! W& O% z9 Q9 K
qryItem.setAttribute("select","item_number,description,cost");
0 E* d( Y$ I1 ~: y1 BqryItem.setID(myId); + v! l# P4 T4 |
, v# `& s. F8 x9 T
// Add the BOM structure. 0 ]. S% {. ]+ A- ~5 Q t8 M
var bomItem = this.newItem("Part BOM","get");
9 @8 ?7 U) R {; a8 @8 MbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 8 R5 e% z+ S/ n4 m
qryItem.addRelationship(bomItem);
7 g4 {. c2 D) E& D8 c- v + ]% l) @5 m$ d/ `
// Perform the query.
% \. m2 \4 s, R/ L0 E, [var results = qryItem.apply();
, Q& { {( r0 D6 G3 U1 R 6 ^9 [* s0 Y" {
// Test for an error. " q! t- }8 o0 w3 U. ^- P; ?
if (results.isError()) { , T" U8 c7 B* v$ k( g
top.aras.AlertError("Item not found: " + results.getErrorDetail());
& {: B* R# H9 G5 O) T8 N return;
9 {4 j" e9 s% B9 J}
( T# g) S( n) p% B. I 1 L6 D8 b+ H$ j/ W% W1 A$ w
// Get a handle to the BOM Items.
$ G2 C S& F& |$ d; C% a9 ^3 ~var bomItems = results.getRelationships();
' S# {$ u" l+ ?7 t6 {. ]$ rvar count = bomItems.getItemCount(); 5 }9 r: e7 F) E. K; v1 \
: B9 Q3 i: G, m) w0 q# e! j! D
// Create the results content.
8 \: `2 Z# u, h+ I" W" Jvar content = "<table border='1'>" +
6 }* m+ b( V# }7 y "<tr>" +
' P/ s8 l1 V M! L) d "<td>Part Number</td>" +
. z e4 L, O! } ?( A& h "<td>Description</td>" + + ]6 q9 P, l( i
"<td>Cost</td>" +
. }, Y8 G; O4 T, G" N "<td>Quantity</td>" +
( _ t0 V& p/ ^: _ "</tr>"; ' q. D; ^2 o% g$ T& m3 `
: e$ w+ N% D2 E# j// Iterate over the BOM Items. ' x6 O( Q' q$ S t( ]2 ?$ U& E
for (var i=0; i<count; ++i)
; z0 T7 ]. a% w g G) m{ - f, x% H6 J# V7 U/ m; z
// Get a handle to the relationship Item by index.
8 d1 c( Q& o" Y. W8 x2 G var bom = bomItems.getItemByIndex(i);
+ f; O3 \9 _4 O// Get a handle to the related Item for this relationship Item. " H! M j# w) j. q- Q
var bomPart = bom.getRelatedItem();
+ c7 g% y# _* b' ? . T: m+ R( [& X F
content += "<tr>" + 3 o& i/ S; r5 W' o. p* t
"<td>" + bomPart.getProperty("item_number") + "</td>" + 9 l* V# b# v- s# {, l! `& P
"<td>" + bomPart.getProperty("description") + "</td>" + ) ^+ o% a' O! [
"<td>" + bomPart.getProperty("cost") + "</td>" +
# Z4 Y: @1 u2 V, h( s& f "<td>" + bom.getProperty("quantity") + "</td>" + 4 [( p; Z' h' C: m8 b& k2 Y
"</tr>";
% @, @: B8 l& S}
, L; Q- }7 B! V, areturn content + "</table>";
/ u1 ]- E$ D4 a) o: ^0 s1 _3 O9 ?8 I- x9 D9 i% X1 s
) e, W/ p* P' _& `+ d. {& a9 d, |
- f( N( b3 b6 a& W# kC#
5 m, t$ L& U) _8 D y/ |/ o3 ?4 tInnovator innovator = this.newInnovator(); & Y5 {' J7 V( Y) _- T
7 W. S8 u% R% F5 X7 {
// Set up the query Item. 6 b' e. N6 o( _+ L9 q1 z
Item qryItem = this.newItem("Part","get"); 8 {* b v8 _, Q8 \$ L0 Q( v( \* e B
qryItem.setAttribute("select","item_number,description,cost"); ; L' \5 y, q; |/ G( ]
qryItem.setID(myId); 8 B& I9 w% V/ M9 E: v8 X' Z
1 s; g/ _# I! y
// Add the BOM structure.
4 T$ Y# o5 L7 ? _. b) v2 y3 }Item bomItem = this.newItem("Part BOM","get"); % |2 _7 f: z* b8 o, U
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
# R, ?2 X! [" lqryItem.addRelationship(bomItem); L* }- S7 n" a4 Y' | t
. L( t* }. L: T/ f$ u
// Perform the query. * L* r$ u# R7 ^$ T! T& B5 `
Item results = qryItem.apply();
. F0 Y# {, w! z/ K
# q& y' _* j! j- P ~" ^& o// Test for an error.
1 C' X2 u) @- M7 m) Z7 sif (results.isError()) {
0 D. f0 g& ^( G5 P: x return innovator.newError("Item not found: " + results.getErrorDetail());
2 l A, n' e2 h8 r- R7 ^} ( H! l s- b0 Y6 u; H! F* }5 E5 X9 _2 L
4 ~/ n; k; s9 M# r) h. X! G/ M
// Get a handle to the BOM Items.
L* P2 {4 [' U1 m7 ^Item bomItems = results.getRelationships();
* H0 Q+ B |# {9 S. N& q/ Iint count = bomItems.getItemCount(); + V: E4 F4 Z; r# ?% x1 v
int i; ! B' {1 `; S; X$ E' `
. g* {4 P# Y* j2 N$ Q, p5 P// Create the results content. 4 H3 p- [6 w j6 j" N
string content = "<table border='1'>" + * }! a8 T8 q8 i0 X
"<tr>" +
- |1 Q& W2 W' {& [$ w$ M& w/ R "<td>Part Number</td>" + 5 @- u! w: x: o0 U2 k8 P
"<td>Description</td>" + % J6 Z8 `& ~$ J' q+ [
"<td>Cost</td>" +
3 |/ J! [0 f$ }) R2 _ "<td>Quantity</td>" +
: q% N9 K n6 k "</tr>"; . L& j! A# m$ u/ i
, q' r, K* P) i" L- Y6 ]( C& {// Iterate over the BOM Items. , s2 S- [+ i! o$ i
for (i=0; i<count; ++i)
+ j. L, d" F* j1 n [{ ; z' W+ K2 ~' i5 X! U
// Get a handle to the relationship Item by index. # w. T; F+ o& G. j% `; B
Item bom = bomItems.getItemByIndex(i);
/ Q$ J8 b9 x" u* ]1 `( h// Get a handle to the related Item for this relationship Item. 4 l6 D7 ?/ {0 o8 j$ \* b
Item bomPart = bom.getRelatedItem();
. B0 Z& ]2 Y! v) ] , ]" r5 _& _' b0 M5 Z2 l/ ^
content += "" + ( h! X+ d5 U6 `9 r. ^7 r
"<tr>" +
( h: M+ z$ v7 j2 Q$ j7 h "<td>" + bomPart.getProperty("item_number") + "</td>" +
* @! A" B' a- V" C& c5 I) l "<td>" + bomPart.getProperty("description") + "</td>" + : R5 B2 H: L+ [/ X0 i" p- Q/ r
"<td>" + bomPart.getProperty("cost") + "</td>" +
9 w, `$ e1 T1 h& w7 i$ Q "<td>" + bom.getProperty("quantity") + "</td>" + * U" W& O3 p- L: _/ s
"</tr>"; " k. `$ y: }& H+ |; p
}
- o) w! ^$ ~ m5 V+ Ccontent += "</table>";
0 b# g2 [" h* q. |) I, y
* y6 _% Q2 i4 ?! Lreturn innovator.newResult(content);
1 |8 l- P9 U! f7 I9 m' i- k. l' ]. ^: b1 Q
8 V! z" A% X( x( @% B0 R3 E8 C8 q$ m! V. g2 L- H
8 u }5 O, j1 J% Y+ v6 ~# F& y, B3 p9 T8 \1 s3 ?; o
2 @' I; ~) l7 u, p# d9 P; c ; S7 _3 k G! P2 b/ U1 N+ j
Page 46 1 { `1 @. y% y* ]( ^+ o
8 r5 w8 M3 i7 s6 C% c
Copyright 2007
" Y0 ?+ D- u6 t" iAras Corporation.
5 i9 @, m1 T& b( XAll Rights Reserved.
/ [1 a! ^1 d7 q6 g$ h- H; LVB.Net
l! F. i- z/ e6 O: c QDim innovator As Innovator = Me.newInnovator()
: [8 p9 u# A8 P G; X% J . L+ O& x1 \ s( f# I; n
' Set up the query Item.
+ O; b4 W+ W; [! LDim qryItem As Item = Me.newItem("Part","get")
/ @' b4 t G+ R. g9 I8 `" LqryItem.setAttribute("select","item_number,description,cost")
$ P8 t1 o, V. {, g: I% |3 p+ `+ ^qryItem.setID(myId) 4 |- H o K# u1 U+ j" ]2 D9 v
8 o8 D$ E. X+ u9 Q! o8 l/ b
' Add the BOM structure.
1 R+ [& k! I( |! @Dim bomItem As Item = Me.newItem("Part BOM","get") 5 W; M [8 n3 C1 p- N2 _
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
, T8 ]0 b6 z2 P/ x8 uqryItem.addRelationship(bomItem) , H: n2 }, X2 h- f6 E
9 i" |2 p, e* S
' Perform the query.
9 L2 H9 H2 }2 E) w- i5 k' yDim results As Item = qryItem.apply()
6 P& ~0 Y; V% a4 u& d* q' y5 B 3 G: X. g" b7 t7 r" l3 I9 C
' Test for an error.
4 N: e1 Z& _* J$ h0 e% J" Q9 F, L9 fIf results.isError() Then ! v4 H# G9 @, v, D
Return innovator.newError(results.getErrorDetail()) % n: e7 V' z; C+ @6 P% m
End If
! M2 | A# d# Q; B; m, ^7 ~ # t1 S2 a7 K0 w X+ B9 A
' Get a handle to the BOM Items. ; k( V4 i% G: t N6 H0 X) I- p5 J
Dim bomItems As Item = results.getRelationships()
8 r0 m5 L4 { z! LDim count As Integer = bomItems.getItemCount()
, Q( c( f- S3 [, N V5 P% kDim i As Integer
3 s. g4 w) R" X: A 1 Y! A; r- F# \
' Create the results content.
5 J! ]# R9 z% QDim content As String = "<table border='1'>" + _
4 o! r% H$ h. h+ v- r+ a "<tr>" + _
/ D5 i4 G/ T. A9 f% t* s, M "<td>Part Number</td>" + _
d" e/ A0 W5 s "<td>Description</td>" + _
3 V. o- _7 f" f2 l "<td>Cost</td>" + _ & Z+ ~7 Z8 S* `) M
"<td>Quantity</td>" + _ # V5 A9 q& k" ~) L o* C
"</tr>"
1 i! G3 v0 d7 w# O' ?
9 q: a" I: ]# \7 j9 V' Iterate over the BOM Items
% R' S- Z/ d7 S. z; v% o7 LFor i = 0 To count - 1 5 x+ {% c6 S$ `3 q% q( Z' T2 k
' Get a handle to the relationship Item by index.
! g: t. F7 b5 L& _8 q( r; p Dim bom As Item = bomItems.getItemByIndex(i) + J/ R( A4 c: ]) A$ S/ D# g
: q3 q1 |) T B3 x& z' ]' Get a handle to the related Item for this relationship Item.
6 I- `' d: V0 ]7 b6 H Dim bomPart As Item = bom.getRelatedItem() 6 P, G/ }5 x# h
2 l( @3 h" l9 K, ` content += _
" u3 \# V m. d+ J/ @! q4 g3 ^: ^ }* e "<tr>" + _
* l$ b# f) ]% s; s: ^ "<td>" + bomPart.getProperty("item_number") + "</td>" + _ + n6 I. q2 p/ W7 ?
"<td>" + bomPart.getProperty("description") + "</td>" + _
$ I4 M; d: T# r "<td>" + bomPart.getProperty("cost") + "</td>" + _ - |& a" F" l: |) j3 B/ c" _: |
"<td>" + bom.getProperty("quantity") + "</td>" + _
5 D' @0 ~! W' z. [0 G "</tr>" 9 M1 F3 }3 k5 ?) r, p8 g {" |
Next
& F* B# s3 @) P" I. ^! bcontent += "</table>"
, ]4 U4 M9 Z% y' E6 c* n# r% O
! K# P6 \) h. L. [. L6 YReturn innovator.newResult(content)
" }+ z. s, A( y9 w) w8 I8 o- G' F" [$ T: \: w+ z
|
|