PLM之家PLMHome-工业软件践行者

【Aras二次开发】通过Item查询关系Item信息

[复制链接]

2018-8-1 13:41:14 1867 0

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
Technique  ! n* f0 @( E, y7 i) A* ~
To query for an Item and retrieve its structure you build the query as the structure
, g$ W# U* i3 V: H! ^% w6 K8 T  zyou want returned.  Use the IOM methods to add the relationships you want and
5 D$ w  U4 F3 ubuild the structure in the Item.  The server will return the structure that follows the 1 q& {, }' _$ S9 t
request structure. 0 M2 Y; L7 C& u8 K4 G3 v, C5 u
This recipe illustrates several related concepts together, which are how to get a set
& ~! D. C. S( O& r0 x. Nof Items from an Item and how to iterate over the set, plus how to get the related 0 G' i' |+ X8 f- d& y
Item from the relationship Item.
. i& ~  D* j. l$ B- Q- [7 ?JavaScript  
4 ]' ~% k0 J8 |$ E2 \var innovator = this.newInnovator();   V# F2 K0 D3 D$ j

' y9 A, ~( @! w, I/ C// Set up the query Item. ; g1 }7 L( x  p5 y
var qryItem = this.newItem("Part","get");
' z" C! p/ N; v6 i8 _. F  iqryItem.setAttribute("select","item_number,description,cost"); $ h+ _: b* }) P) B* }4 R+ |  H
qryItem.setID(myId); 1 k; w/ L" J2 L8 ]/ @+ ]
. H6 ]* t0 w2 s( d
// Add the BOM structure. + d- ]+ P* p! T. W. q
var bomItem = this.newItem("Part BOM","get"); 4 h8 o& W2 p# X
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 2 ]: K; E! H2 p4 p% y" X5 {
qryItem.addRelationship(bomItem); ; S4 N% W' R; k3 e# z1 F! |

! f4 f7 D! V8 v- @6 D// Perform the query.
% w$ H4 o7 w, fvar results = qryItem.apply();
( B% f3 o0 d. F: b) `$ u
/ D$ C" V$ u( }$ \6 ~// Test for an error. 1 i) @6 W( g  ]! V" h9 b" \0 [( g
if (results.isError()) {
% a) O) X8 |' u$ |( s/ S2 M  top.aras.AlertError("Item not found: " + results.getErrorDetail()); $ ~0 {8 W: }$ }3 ?. b( ?4 Q
  return;
9 @) {! C, q3 q6 M5 p( X9 z} : u* q, T3 n4 S3 D$ L

' S( D$ u4 S% v# I// Get a handle to the BOM Items.
8 C9 @% W' R9 l9 c. h* bvar bomItems = results.getRelationships(); 0 Z' Q: P) I* N' T5 U/ R. Y1 J
var count = bomItems.getItemCount();
- D, f& V: D; C3 t( g6 _3 ~0 Y3 G
- u9 t$ t2 j' y// Create the results content.
. c. w: Z/ Q: r: f5 N2 S: {% Ivar content = "<table border='1'>" + ' n# V! K6 x/ m# L, _" Y/ O! l  k
  "<tr>" + ! l/ F% y# t* X/ V
    "<td>Part Number</td>" +
# T! I6 M5 L% j; |7 \! N/ f    "<td>Description</td>" + 0 f* r4 \8 ]+ d6 m1 }8 A( M/ G. `
    "<td>Cost</td>" + 2 i8 F8 ~* d8 [
    "<td>Quantity</td>" +
, U: `) j: t2 U9 l* r8 D  "</tr>"; - b+ ^0 s8 `" L7 S

5 E5 p- G* ]) G3 \$ I// Iterate over the BOM Items.   R  K! Y1 N. l7 ~# N9 h
for (var i=0; i<count; ++i)
8 `' C: X9 i2 Q" Y. {. ?{ / n6 Y3 h1 j% b4 b+ ^' F/ e
// Get a handle to the relationship Item by index.
( J2 p8 i! m  m- g  var bom = bomItems.getItemByIndex(i); 8 S$ D, P& h, [! m( W
// Get a handle to the related Item for this relationship Item.
1 j, b9 ]$ N" D4 `5 B  var bomPart = bom.getRelatedItem(); ; p. p; q, m- _: }5 k7 r

