|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique - k1 A2 Y( S. a% ?* ^
To query for an Item and retrieve its structure you build the query as the structure
( U, R3 h" Z& M8 O0 e& A V/ F) syou want returned. Use the IOM methods to add the relationships you want and
: E' V @* v( {: X/ Bbuild the structure in the Item. The server will return the structure that follows the ' j* _6 R. I7 `1 r" f
request structure.
8 i" s( E% B Q3 R; q, ^+ X& N) NThis recipe illustrates several related concepts together, which are how to get a set $ c& w7 ~( G& ^/ p$ T6 X
of Items from an Item and how to iterate over the set, plus how to get the related
% A" B" @* E1 P2 H0 c% A/ AItem from the relationship Item. # p2 k. p9 u% t/ [' h
JavaScript , u# `8 [. f: a" E& U6 Z
var innovator = this.newInnovator(); # O. A9 D* s" v+ S
; S j& O# u* E9 W3 h+ Z$ U S// Set up the query Item. 2 b9 t- x8 E& o z
var qryItem = this.newItem("Part","get"); / d/ `8 T. L4 l" g, L) t. p, H
qryItem.setAttribute("select","item_number,description,cost"); , i1 G4 O5 A- J" r1 |
qryItem.setID(myId); % T5 u- k) W. `, w+ C5 l
3 n- c! B6 k! P5 N0 |// Add the BOM structure.
9 z- v2 ?$ r- _( l' J0 b0 P( Qvar bomItem = this.newItem("Part BOM","get");
( l5 A; `8 ?5 ]: r4 H; q0 qbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
. ?' j2 A3 U* o' S6 qqryItem.addRelationship(bomItem); $ n- i7 K$ ~& x
1 y: `- Q5 ?* ~: j
// Perform the query. . D: v! J8 {3 S c0 _
var results = qryItem.apply();
+ B) | F4 |5 G" P; r 6 O* x4 |$ E$ B7 d) o) v: l
// Test for an error. # \/ [! m4 \- Z2 Q2 I: `
if (results.isError()) {
- ?6 u! Z& x( r/ I" u' p8 j top.aras.AlertError("Item not found: " + results.getErrorDetail());
& g( w' d7 W! n5 Q+ n return; ! w; [% G' J8 C; }" ^
}
+ y9 }" M# S3 @5 _% f2 t( u
3 H8 l: y0 C- z; J// Get a handle to the BOM Items. 9 t' {2 x/ A3 N4 `, V# u K
var bomItems = results.getRelationships(); # ?5 ]1 P( a( Q% x! [ t, G
var count = bomItems.getItemCount();
* } |0 F8 d3 l, r9 X% U
' H8 H- ], y2 D0 N// Create the results content. 5 t( n# f! w# E7 x7 C
var content = "<table border='1'>" + 1 H* s; i$ m7 z* C- i
"<tr>" + : S0 R1 C: `* N3 L; I
"<td>Part Number</td>" + - G! D* \4 {- m$ i7 n
"<td>Description</td>" +
" x1 n9 B+ {) n, ? "<td>Cost</td>" +
+ g8 C, u7 e0 ]; v( j( Y6 V5 `- k# F "<td>Quantity</td>" +
7 q5 A0 q6 ^ g "</tr>"; . d2 t3 N, k! y3 V( q8 u2 e5 G% q
( h' J2 x' D& ^$ |0 I$ @$ ~// Iterate over the BOM Items. / v! R: m1 T5 f# b
for (var i=0; i<count; ++i)
, u( `8 y$ s5 u{ ! w' R& Y$ ~) A8 i; n6 ]
// Get a handle to the relationship Item by index. & F" \7 u) K1 r j. l' r+ K
var bom = bomItems.getItemByIndex(i); 9 l2 I1 ?0 i4 [- I+ j4 n. v1 `
// Get a handle to the related Item for this relationship Item.
3 m% R+ t% b- L: T9 Y% G% b var bomPart = bom.getRelatedItem(); 2 D8 j& C. }$ e& p3 G6 x. M
0 y. Q: `) O, I9 x( J
content += "<tr>" + " C, Q0 t9 C& ~
"<td>" + bomPart.getProperty("item_number") + "</td>" + 6 G D$ w! M) i1 ]; k8 T5 K% v5 {
"<td>" + bomPart.getProperty("description") + "</td>" + ) y) v9 F+ I" w
"<td>" + bomPart.getProperty("cost") + "</td>" +
8 l7 K% X4 S) M% b" T; c, G "<td>" + bom.getProperty("quantity") + "</td>" +
% l# a& C8 O; ]6 C4 n "</tr>";
* t0 \3 G( c4 P) Q$ G% q} ; C, E6 g" q* e8 S9 u9 j+ k
return content + "</table>";# x0 r% j$ b' }& ?
) F7 t2 w! i7 o0 o( y' f- @4 w+ t/ \. ?2 n$ S& T# r
" v1 t- l- B# t, l- `. d5 a
$ ^8 X9 R$ J2 U( ?* n7 lC#
' K: b4 E) J5 ]Innovator innovator = this.newInnovator(); * s, `+ Y1 @! L I& o2 X5 W |8 z
9 H% \. |* B! K9 D// Set up the query Item.
& L0 ~& ]9 U- P" Q. I+ PItem qryItem = this.newItem("Part","get"); & ]' M2 u- h8 c9 K+ J; l" `
qryItem.setAttribute("select","item_number,description,cost");
/ j/ J3 u4 u" {8 v+ QqryItem.setID(myId);
+ ~% z, Y% O' O0 y 8 ~% w' X m* k
// Add the BOM structure.
* h1 [$ W9 ~( M- uItem bomItem = this.newItem("Part BOM","get"); " M: f$ G% j5 J3 {, M
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ! t* ^* P( t/ b3 K) n$ m
qryItem.addRelationship(bomItem);
$ L& q0 }5 Q: W$ E" m
( ^+ u l9 z2 U- s// Perform the query.
# m3 ~* T0 S$ x4 b$ k7 b/ p. DItem results = qryItem.apply(); / N* m9 `, _* K! g/ @* D9 ^0 Y
( n {5 T8 Q' u) D) M6 R
// Test for an error.
5 j& ~3 h! {+ e5 B2 h2 p, Uif (results.isError()) {
- v) ?+ h3 [: n$ t9 R8 G return innovator.newError("Item not found: " + results.getErrorDetail());
# z) e2 M, E& [4 p( e} / z3 B4 V0 n3 r3 `7 Y! v( E' Y5 Z) R
- v, r# c3 S! |// Get a handle to the BOM Items. . i9 L) E& X- e
Item bomItems = results.getRelationships(); & m: n( F" t; k5 J
int count = bomItems.getItemCount(); 9 g4 ]' }3 H- ]3 m
int i;
9 q$ i; V8 }# |+ }9 V
/ \2 p- k; z- ?0 }; G// Create the results content. + i" _ a+ C, F$ o; Q/ n
string content = "<table border='1'>" + 8 I/ q( v Z2 u* D
"<tr>" + # T; V/ ^0 N7 }, |# I
"<td>Part Number</td>" + & P; k: u' d: P- z1 P2 R5 M$ ]9 T
"<td>Description</td>" +
2 T8 a7 Z3 q% c6 e2 P2 p0 h "<td>Cost</td>" + ' q; V3 l1 @+ e/ \
"<td>Quantity</td>" +
% a! [' r* k5 b* P "</tr>";
& E; |: {& V4 ~; g0 O8 W ! @/ R: e6 x% d5 ?
// Iterate over the BOM Items.
9 K, g. A1 G8 R9 e8 d" s+ _for (i=0; i<count; ++i) ; d2 X. n. Y+ u& H0 G' ?& P& ~
{
& B3 @- O: i! \// Get a handle to the relationship Item by index.
0 X" ^0 H; S# V, s! x Item bom = bomItems.getItemByIndex(i); 7 v- t" h) k, V# ]: | [
// Get a handle to the related Item for this relationship Item. ' U- y9 x( i* A x# H
Item bomPart = bom.getRelatedItem(); * G. y% }: C8 U k" Y1 J: S
8 @1 q N, T4 ~
content += "" + & S; Q. q: g/ u" s9 }- C1 B9 Z! }, V
"<tr>" + ) A+ A. g7 \5 {; n0 |5 u4 u$ V, e, O
"<td>" + bomPart.getProperty("item_number") + "</td>" + F6 h- p( w# O5 ]1 R O
"<td>" + bomPart.getProperty("description") + "</td>" + 2 W' A% ]1 [2 U3 f. L
"<td>" + bomPart.getProperty("cost") + "</td>" +
# Z5 x3 s/ c$ s. P "<td>" + bom.getProperty("quantity") + "</td>" +
' Q& \* B* \# E' y8 \+ u) R "</tr>";
$ i/ _9 n. A) O. c* z# |8 g} : R! ~9 R7 O+ N' z4 s/ O1 i/ y
content += "</table>";
7 e& \! A! u. \& H9 K* D3 J
. O- r6 e [9 j$ ^return innovator.newResult(content);
1 f% `4 N/ J j( r3 i6 B; L; c1 i4 @5 S o0 B( V1 G a7 S$ U
0 c5 \& u: I1 j+ L/ A) \/ {, [$ V( S, {5 o
3 P" c6 ^( k& h% o% m- @/ B: `* m4 C
' E( J: f+ u* [( }/ r; k. N+ T0 G* f8 M4 e6 N' S* M
. g. e; h* D$ t2 I
Page 46
6 R- a& c; ?% W) n8 [
( ?! e& T: c T% h# `2 S n+ P# [" wCopyright 2007
& v0 j9 z) E% ]7 H- `Aras Corporation.
5 w& c8 |+ {( N7 j3 l3 L1 T$ E5 \, \, EAll Rights Reserved.
" ]$ S# t0 ~! n# PVB.Net
. V9 n. h L+ A H: BDim innovator As Innovator = Me.newInnovator() & Y* q: j8 b# t& K) |6 c/ ^6 y- A* A
# I% F# O8 W" O, Q' Set up the query Item.
# `* l+ Z. {9 H4 L) g ADim qryItem As Item = Me.newItem("Part","get")
# S1 I8 v& w: n/ s6 ~5 e3 r( `! u) `qryItem.setAttribute("select","item_number,description,cost")
# ~3 Q' F0 l/ v. gqryItem.setID(myId)
& f% c8 V# @0 X' N , r" P3 P& d# P/ r# u* e$ y1 E
' Add the BOM structure. * }: b2 ~: V3 Z2 e& Y6 Z" [
Dim bomItem As Item = Me.newItem("Part BOM","get") - c/ e6 n8 t7 S+ Z! S$ F9 K
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") e+ X/ [ K: W7 G$ L' ]
qryItem.addRelationship(bomItem) - G: M# P `, ^9 a" a
: r0 \( b [+ Z" N; F/ F) ?! D
' Perform the query.
4 Z0 P' ~0 r$ @Dim results As Item = qryItem.apply()
" ]. W6 o7 M2 }; O( m3 j
; W6 R8 @+ ^2 B( E. B. ^0 Q' Test for an error. 1 i0 t' G' T- x7 L+ W7 U
If results.isError() Then
1 p- e, a7 n- k0 c: i Return innovator.newError(results.getErrorDetail()) 1 v/ W+ ~8 n! m6 N. q% Y
End If ! B- ^5 D4 X" y. `3 j; t
* d1 U1 f8 ^! s6 n E. J' Get a handle to the BOM Items.
0 ]% x. h: B- Y! f% j. N2 pDim bomItems As Item = results.getRelationships() ^" @. u1 p- U: |8 [
Dim count As Integer = bomItems.getItemCount()
( w) i- M/ X3 W+ ^: F5 eDim i As Integer
, p. d4 V- Z% ]' ~ T0 V - F4 [# f; g7 z9 }$ e" ~) M" h5 t
' Create the results content. . C& C6 I' r* S
Dim content As String = "<table border='1'>" + _ 6 t5 ~6 D- j- c
"<tr>" + _ / B0 |2 i) s5 S, _! V$ O) d8 S
"<td>Part Number</td>" + _ $ [1 f. x! i" ?; n
"<td>Description</td>" + _
' A7 k/ F+ m( u1 Z9 H "<td>Cost</td>" + _ $ W+ \2 Q2 @6 L% Z2 ^0 V
"<td>Quantity</td>" + _
1 V4 r B( Z7 J% Q2 ]4 x0 A7 G% W "</tr>" / N2 K( x1 m* u. S o+ U
+ B v9 I' Q/ f( S, q( R8 j3 q' Iterate over the BOM Items ( s; L1 A: V$ `7 z
For i = 0 To count - 1
- g: Z& D& ?4 K0 K* E" t' Get a handle to the relationship Item by index.
- W: b0 W7 d, L; D/ o Dim bom As Item = bomItems.getItemByIndex(i)
! U% s+ U0 {$ B1 h" ]) V
& M5 n, E6 ~7 o7 l' Get a handle to the related Item for this relationship Item. # |6 z' n8 H; Q* m4 C6 X# k
Dim bomPart As Item = bom.getRelatedItem()
; u* [2 G2 P7 i& e: Z
: ^/ ^% u9 i: @% g& R; X6 D; g content += _
. [: g; d& C' |" C+ ?2 b "<tr>" + _ & I9 |9 W2 |2 d' o1 s6 Q8 c
"<td>" + bomPart.getProperty("item_number") + "</td>" + _ 0 F* {0 n5 C" o$ m# G) C
"<td>" + bomPart.getProperty("description") + "</td>" + _
& w E6 F. [+ S "<td>" + bomPart.getProperty("cost") + "</td>" + _ / G( Y6 u+ @2 H- W; p- E
"<td>" + bom.getProperty("quantity") + "</td>" + _
, Y& S1 f7 F# X3 F "</tr>" 2 }; o9 N/ A5 F% R) W2 I8 r/ T
Next + j2 a) s2 {# ?- v% C5 @8 E' Q
content += "</table>" 5 K3 ^" `" G5 h# E) F5 K$ c- P
* @" B7 ~( v$ W& r2 ^Return innovator.newResult(content)
6 Z& c! w* |, I# M$ V/ c1 |' Q
|
|