|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Technique * D4 J: o; e* l
To query for an Item and retrieve its structure you build the query as the structure
# E1 q( f4 p0 R' V8 `7 X1 |you want returned. Use the IOM methods to add the relationships you want and ! `9 x* ?8 N' s, K. B
build the structure in the Item. The server will return the structure that follows the
: Q5 k/ g6 ?$ t/ rrequest structure. - l& _; s5 I: T; |
This recipe illustrates several related concepts together, which are how to get a set
: m* P' l3 B9 K9 eof Items from an Item and how to iterate over the set, plus how to get the related
& L% k4 t: w9 W, ZItem from the relationship Item.
" `! c9 L7 P) J/ XJavaScript ' d' B4 z5 L! d: e
var innovator = this.newInnovator();
- w$ l( k3 m! T! ~/ Y. z
% z O# U6 u; j7 E// Set up the query Item.
f- i/ R( |& A) Z. {* Q6 lvar qryItem = this.newItem("Part","get"); # ]2 l# r6 n% o
qryItem.setAttribute("select","item_number,description,cost");
; ^# D; J/ G2 m& y$ ~qryItem.setID(myId);
& K1 }( M, `2 V" Q
- |( g1 b9 W0 E/ L5 |. `// Add the BOM structure. 2 e U5 M- e3 L& b! w- q5 b" ^
var bomItem = this.newItem("Part BOM","get"); ( z' |9 O% r$ t. o% m
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ' X2 L' I7 K8 H# g. t4 E. [
qryItem.addRelationship(bomItem);
% M0 ^6 I! p( j+ h; k3 A9 w 7 ^/ c6 Q" T: O
// Perform the query. ) h; y% R! B2 G$ K/ Y
var results = qryItem.apply(); 1 ~! |1 B% {- O& ]
: J9 n5 Y# T5 Z3 i6 p2 P9 N
// Test for an error.
) v7 h: J( c/ [& J' R* J, Q. z# `if (results.isError()) { , W$ U) m) L9 V9 e/ @
top.aras.AlertError("Item not found: " + results.getErrorDetail());
# c- |1 U- P( C8 ~/ f7 X& g return; 3 r$ S$ N0 {) X2 ^% ~7 Y8 y; x
}
* J& R$ P) C2 U! v2 Z1 H
) a! D2 L/ @: G. h- X// Get a handle to the BOM Items. % |2 s) D* A- t
var bomItems = results.getRelationships(); $ s1 G# j! a6 O5 \
var count = bomItems.getItemCount(); 8 q( C3 t" w+ z6 m: M# W* r
/ C x- D+ l! m7 c
// Create the results content. 8 q2 d3 e9 K! M3 J6 F
var content = "<table border='1'>" +
4 U! f! o x [$ C' b! q$ P "<tr>" +
; B! s* C- F. i; B' }: E) e4 X "<td>Part Number</td>" +
, g% N$ }- \" G2 M$ u) F9 r( E* I "<td>Description</td>" + ! ^1 n. h- i$ T
"<td>Cost</td>" + ' y0 K2 C9 l6 K. F/ s
"<td>Quantity</td>" +
% ]2 i/ i2 k; z# M8 p "</tr>"; 0 I6 C/ F( z5 V5 c9 h+ X
" M D2 G5 g1 j7 e, \9 ]' G, i% x3 x// Iterate over the BOM Items. 1 S2 Z8 R, j6 Z6 m8 q
for (var i=0; i<count; ++i) / P; }5 P% g* p E
{
' R( O4 Y/ J) W0 T t// Get a handle to the relationship Item by index.
: J- b4 { S' I3 @4 C S var bom = bomItems.getItemByIndex(i);
, ? E! {% L9 c// Get a handle to the related Item for this relationship Item. 6 @4 d% P6 m" p! t
var bomPart = bom.getRelatedItem(); , @+ W5 v- K- {5 z8 d2 V+ ^
1 p- m% o- D' `/ H9 Z# _1 I
content += "<tr>" +
5 t( k; {3 n7 g. v, g- O& P! w "<td>" + bomPart.getProperty("item_number") + "</td>" +
! O& A% T+ k( v: u5 a6 t* q: x "<td>" + bomPart.getProperty("description") + "</td>" + & [: ?' b9 G! W" B8 F7 U5 _
"<td>" + bomPart.getProperty("cost") + "</td>" +
6 w D* E& h$ N: Z# h* x "<td>" + bom.getProperty("quantity") + "</td>" + . f: P) J6 p8 E# C9 Q
"</tr>"; " l+ C1 o7 x/ [' F6 k/ P$ S2 z
} * \2 e; G/ R8 F$ A6 ?
return content + "</table>";
4 @+ p& l0 }1 q, }/ W" N- U D0 Q9 E7 k1 Y& N0 R2 |
3 I: Q' J- M* M
' ]5 Z+ F- t( m" G1 G7 a
" l5 Y1 k" {7 Z/ h* C; M/ \3 [C#
4 _0 W& _& `' c+ {Innovator innovator = this.newInnovator();
% L# ]; @) ^9 ^! @ * _3 Z4 ^5 N3 c
// Set up the query Item. 6 y3 K3 Z8 w1 D, v5 _+ n
Item qryItem = this.newItem("Part","get");
& S* W5 E/ |$ pqryItem.setAttribute("select","item_number,description,cost"); 4 Q5 X" b- Z3 a4 {) |
qryItem.setID(myId); ; Y6 N5 F5 F' [- j7 R
+ k& x( N% S- d* D; c1 ^( {
// Add the BOM structure. ) C: H: i* t4 d4 ?) ]
Item bomItem = this.newItem("Part BOM","get"); + P* l: Z; v- i( A( Z- J$ M# K6 G
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
/ h; Y/ C3 ]& Q9 {qryItem.addRelationship(bomItem);
( H9 k/ ~! M: t" F$ u + ^) |4 m {5 J& N: E
// Perform the query.
5 ^6 ]; L' z x& z1 w8 \& `+ u& uItem results = qryItem.apply(); ' s2 T$ W& T9 b7 |- t
5 P- N2 x0 b9 ~3 Q D
// Test for an error.
6 z* @) G- H- `% @8 x) gif (results.isError()) { / Z* Y/ \1 f, \( s% `( n0 m8 e
return innovator.newError("Item not found: " + results.getErrorDetail());
& V' W i: A" G! h}
9 v6 K* R B% g
& N- N/ `" ?2 d8 A) Q- I// Get a handle to the BOM Items. 1 ^1 m- j3 E, n. A# F
Item bomItems = results.getRelationships();
3 ?6 m( W! q4 e5 G; @% p6 M# V% ]int count = bomItems.getItemCount();
9 \8 B6 x+ s8 [, z4 B1 b/ C& Sint i; & X) C. C D* J2 h. B/ |
5 u, O7 r; R s5 y, c0 d! r( z$ f' J
// Create the results content. 1 e! L2 \5 I3 d1 T2 n5 k
string content = "<table border='1'>" +
# n8 z2 c# }: |4 q7 N) p4 ? "<tr>" +
- R1 b6 G4 y4 C, z8 _. c% K "<td>Part Number</td>" + / S# f! ^3 U/ j8 K1 g1 R
"<td>Description</td>" +
% J! w, ^$ I( b, i0 M "<td>Cost</td>" +
4 w: v2 i/ R- H "<td>Quantity</td>" + % y* x0 \' K* f5 ^
"</tr>";
' k. r' @$ n0 ]7 K6 i; W Y 9 m& O5 R; S/ _$ J% n
// Iterate over the BOM Items.
. X6 `$ z% Z! s& pfor (i=0; i<count; ++i) 0 c0 t5 k5 [7 o% |
{ 1 W: F* R) d. u; G4 h
// Get a handle to the relationship Item by index. ! u$ f; G2 m( b% Y
Item bom = bomItems.getItemByIndex(i); 8 \+ _) [' M0 l" U
// Get a handle to the related Item for this relationship Item. 0 N) _6 ?: b; f' b7 G# z
Item bomPart = bom.getRelatedItem();
$ E; E' h- `6 \
$ L7 p/ M; F' s" P6 ^% c3 i content += "" +
2 B' d0 A; x6 i/ w3 u+ [ "<tr>" + ( C7 _9 T& p, G& R1 ?6 U
"<td>" + bomPart.getProperty("item_number") + "</td>" +
t$ X/ B) X$ ~4 n3 u "<td>" + bomPart.getProperty("description") + "</td>" + ' C- G# \# G" p/ `, x2 c
"<td>" + bomPart.getProperty("cost") + "</td>" +
) G4 o. U1 U: K& W) L& e "<td>" + bom.getProperty("quantity") + "</td>" +
, T( D, P& m3 x2 _( \- M n. F "</tr>";
$ D% A3 L+ ~! y4 A: ]7 S6 m( W}
8 B% y; B" Q' ^, J! J8 gcontent += "</table>"; 2 x( M$ Y# ?. s6 U
5 u" F/ Y: {1 w M7 @return innovator.newResult(content);
( c6 x; s8 @7 b s' K( c
( b/ w+ X+ U. L2 Y+ \% v' L# A
, K9 K5 \8 D. k0 J, U& f. a
* Y4 J) x2 S/ D( o$ Z/ s( A
: M7 b5 c1 x; q. w8 k+ E
: X/ Y2 H3 ?: J! M" L7 j
% i9 t+ |1 P3 N0 F+ z( k1 k, O
8 \% v5 i, m8 z Page 46
! |% F, C: `0 u; u
3 _# `+ p! ]) S: gCopyright 2007 ! y# T, j$ o. \- }9 _" [% G* P5 q
Aras Corporation. 0 e" z; U# Y8 ?# E( S/ c) @
All Rights Reserved. ( U, {) z7 d |7 B- }
VB.Net " X' j4 k8 Y" r" M
Dim innovator As Innovator = Me.newInnovator() 2 U6 D, x; t0 c8 S m0 a
" i/ W& z8 ?" t% H
' Set up the query Item. ( K" u. C) m- F C) f/ k& h
Dim qryItem As Item = Me.newItem("Part","get")
$ \ x' J; o# [3 a$ [& k, x3 g i+ xqryItem.setAttribute("select","item_number,description,cost")
% R! [; Z: }! H' I5 g0 Z6 rqryItem.setID(myId) 4 {. z9 S) E) X# {% h( e/ s
h) J: u+ a7 w. N- P1 F; l7 g# S' Add the BOM structure. & V& D4 W* C# D) e1 w' B5 m
Dim bomItem As Item = Me.newItem("Part BOM","get")
4 D4 I4 x Z9 w) T2 m9 P# T: gbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") N7 ?( D2 O% R6 K
qryItem.addRelationship(bomItem) ; u8 t; _3 G; P* T4 S- |0 E
+ M) @4 c$ E' Z( D- b% _$ V' Perform the query. & E7 \) f/ k' D* G" B* T$ ?8 H( `
Dim results As Item = qryItem.apply()
, x& w& B1 a9 z9 a9 Z! g# o
4 G1 q! b( w0 k6 f/ E1 V9 \$ H' Test for an error. 1 J8 Z0 D" g/ C8 q
If results.isError() Then 3 W1 B5 _, t% _5 C R; m$ ]
Return innovator.newError(results.getErrorDetail()) . F! d) }: [+ U% ?+ F
End If
3 W* O# e2 S2 i! J; {0 A/ W0 W . ~! d. O; ^! o* r
' Get a handle to the BOM Items.
' V0 I" X+ R [& ]Dim bomItems As Item = results.getRelationships()
# [$ ]& D3 K ]$ \Dim count As Integer = bomItems.getItemCount() 4 D/ F# P) K2 z& `" D
Dim i As Integer
/ b, K- [! y. F. e: I0 C 1 J7 M; l4 B( w1 C7 \/ {
' Create the results content. - R& ]5 X" `9 Y5 [
Dim content As String = "<table border='1'>" + _ / Y7 {0 y( ]9 a8 Q
"<tr>" + _
1 g( R6 h3 d' j7 u7 K- z9 y "<td>Part Number</td>" + _ ! {( q+ F* @: a6 y$ g4 b
"<td>Description</td>" + _
% r5 L3 _4 _% t, @( P% s/ u "<td>Cost</td>" + _ ; W# P9 N' W0 j# c
"<td>Quantity</td>" + _
" E; b- W4 O) N1 ~( b P" K "</tr>"
. N# K/ H q2 x. U0 ?, {2 @
4 w: w1 L; m3 |& }$ z' Iterate over the BOM Items * n/ i1 c! D$ a
For i = 0 To count - 1
: ?# s; Z5 ?' @, W' G$ g' Get a handle to the relationship Item by index. ' R" S/ H) Z, Q7 r, u$ i+ A0 \
Dim bom As Item = bomItems.getItemByIndex(i)
' A; B0 y* G2 a
$ t5 z+ l4 Q/ m0 A3 n1 Y" ]9 p' Get a handle to the related Item for this relationship Item.
1 o2 R3 U; ^# y; L4 A- e- h( U Dim bomPart As Item = bom.getRelatedItem()
, W7 I$ W1 ^4 F 3 _/ {/ s- K7 P6 [7 S a
content += _
- t& K5 S/ V" a$ r "<tr>" + _
( o3 ^0 P& W; u0 L' u "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 1 M1 Y: q- i: s
"<td>" + bomPart.getProperty("description") + "</td>" + _ ) H* ^1 L$ D+ y+ J- j: c* z
"<td>" + bomPart.getProperty("cost") + "</td>" + _ ( _, }9 I& |" C
"<td>" + bom.getProperty("quantity") + "</td>" + _
# l- ]3 L; T9 L& J "</tr>"
! u+ t- m" G J7 v- P' u! d3 DNext
+ L' t' Y0 ^1 F% n) J+ _* @content += "</table>"
' }% @* C/ s& c- ^# h* L " U+ X( n" H/ ^, Q5 W
Return innovator.newResult(content)
8 k* q! e6 b) b+ T+ C p
2 ^5 [! h. v u0 T0 J% l |
|