- K8 B5 e; [. O6 M  content += "<tr>" +
. c) D9 P9 c4 B8 |6 Q6 u  W% `      "<td>" + bomPart.getProperty("item_number") + "</td>" +
- V  d! g5 f8 x      "<td>" + bomPart.getProperty("description") + "</td>" +
# |( u' R, c% |$ ~9 |      "<td>" + bomPart.getProperty("cost") + "</td>" + % ]3 y5 Z' m; l
      "<td>" + bom.getProperty("quantity") + "</td>" +
7 d7 f( v+ ], K! j% P7 x- m, B    "</tr>";
7 \7 g2 H' X% I0 E4 D7 Z2 Y}
4 [# m9 G1 T6 i$ Q& wreturn content + "</table>";' c8 r4 W3 h5 X3 S) d$ m

: Z! w" T* T& {9 g2 q

% \! i: g4 I7 _  [' d/ O0 L; A: p2 G( N& D$ L' M0 D
# z* B* q4 {' d" b7 a2 o9 b
C#  
+ b0 h+ P, i6 |% }Innovator innovator = this.newInnovator();
$ ]& E/ X+ w5 O0 E  X ; D% w$ a6 M$ ^8 x6 W
// Set up the query Item.
# h5 v' D; H! R, N; ]- n' SItem qryItem = this.newItem("Part","get"); 9 K. s# }$ L: k/ N- L& g
qryItem.setAttribute("select","item_number,description,cost"); 8 S+ P) s; T# P- i9 j
qryItem.setID(myId);
1 s0 i2 N4 U3 b  ?$ G
- P, ~0 x. ^3 O6 x# e// Add the BOM structure.
2 w/ p* `3 Q# s6 D# H& V5 @7 _Item bomItem = this.newItem("Part BOM","get"); ) y. M2 p$ C3 z" ^
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
! F# Z) {4 E. tqryItem.addRelationship(bomItem); - x! x: K3 R+ K% S3 L

% C9 Z4 T" p; r4 z9 G// Perform the query. ' n/ F0 i' L* R9 H
Item results = qryItem.apply(); + F" R& c: ^0 I0 N) i1 u% w9 r' f
; A( t) [& a8 b: v( j
// Test for an error. & g( w, Y- O! X5 O" Y, z
if (results.isError()) { 8 @" f& f' ^# ?* c$ P$ w0 B8 W; g
  return innovator.newError("Item not found: " + results.getErrorDetail()); 8 D  m$ v& V$ Y3 E4 e
}
5 [  z0 Q9 O0 c! _' P 8 k) W% g$ O% y8 A  z
// Get a handle to the BOM Items.
& J, ^& N# Z; f9 M8 EItem bomItems = results.getRelationships(); 5 t3 Y) W' Q4 l5 {- k: b9 F6 _' N
int count = bomItems.getItemCount(); 7 N! c' B$ F8 b
int i; " r0 A; ^" q) ^' u7 }4 X3 O$ P( t

, J: B6 @% Y6 D0 P6 B3 ^) `( N// Create the results content.
: w: }& m  ~3 ~4 b. ^8 |; K: pstring content = "<table border='1'>" +
% z0 N) P; w: `  "<tr>" + " j; J; ^" I# K+ Q1 Q5 k# }
    "<td>Part Number</td>" + % `  g# g1 H2 h8 f
    "<td>Description</td>" +
9 K# _* g  v# y- S! o# m, r    "<td>Cost</td>" + 3 Q  L1 {( b/ G. n. {  A$ v
    "<td>Quantity</td>" +
$ i) T1 H1 s9 k2 G' B  "</tr>";
, Z; S$ U) @; g, y  d
+ U3 F8 U' B$ T; t0 J// Iterate over the BOM Items. 8 L: t5 j4 i( S% S! s( O" b
for (i=0; i<count; ++i) " {+ I. U/ c# `; r( k
{
4 h# Z/ |2 M2 ]// Get a handle to the relationship Item by index.
; @( `: h9 {7 t# B$ k  Item bom = bomItems.getItemByIndex(i);
2 e# o9 `9 R% i9 |  L# d// Get a handle to the related Item for this relationship Item.
$ g0 C6 Y6 b8 f, X* s/ m  Item bomPart = bom.getRelatedItem();
3 w1 X9 C8 s' F& V / @% }8 U; `) K5 m7 E9 N* w+ W
  content += "" + ; |0 g  U( k' Y
    "<tr>" + % G2 N% ?. r; n) S: T8 k
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
2 u9 `6 {9 _2 ]& P# u. u4 B7 b      "<td>" + bomPart.getProperty("description") + "</td>" + % ?, U) y" Z/ a+ A
      "<td>" + bomPart.getProperty("cost") + "</td>" + ' A8 R& O& V4 v
      "<td>" + bom.getProperty("quantity") + "</td>" + ! a) V1 E8 y) v/ w, T8 T, }
    "</tr>";
" h' g( E  s$ F8 B$ ]( a} 5 w* l* Z: k/ O# W9 e; X6 V& ?2 o
content += "</table>"; 9 o5 y9 h/ ^( Q. e4 G0 [

# A& a) [, m3 @+ W, Kreturn innovator.newResult(content);
* i( V# y! K" _) Z0 E1 p' g
( e/ A, [6 y  i+ }

* u: ^$ \2 f4 m. u: v# f6 P; z7 Z& x3 f8 w$ C

* C9 _/ g' s$ x( |6 S& b
$ x7 r( K' Z4 e, N  K

6 k1 A- G  i, J* r' |; R6 g
8 p4 Q1 }9 t" s  {# d* U    Page 46 # o# ^: K5 L- a) u$ p6 ^- n

4 Y% ^2 }8 [% L" e/ T: zCopyright   2007 % D; m& V0 [  s9 C( P( a3 N
Aras Corporation.  ( m: r( I; l+ j3 p
All Rights Reserved.
" s& I( `0 w& W/ B0 nVB.Net  
* r+ s# L+ x; @Dim innovator As Innovator = Me.newInnovator() # p8 g' C$ J$ m+ l; l; o" X

: c: i5 s8 _5 x# |8 n' Set up the query Item.   P* W* C. Y( B1 N4 s2 ^
Dim qryItem As Item = Me.newItem("Part","get")
" x: n3 N# d8 v" G7 rqryItem.setAttribute("select","item_number,description,cost")
; [' j* w( b5 F$ U% b6 A& kqryItem.setID(myId) 5 z: v6 Z* j" X, c2 J
4 l3 V+ K, n5 q; c
' Add the BOM structure. 6 c2 T4 f5 @& C1 A! m
Dim bomItem As Item = Me.newItem("Part BOM","get") 7 V: f0 ]7 }6 K  M9 y
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")   u* k6 \1 L  Q( t$ _( p
qryItem.addRelationship(bomItem)
, t1 Y: y& Z6 G3 n
& B" T1 L  u3 T4 `' Perform the query.
9 K0 C1 ~6 S6 b8 XDim results As Item = qryItem.apply() 1 L( j5 p" `# k& B$ P
: q. ?5 u3 u# ~6 z+ q! j: b
' Test for an error. 3 t3 f' |5 P! r* b2 P3 x
If results.isError() Then % k' S4 R- g( G4 M  d
  Return innovator.newError(results.getErrorDetail()) 3 G* E% d' h7 k0 \8 T
End If
! ^+ A/ x. G. e 9 x7 ~% h/ s6 }2 k" M
' Get a handle to the BOM Items.
6 T$ D; ^* a! }; a6 \5 z5 I) d/ h# RDim bomItems As Item = results.getRelationships() 8 E( O+ t# b& J5 O+ l
Dim count As Integer = bomItems.getItemCount()
8 R1 Q, l: g8 N8 o+ O9 s! tDim i As Integer 8 c, r: A, c7 n, M6 ]! P  y6 y$ M& I

