|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique ! O: B' _5 r+ a5 b2 v. X
To query for an Item and retrieve its structure you build the query as the structure - x: N# k3 U; P
you want returned. Use the IOM methods to add the relationships you want and t7 \0 |' r! J9 i% D2 f# W
build the structure in the Item. The server will return the structure that follows the
. o5 I, n% e# B( {request structure.
! r( Z# ]- ]. \ M" DThis recipe illustrates several related concepts together, which are how to get a set
. \- k2 c2 P+ S- V5 ? ~) dof Items from an Item and how to iterate over the set, plus how to get the related
' H3 w* _* p( d6 n; U9 E/ ?Item from the relationship Item. 0 H( o2 ?( ]. K! B
JavaScript 7 W( @' |, g5 A' J/ j" t8 Y
var innovator = this.newInnovator();
6 e% S" n9 B0 l' e( E% \: H
7 ?$ b$ t2 A- P* L8 {- v( H, _* T// Set up the query Item. # w6 ^0 t+ N% u& ^
var qryItem = this.newItem("Part","get");
0 _5 K) {; Z+ A8 ]qryItem.setAttribute("select","item_number,description,cost"); : a$ I* h' ?# g2 k$ b6 a0 W9 ? @
qryItem.setID(myId);
5 j1 P. p! ~9 S+ _) X - M; y$ y% h! r B* W
// Add the BOM structure. ; W4 B& D; e9 @9 p* M# K/ D
var bomItem = this.newItem("Part BOM","get");
! ?" ?% X+ N3 ?% o0 xbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); \4 z9 _' v+ k* `
qryItem.addRelationship(bomItem); ! A3 P7 r; \6 z, \
( F! R D( `$ ?+ s
// Perform the query. $ z" ^( O% U( k* d
var results = qryItem.apply();
8 |: L. R2 b7 ?2 s' E" S 7 m/ T: ]: M! e+ B, o& \
// Test for an error. 7 |" }6 [2 \& j/ K2 z- y8 D
if (results.isError()) {
& i7 S+ f7 N; U- v# Z* M top.aras.AlertError("Item not found: " + results.getErrorDetail()); % O0 q$ { n" i$ c' m+ ^+ {. B
return; + m- P' G) k, U* o$ N& N% S) ?- L
}
7 o6 i% I! ~8 I1 e! U
, N) `3 Q* C' s7 B+ n) G/ |* W// Get a handle to the BOM Items. 3 n( G4 @! Q5 e8 J
var bomItems = results.getRelationships();
7 a C2 G# ?3 s/ Ivar count = bomItems.getItemCount();
% }# O/ v7 Z$ V. D ' @4 ?5 R8 ]& b* a; f' ]
// Create the results content.
1 V$ k4 K8 D$ ^) X' |2 W Wvar content = "<table border='1'>" + # }7 p& i5 v- i8 T& O
"<tr>" + 8 Z4 J& @$ P0 Q, T9 v' n9 X& A( k
"<td>Part Number</td>" + Q/ e$ X) H+ Q7 B
"<td>Description</td>" + 0 u$ ^0 X- w: b) ^/ ?! g& r9 q
"<td>Cost</td>" +
) e A3 G1 Y/ v. P) j "<td>Quantity</td>" +
. [7 x( {5 E$ t& G; C- @ "</tr>"; 8 A+ w7 Y9 z) N3 n( ]/ ?" C8 D
, K; d% g+ _+ I0 e3 M5 {- B// Iterate over the BOM Items. $ d1 K1 G, {& x, O* E' V' \
for (var i=0; i<count; ++i) ' Y# b9 q$ S: y- i
{
7 ~' C5 v8 J+ j# {5 k// Get a handle to the relationship Item by index. ) X/ K3 Y# J; |7 R8 r* y- h
var bom = bomItems.getItemByIndex(i);
' C/ [) W" R9 C/ ~+ q// Get a handle to the related Item for this relationship Item. : L: o5 R6 o; U) `
var bomPart = bom.getRelatedItem();
* u A X( Q0 d . L7 ?3 A+ q% n* N& T" j1 a
content += "<tr>" +
. P* W$ s# |! u8 n. ~ t+ a( n& U "<td>" + bomPart.getProperty("item_number") + "</td>" +
! C, z/ U3 V ^" j "<td>" + bomPart.getProperty("description") + "</td>" + . T" N |) _. I
"<td>" + bomPart.getProperty("cost") + "</td>" +
1 k" L" [7 K4 E. r1 x, l "<td>" + bom.getProperty("quantity") + "</td>" + : c# v* G, t% h# O/ X7 k1 j% {
"</tr>";
- n6 q2 U; P) ~: ]5 ?}
9 q* t9 N; v8 h5 ? P( ^return content + "</table>";
1 r7 R5 r; T: P) v6 Q
; d1 F7 V5 l2 W' Q
3 Y7 o+ ^# j) E1 y3 i4 p0 @, d0 H I0 l ~# ~4 N
) [0 a* n+ p) y$ J7 U
C#
4 N. l1 g& a0 I, o( J" }& kInnovator innovator = this.newInnovator();
( V0 k* H7 z0 T! A& ?
9 q/ d' S6 Y$ x; U4 @, x! k// Set up the query Item. 5 c: ]9 B% o' X' Q. L
Item qryItem = this.newItem("Part","get");
: _+ N7 i7 Z! L3 ]# YqryItem.setAttribute("select","item_number,description,cost"); - R" _/ u2 b f
qryItem.setID(myId);
. J# [6 ?, b x1 E, ~/ \ 7 ?- ^/ p2 n+ N9 w
// Add the BOM structure.
0 {6 B/ x( {5 E- c, A) ^5 zItem bomItem = this.newItem("Part BOM","get"); ; t. B+ l" i* q! X- s& }8 a! f
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
0 D+ a: E2 m! d+ p, dqryItem.addRelationship(bomItem);
1 o# l. w, y7 X+ r* h7 c% W+ q ) @1 u$ {: l% f7 D
// Perform the query. ; U$ ^$ j. b, A; T+ S& i/ t
Item results = qryItem.apply();
; w2 J# g9 U3 [1 g% L
/ P, @* `' n2 H- m// Test for an error.
3 R' `! {6 R; }/ w/ nif (results.isError()) { $ u) a3 O+ m+ J4 U* ]4 y2 C
return innovator.newError("Item not found: " + results.getErrorDetail());
; x# B6 |/ {8 o5 Y5 {& v} 1 K% V8 S( _7 W' M
0 x: {( i( C4 {, o2 v: |
// Get a handle to the BOM Items. ( X* X+ ?; F, R) H5 G+ ^
Item bomItems = results.getRelationships(); ) k4 s; s2 k X
int count = bomItems.getItemCount();
4 |$ i* R6 O6 K0 V& }! Wint i;
, l% @, @# V# G$ w X2 v8 F
, i) a" K% I1 `# Z// Create the results content.
' P9 V' o/ x: x+ L$ nstring content = "<table border='1'>" + ) P$ r# n% Z6 p7 n* A, `" y
"<tr>" + + N# k, _. K+ ~
"<td>Part Number</td>" + # z- P/ T4 _' Q3 `& I& Q- j
"<td>Description</td>" +
8 o% t a6 S6 K# x "<td>Cost</td>" +
7 Z. V% b5 ?. }, C1 E" M8 V "<td>Quantity</td>" + ; {; m% a5 L; }- N
"</tr>"; " N3 v9 @/ o* J/ Z/ M- n) {
3 i, z4 U) v0 @: s5 u# I6 E! E9 Z// Iterate over the BOM Items.
" o1 U9 e$ \) |' A* a5 nfor (i=0; i<count; ++i)
( [8 `, S% J0 ?( Z8 E" D{
9 \+ R% A3 t& j3 s/ G3 D, _// Get a handle to the relationship Item by index. ( u+ j7 c' a2 \. J0 F+ u" c5 [
Item bom = bomItems.getItemByIndex(i); 2 `/ y7 z* L/ I
// Get a handle to the related Item for this relationship Item.
h- y7 C+ x. P$ q( H, d, B# S i Item bomPart = bom.getRelatedItem();
+ ^6 j5 m0 v8 i5 Y6 j4 _ ! i& G2 r/ |( C) E
content += "" +
2 m5 m% W6 b* O0 o "<tr>" +
+ |4 Y: \, e$ A* @8 h1 Z) [ "<td>" + bomPart.getProperty("item_number") + "</td>" + % k( z) o& X. y1 R, i, T5 D& i
"<td>" + bomPart.getProperty("description") + "</td>" + * Q ?$ d# O* \/ P4 c# q( E8 O6 A) [
"<td>" + bomPart.getProperty("cost") + "</td>" +
) {# S6 T% _( y "<td>" + bom.getProperty("quantity") + "</td>" +
( ~$ |7 Z1 P4 Z5 x% E/ w( I "</tr>";
& d( v$ Q1 V& j0 I$ o, F' h# T( I} : }" X% q% f# Z. L9 c2 V
content += "</table>"; 8 }2 `% A/ V e4 A! S# ?
5 }# d2 Q' a+ W# R0 |0 ~" a
return innovator.newResult(content); ; X" |1 J+ E# M
8 A" }) q8 s% v
" d6 G& o) ]8 w+ P
" i: s6 _( u/ _1 l$ X
. I: B2 a2 k6 {7 U. a* M6 f- ~( Z+ e' B6 d
1 p0 [2 Q6 Y {( n0 N" L
' t* S6 T( S. ^6 {' P# S) I' a; \ Page 46
* |& w& X! G* X0 A( T* I 2 G* t" k* H3 r5 V
Copyright 2007 6 @/ a% O+ ?* W( A
Aras Corporation. 1 W; W4 P z1 G: Q t9 v& Y4 F
All Rights Reserved.
- \- Q0 u; ^, X3 fVB.Net 4 g) y" m2 ?0 ?7 j3 `
Dim innovator As Innovator = Me.newInnovator()
0 r- l* i( h6 I; I0 P9 T& ~
' e& U* b% x/ X1 m4 T! [0 f' Set up the query Item. 5 B6 `# k9 {+ K0 {
Dim qryItem As Item = Me.newItem("Part","get") - R/ d& Y X! ]' c
qryItem.setAttribute("select","item_number,description,cost") ( i' ]3 |0 J; z
qryItem.setID(myId)
1 w. i7 g5 J( _! d) E # n' W$ ~# I; {2 |/ _. d Q6 q
' Add the BOM structure. 8 m; Y* i/ p; d7 K8 g- A7 f8 V1 f
Dim bomItem As Item = Me.newItem("Part BOM","get")
! x. v: A! ?6 x! A! X) hbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
& L, M7 S6 j- s) J& @* G8 lqryItem.addRelationship(bomItem)
* s1 M- ~6 g# x/ G& `) T& ^
8 u! L) G4 N' X% y' Perform the query. ( m9 ^/ U+ [9 c F! |. |9 Y
Dim results As Item = qryItem.apply() 2 l+ @$ ]$ a3 O% g. N
0 y4 V4 d' |" e' Z, U3 F
' Test for an error. + N9 g% S; M6 [/ \! C! c
If results.isError() Then
$ U0 H: e3 D6 s$ m7 s5 `0 o Return innovator.newError(results.getErrorDetail())
5 a, D$ L3 R P$ P3 B! Z2 mEnd If
1 C8 ^0 R9 F" N3 M/ ?( P* O" i # O$ o: n# U2 `& I0 m/ C/ C
' Get a handle to the BOM Items.
) R" j5 S1 S' d' `; y& [/ C& l2 PDim bomItems As Item = results.getRelationships()
3 r' `+ Y1 z) O a) [4 pDim count As Integer = bomItems.getItemCount()
4 R# h; n) k3 R* n* nDim i As Integer 5 u2 m7 }, @& S- K( M2 v
8 {3 K5 x" Z( z
' Create the results content.
; e2 F5 n, l5 d% E pDim content As String = "<table border='1'>" + _ / `8 N% ?4 }" x& E0 ^
"<tr>" + _
7 a2 S$ m, `& v" {' L2 f7 d "<td>Part Number</td>" + _
3 \' P- u8 k" q! | "<td>Description</td>" + _ . ]+ N4 |/ T5 \' N# A* B( T9 E3 T
"<td>Cost</td>" + _ % v2 G9 e5 W# t6 j
"<td>Quantity</td>" + _
! i# J# J9 w F6 o& H4 r "</tr>" ( |& I6 D7 M. q5 f$ T
4 G& }8 x& u3 a+ [) _! q8 ?2 Y' Iterate over the BOM Items
& P+ j, R0 E) {For i = 0 To count - 1
; R! l4 k* S1 D9 t9 u7 J' Get a handle to the relationship Item by index.
' u1 K+ R3 q- n5 V& i' ]& \& `$ d Dim bom As Item = bomItems.getItemByIndex(i)
\5 j1 `+ n1 C5 ?
1 U8 m0 ?; {) D( U; c' Get a handle to the related Item for this relationship Item.
2 I: _- c; x0 ]5 \7 Q Dim bomPart As Item = bom.getRelatedItem() / M6 Q# ], }& y) q- W4 K/ z
, O( b, D4 F2 N9 b
content += _
^$ v( X+ W& D8 [. u1 z "<tr>" + _ 7 X' c5 r1 P# j' C! o$ L- z
"<td>" + bomPart.getProperty("item_number") + "</td>" + _
% g1 @3 J% f) `4 r "<td>" + bomPart.getProperty("description") + "</td>" + _
( X; R/ b; z9 X N9 { "<td>" + bomPart.getProperty("cost") + "</td>" + _
5 G w4 D! q+ l( t3 I2 X. \: d "<td>" + bom.getProperty("quantity") + "</td>" + _
. Z) Q; ?6 c7 z: ~" _ u" S, C "</tr>"
- x% M2 N4 |6 L- F" V# {5 O, fNext
4 _* A6 e+ z, R+ [content += "</table>" . Z! ?. Q3 I0 {- E
* Z9 x9 k; F( {6 o1 q8 zReturn innovator.newResult(content) 6 F" ~: D" k9 ?
% |7 ], a$ o0 {4 U8 u( X* l+ [
|
|