|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
Technique
1 V Z2 W* q5 v- `6 fTo query for an Item and retrieve its structure you build the query as the structure / i U& A+ _/ |- I2 W1 Z* {
you want returned. Use the IOM methods to add the relationships you want and
! d2 V8 Q; ]( d5 A: [! X' Tbuild the structure in the Item. The server will return the structure that follows the
" i# w8 n" B6 b$ L; `) xrequest structure. ' K ?: l' U4 K s! n& @
This recipe illustrates several related concepts together, which are how to get a set ; v. n8 y2 l/ e! T. m/ m/ G3 j
of Items from an Item and how to iterate over the set, plus how to get the related ( R5 d" k5 j2 O+ R' l" Z0 `6 }' B7 i
Item from the relationship Item. - ?8 ^( B* y+ r, r8 q% S
JavaScript
# a4 N7 d0 B* a% ~, yvar innovator = this.newInnovator(); 9 m" m: W/ u8 Q. I& v2 O
) f$ v8 m& |( h( O$ t& i
// Set up the query Item.
9 X' c/ }+ s+ c& Q+ M& t9 zvar qryItem = this.newItem("Part","get");
9 d5 D0 p [; T. o( x/ a. [: A4 IqryItem.setAttribute("select","item_number,description,cost"); " }( }5 w. S0 c/ g) r
qryItem.setID(myId); : \; _& i1 d9 B
* O6 W) ^0 |! t+ W1 g// Add the BOM structure. ! ~9 R5 M5 t; Y+ [
var bomItem = this.newItem("Part BOM","get"); $ f+ W1 Z: I, B8 d
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 9 `$ ~0 g- c: A
qryItem.addRelationship(bomItem);
2 p2 H# A9 j+ j, Y7 |
' } f [ A: F" Z' s// Perform the query.
" X, O9 ~" ?9 C. H( o' h, Hvar results = qryItem.apply();
! P; J& @; H6 ?: o2 P. L8 l
+ y9 }# D; z% h* @4 R// Test for an error.
" v, t5 {% O* z9 hif (results.isError()) {
& e, n! s' k8 G# c top.aras.AlertError("Item not found: " + results.getErrorDetail()); - _/ b' S( u7 x: |' @* |
return;
" ?6 Y' V! n: F}
# C6 o- ^5 R0 k' R) U9 r- l
9 T# L m" L9 f) [, O) W// Get a handle to the BOM Items. $ l* {0 p6 Q7 i W
var bomItems = results.getRelationships();
! R! ~/ k0 e$ Gvar count = bomItems.getItemCount();
6 L" a7 |6 y5 y$ ]% Y- k" a , i( i& }4 a0 m2 S3 V7 b; T4 Y4 }4 q
// Create the results content. 1 T, f0 S& U; s0 z7 u i
var content = "<table border='1'>" + . b3 W; d) f: M# J0 k0 i! m
"<tr>" + ' @! w/ u: W5 Z# U4 n. j
"<td>Part Number</td>" +
/ ]# u2 N* j/ D6 e" [5 F% b "<td>Description</td>" + . p( Q# R/ m) I
"<td>Cost</td>" +
& i6 |; i0 H$ G0 m% | g "<td>Quantity</td>" + 1 u% n$ c9 w7 h x
"</tr>"; ( F! ~/ w' Z' N$ `" Q
1 N' r; J1 i0 W+ K
// Iterate over the BOM Items.
/ D& \( f \, z, Sfor (var i=0; i<count; ++i) - A& e0 z) \8 ]. v
{ 0 L" j' Z) W' n8 o/ H% G- I
// Get a handle to the relationship Item by index.
9 t2 K8 z. e: ^' L. x var bom = bomItems.getItemByIndex(i); # F0 v) ?6 O/ x- C1 ~
// Get a handle to the related Item for this relationship Item.
* L' |7 a m* d! T, B var bomPart = bom.getRelatedItem();
# L. Q7 q0 |! ~4 u 2 d3 B4 b- z6 ]4 {4 W. Y+ Z0 s
content += "<tr>" +
! I+ `$ i* L6 k. Q$ r$ V "<td>" + bomPart.getProperty("item_number") + "</td>" +
. e: W/ L/ X1 J "<td>" + bomPart.getProperty("description") + "</td>" + & l( C# W# U) d" \- f9 _
"<td>" + bomPart.getProperty("cost") + "</td>" +
0 }' O& {# O2 A$ I4 ~6 B$ ~: } "<td>" + bom.getProperty("quantity") + "</td>" +
0 C% A7 s8 \' p" {2 l1 X" ?( o) r3 | "</tr>";
3 H8 p! y, h/ i+ z0 x8 j* d}
# n! X. A+ F* B# t0 e+ K6 M o' {2 Areturn content + "</table>"; ]8 X5 V! v" ~: n
2 ?. s0 ^+ f8 q4 q3 b! w. o6 L2 h- }0 T1 v9 n# x' N4 {0 ]9 E
% u/ v9 v6 Y' P2 s6 E( L4 m* r7 ^! ]9 S+ e9 _' m c; \3 f/ d
C# " Z/ U1 g# I! R# O9 \( a9 q# N: A
Innovator innovator = this.newInnovator();
& R. n1 j4 N1 @" T / A$ s& X( W2 B& h' U
// Set up the query Item.
1 ]% E) e, m1 p4 U* \: b' h3 ^Item qryItem = this.newItem("Part","get");
4 z# W5 h, s0 [ @% BqryItem.setAttribute("select","item_number,description,cost"); 1 C( G) j. z6 g
qryItem.setID(myId);
" y4 {+ x4 l8 A' V
& X! c3 H5 J2 P4 p// Add the BOM structure.
$ L1 u/ ^" _; @$ S# p5 G% \! N, fItem bomItem = this.newItem("Part BOM","get"); " r" Q$ O; c. ]& w$ g
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
% B6 C" g$ C# b/ x) cqryItem.addRelationship(bomItem); . b1 ?, B+ b' V3 G* M& _
; \# @9 w+ [: U* l% g// Perform the query.
- r+ h$ _+ K8 hItem results = qryItem.apply(); : Z p9 ?9 t- Z' T3 e7 l( e% O0 a
0 m) O- J( z; K: T4 L( [
// Test for an error. 3 ^( A2 P4 q6 J- w8 x
if (results.isError()) { 7 ]3 F1 t3 v- L1 H% v
return innovator.newError("Item not found: " + results.getErrorDetail());
6 i2 u1 m& f" w& r+ [ S} 4 @. d& Y4 m; H/ ?! t$ }# O& _8 S
5 l9 E* q, A. e9 z
// Get a handle to the BOM Items.
% c( y* N8 F F2 v9 fItem bomItems = results.getRelationships(); 9 h7 d3 f1 I% ^) V& V/ u- _! E% L6 Z
int count = bomItems.getItemCount(); 2 Y- H+ f" D- j& {' h' m' `: \( C
int i;
( h) j$ K9 p v4 n4 o
% V* S7 D8 \6 X% w6 j// Create the results content. 7 k+ V7 E- F3 q. A0 i0 J
string content = "<table border='1'>" + " Z: Z# z5 j" n" {% A3 D, `2 ]
"<tr>" +
% f: s: W; }/ b2 g "<td>Part Number</td>" + 7 y& n* r( R/ L- f
"<td>Description</td>" + ' v% R: I9 [) S" q: p8 \, _
"<td>Cost</td>" + 4 Q) C, e- V+ m. X0 M
"<td>Quantity</td>" +
+ F/ n0 q9 B% v( t# U "</tr>"; 6 y f+ D5 O2 J4 G( S- @. n
5 W+ s6 M1 C% y" V
// Iterate over the BOM Items. 8 d$ A0 r: @7 o. t
for (i=0; i<count; ++i)
. L5 Z8 X! j7 w8 I( x! M{ ; ^) }. R1 P) ?! {: s
// Get a handle to the relationship Item by index. / S$ F' d% X1 D5 A3 \+ U) `
Item bom = bomItems.getItemByIndex(i);
" n5 a9 E4 F2 ^// Get a handle to the related Item for this relationship Item. * s5 J; P, o* \( g+ w( J
Item bomPart = bom.getRelatedItem();
% `( e, A& | X: [
: f2 S$ Z) g6 L; b7 |3 X content += "" +
, _; O' e* t( O# ]0 S "<tr>" +
7 m$ H' r. a4 ] "<td>" + bomPart.getProperty("item_number") + "</td>" + ( X4 H# p2 g# s4 n
"<td>" + bomPart.getProperty("description") + "</td>" +
. G3 s( X' c9 C "<td>" + bomPart.getProperty("cost") + "</td>" + 6 T+ N9 j2 |% ?8 c$ R2 d
"<td>" + bom.getProperty("quantity") + "</td>" +
3 c! y8 ]( Q8 v; g; C "</tr>";
5 U; @: [% @& x0 N5 h( K}
1 q. H7 K6 v4 a* |content += "</table>"; / M( Q7 j* d* s
4 _8 o0 G/ ?" l2 u0 R V/ Kreturn innovator.newResult(content);
0 |2 k9 h, t% v% n$ M$ D8 O
8 s e U& k" S" h) e2 D
2 \6 D& j, }3 z! {) H' q4 J/ T! U* `2 K) s3 L$ z2 K! S
$ L' Z% a1 I# j8 D) p, q3 a! m/ P$ x4 G4 h1 G
0 F' q0 ~7 u$ [. f
- i& K5 o0 Z" \! q+ \+ ? b7 B Page 46
' q5 u( z) D6 t4 b o/ g3 V ; s0 R# y- J, R' G
Copyright 2007
( r2 H, M0 v0 s0 eAras Corporation.
1 p5 Q1 |# V0 m+ ^All Rights Reserved. ' P4 m& { G8 i
VB.Net % }5 e6 L0 n2 c i L: B
Dim innovator As Innovator = Me.newInnovator() 9 ^$ G( x: G w% U4 L0 |& l
* K9 w/ ?% F2 B0 n8 d% W' Set up the query Item.
* a8 z. I) p0 u4 h+ u1 f/ w+ p; |Dim qryItem As Item = Me.newItem("Part","get")
$ C ?& Y! w& N* n. T5 lqryItem.setAttribute("select","item_number,description,cost") - @+ v- p" Q8 ]! G0 i7 ?
qryItem.setID(myId) , e/ U/ u- ^$ o+ f: Q
{3 u" a' B% x( P( R2 t' Add the BOM structure.
$ T6 r7 ], k/ q& B/ TDim bomItem As Item = Me.newItem("Part BOM","get") + {, ~/ }8 K( r/ l) x
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
3 d; b, X0 K+ pqryItem.addRelationship(bomItem)
$ g% P" s5 ^, F; j' \' K" u
: y9 g. @9 X0 \8 s' Perform the query. , e& a5 _% z6 S/ C6 u6 @
Dim results As Item = qryItem.apply()
2 b* A, b# Q7 x8 ^3 f8 U1 Z+ q
5 [ e, g3 V8 h+ `7 f7 W3 A' Test for an error.
1 H6 ~7 y9 t8 c7 ^& u3 N9 e% @If results.isError() Then
) l6 K$ y6 W: C8 R8 G6 o; w Return innovator.newError(results.getErrorDetail())
0 o! Z& v1 w( C/ XEnd If
+ h+ F, W K4 j4 W M ; g* k8 k, T8 Z" r6 S7 N1 a/ h
' Get a handle to the BOM Items. # l$ M( Y: {) ^7 a
Dim bomItems As Item = results.getRelationships() $ K. \, Y' S6 L* ~; L) ^$ `
Dim count As Integer = bomItems.getItemCount() ( O* M! Y1 ]4 J9 m, z1 c/ ?6 g% z* [
Dim i As Integer
; [3 z. x' x9 `4 M
. q+ t! g! M3 U: A5 i' Create the results content. ! C$ s {5 c) X D k
Dim content As String = "<table border='1'>" + _ & o( S8 C( R/ q+ N& ]
"<tr>" + _ , y0 L; @; j. y: I: P; ?
"<td>Part Number</td>" + _ # W+ |, b5 m ? `' F% N X$ P
"<td>Description</td>" + _ $ G, ^! R2 P7 M0 q! V
"<td>Cost</td>" + _
) }- z- b9 S; E% T! {% V5 ` "<td>Quantity</td>" + _
% S( ?% V# i$ B$ x "</tr>"
' i" E" Q1 I \ 6 q7 F0 |/ ?/ i' r0 I4 U0 D9 Q
' Iterate over the BOM Items
4 M s: Q9 k' eFor i = 0 To count - 1 $ X) X @' b$ Y6 _
' Get a handle to the relationship Item by index. 6 P) k* y5 c+ z- N; y9 x5 i
Dim bom As Item = bomItems.getItemByIndex(i)
8 `' Z$ c* h8 S! V; b2 M1 Z & a; }$ a. I( \! W' H
' Get a handle to the related Item for this relationship Item. % u$ H1 P" M& T! d# {# E! i3 I
Dim bomPart As Item = bom.getRelatedItem()
. l! x& P. M2 o4 l! a 9 P0 |4 D9 T: d/ B& r2 F& K2 R Q
content += _
+ `: f0 w0 ?- A! H+ z* [$ ? "<tr>" + _
! n$ U" |8 [$ z e% y# B "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 1 i7 T5 \0 u9 a+ C/ ]$ Y) B
"<td>" + bomPart.getProperty("description") + "</td>" + _ 4 ]" b: M0 a8 d( |4 I
"<td>" + bomPart.getProperty("cost") + "</td>" + _
( S/ W3 B; X. a7 @, E( P8 s "<td>" + bom.getProperty("quantity") + "</td>" + _ . {$ @3 b' M1 {4 ?% q) c# [* b0 T
"</tr>"
. e) y; k! I3 n+ M0 VNext ( E7 q6 d, s T
content += "</table>"
( }/ T0 x+ l- x% } V
" y1 `) l" J, g2 \, {. c- oReturn innovator.newResult(content)
6 l! P, {" @8 H- F3 H5 ]
, p% I' `* Y: V( i4 Z7 a |
|