5 _" J6 D( T0 Y$ }! x6 u, \' Create the results content. * \; d$ I7 T0 J
Dim content As String = "<table border='1'>" + _
" {6 x1 h0 N  D5 D/ v% T# B) v  "<tr>" + _ ) K3 _. A1 S% i+ t
    "<td>Part Number</td>" + _ ' |& U, ^1 g1 W, P! Q, ]) o. O8 E
    "<td>Description</td>" + _ + ]# ~, i. P, s* k4 s; Q: R
    "<td>Cost</td>" + _ 7 z/ a- f  q" {) p" a  ], y7 |7 \; b; |
    "<td>Quantity</td>" + _
! Q) r) h9 M) J2 J3 j  "</tr>" 5 B+ n8 B# U. v

, P6 g7 t4 Q2 p! E& [' Iterate over the BOM Items ( y. f1 X/ K8 a9 T& ]% E; Q
For i = 0 To count - 1
1 |% J- y1 @2 B1 v& |$ e) g  W) c: I9 u% {' Get a handle to the relationship Item by index.
+ {. Y' H( N9 ~6 }  Dim bom As Item = bomItems.getItemByIndex(i)
; {3 E, L# q* K  i; c " X4 G; \) f  h9 ~
' Get a handle to the related Item for this relationship Item.
( p" V  @7 ]4 m( N/ N/ S. w  Dim bomPart As Item = bom.getRelatedItem() 3 F# e2 u. u$ |( j! p
! g( ?$ u" Y5 {6 D. b# _& w
  content += _ ( W! s8 P& t6 N  n
    "<tr>" + _
' c) _+ ~6 ]" y" M+ S; E0 n; Y' C      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 2 u( {& R$ p. `: h  _1 j8 w
      "<td>" + bomPart.getProperty("description") + "</td>" + _ % ?+ R+ ?) h( J( R
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
& ~) r7 ?) N+ f      "<td>" + bom.getProperty("quantity") + "</td>" + _
" O& M; ?0 U6 q) V- ~' v    "</tr>" / T! }8 y% b, \1 Q
Next
1 m! g" Q+ J  w9 z1 p% Dcontent += "</table>" : C, i5 S6 ?& ^# }$ c

9 I- y. i6 W7 w; M% x2 iReturn innovator.newResult(content)
; J% D6 H- L1 m' d) s8 T. a& E% f3 ^  I3 N$ k6 C
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了