PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

admin 发表于 2018-8-1 13:41:14 |阅读模式

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
' l6 ^& t+ W# o1 I% L/ [To query for an Item and retrieve its structure you build the query as the structure ! D! ]6 {  X! C0 M
you want returned.  Use the IOM methods to add the relationships you want and ' A( H; Z, [+ P1 j: u1 i0 h4 n
build the structure in the Item.  The server will return the structure that follows the
% t+ J0 e1 K1 b+ w% Z* E& Arequest structure. : e( [9 Y: A$ Z/ i! a
This recipe illustrates several related concepts together, which are how to get a set
4 \7 x% O' ~( v. b2 sof Items from an Item and how to iterate over the set, plus how to get the related * S& A5 u1 a, P, g$ k- S
Item from the relationship Item.
0 B+ r8 f/ J  t& r  I  _9 `JavaScript  & k9 Y7 X8 n; [9 E4 t
var innovator = this.newInnovator(); ; D2 ], n( T" B& ~; x
9 k) }8 m! i. [( N, V: Q
// Set up the query Item.
, _3 b! K. o' J0 e' Bvar qryItem = this.newItem("Part","get"); : R8 I+ V: m% B9 @
qryItem.setAttribute("select","item_number,description,cost");
/ n9 Q* i# X5 y3 S! F4 Q) ?qryItem.setID(myId);
. j1 p" W7 G* b$ a$ z
0 F/ `1 B8 U  h- H5 A& d" V// Add the BOM structure.
4 `/ p& L& k2 z6 Zvar bomItem = this.newItem("Part BOM","get"); : h0 V* N% w% m! `: G) m
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
$ a) L+ g2 @; lqryItem.addRelationship(bomItem);
2 G# W" Y) l/ X$ U9 k& M; r ' e) M* {" @$ R3 B% s+ Q. t
// Perform the query.
; x4 H8 x8 {$ M3 x$ p) Lvar results = qryItem.apply(); * p8 j- u0 s  `; {. b' `  `
+ v! m% Y+ ~9 t; \2 y
// Test for an error.
' v0 @# P# E4 F8 Bif (results.isError()) { ) S: Q# U) `) L) s1 M
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
$ y. H1 ]" l* M0 c7 S6 p  _; N  return; 2 k1 R6 M6 V0 ^& R; x7 g
}
3 X# X: ~3 u% C$ \+ y) e6 p
& ~3 n  R7 w: a! r$ T" _// Get a handle to the BOM Items.
& d% ?- v& S) h7 p9 Hvar bomItems = results.getRelationships(); 6 A: Q7 K9 R  M$ k5 A$ `  O
var count = bomItems.getItemCount();
- J, o1 _8 I. ~0 ]6 @
7 x4 X3 u+ ~  o* T// Create the results content.
- ], S5 E# v5 Wvar content = "<table border='1'>" +
2 s6 e6 I( f9 v5 l3 e% m+ |  "<tr>" + , t5 E" j0 D3 `3 c8 [
    "<td>Part Number</td>" + ! a0 K" v2 W% r3 k+ m
    "<td>Description</td>" +
9 l$ E& X, a' B    "<td>Cost</td>" + 6 L# n5 d9 m+ t: d: D  ]
    "<td>Quantity</td>" + + J- ^+ T. D  i- e% Y
  "</tr>";
' s/ [) m3 ^  M0 }$ ^. J' R 1 Y8 M  f1 Z& y5 ^. l4 {" L, e
// Iterate over the BOM Items.
+ z& Z" C7 _8 d2 R! V% r! E4 Rfor (var i=0; i<count; ++i)
" B. D) @- `' R2 }, K+ |{ 4 i3 I/ D5 |6 M+ i; p2 X& t7 x% h2 S+ `
// Get a handle to the relationship Item by index.
# ?/ V3 E: X, a  var bom = bomItems.getItemByIndex(i); : [+ y9 a9 e8 e* Z  g6 P
// Get a handle to the related Item for this relationship Item. , t) j& P1 K) Z1 i6 j5 @
  var bomPart = bom.getRelatedItem();
( [/ O+ h3 z5 x6 r
8 q, ^; @% H! S  content += "<tr>" +
7 B% @+ c. M" q  H      "<td>" + bomPart.getProperty("item_number") + "</td>" +
0 |, W: s" ]7 I" v/ n      "<td>" + bomPart.getProperty("description") + "</td>" + 2 n5 u) ], T: ^" l7 r6 c: K
      "<td>" + bomPart.getProperty("cost") + "</td>" + * ^& k1 e% `: R0 t
      "<td>" + bom.getProperty("quantity") + "</td>" +
5 {4 v2 \3 S/ b( b9 b  K    "</tr>"; ) ~, X0 m; z% L2 D/ O, m* m+ B
}
2 \4 _. \% Z% U0 q! a3 breturn content + "</table>";
( ]& D- w) v# J$ x  g: H  ^* ~
! _' K" z! d- }) ^
5 n7 F' R5 B2 }

" h( j7 d0 q! `9 ?

) b1 [/ w8 E! f' |/ SC#  
  W; O8 ]& a8 m2 G& R) W5 z( S; jInnovator innovator = this.newInnovator(); 6 ^: c6 t, \4 ~/ W7 U( B

+ u& ]/ c5 c" ~2 H2 }3 M// Set up the query Item. 7 `* P  b/ s4 M- y& G* {
Item qryItem = this.newItem("Part","get"); 2 {) s6 y4 ]3 R4 q& C; O
qryItem.setAttribute("select","item_number,description,cost");
8 N9 A5 l' e5 l9 @qryItem.setID(myId);
8 M" c! C4 z; f' F, b1 ?) u
. {/ J2 k% H) L: h9 [* z% R* W; x// Add the BOM structure.
( x/ j5 j0 t4 ]1 t. TItem bomItem = this.newItem("Part BOM","get"); & v! u3 ?! T& e& p: r; O2 b0 d
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
* m' g( a, t9 ^. {2 Q6 k9 lqryItem.addRelationship(bomItem); , w, b3 o7 L2 y5 E

: ]5 M" L# ?$ L3 q0 ~8 M// Perform the query.
+ h8 K/ g& L! [: e+ o* p8 Z" O& VItem results = qryItem.apply();
1 T" u3 ]8 N# `# E' B2 r  B ) W; u3 ?9 J' ?3 X  c: {( c
// Test for an error.
6 U2 q6 s$ d: i5 r; u! tif (results.isError()) {
3 e, g, i2 I9 q# O; ]2 F  return innovator.newError("Item not found: " + results.getErrorDetail());
0 X3 j* Y* |9 h! ~+ V+ U} 0 H  w4 T$ i4 r- K, h

( x  B, ~; Q9 ]" f$ L# e// Get a handle to the BOM Items. 1 y! k! k/ H5 ]0 F
Item bomItems = results.getRelationships(); / b5 `7 {3 }0 V  x" i3 i9 i
int count = bomItems.getItemCount();
& h4 k& C% c9 G8 ~: c+ oint i; 7 i2 ]: K% l' H) O) h( g

6 Z8 `/ t8 ?, a+ P* u1 e- X) v// Create the results content.
9 g8 b  [* i6 ]8 V  y" Ystring content = "<table border='1'>" + + a8 o# T* ^7 K" Q3 F
  "<tr>" +
0 y: N+ V$ t6 g    "<td>Part Number</td>" + 7 Z$ ]" X; `$ U$ b$ v
    "<td>Description</td>" + / l, T7 I3 I7 `) Z- d, F; ~" ]
    "<td>Cost</td>" +
1 w+ C' K$ M: c2 C    "<td>Quantity</td>" + . Q0 p9 v2 @0 O
  "</tr>"; 1 k7 _! V( T- J. q( z4 H5 B# O) r, \

  v2 d& a9 z' U& B// Iterate over the BOM Items.
) G& J8 [2 e. F# Q& S: efor (i=0; i<count; ++i) 8 a" N4 N9 L9 R3 `: e
{ . V0 T& r4 l$ i9 {) c
// Get a handle to the relationship Item by index.
0 e$ A( S9 I* h4 o: P9 R4 g# J  Item bom = bomItems.getItemByIndex(i);
, x7 R  X) X$ T// Get a handle to the related Item for this relationship Item.
9 j3 I5 c' u( Y( f9 o- n  Item bomPart = bom.getRelatedItem(); 6 O: O) N9 ^5 A6 C5 F
3 r) A  `: N3 X% W" P8 E& p
  content += "" + 9 \+ V7 h% x" ~! N9 O
    "<tr>" +
  k9 M0 p8 b4 k9 x# J& c4 B      "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 i* ^6 ], G7 a. [3 o! Y4 R      "<td>" + bomPart.getProperty("description") + "</td>" + ! Y' O% M" B0 C. M
      "<td>" + bomPart.getProperty("cost") + "</td>" + $ ?0 w* s' N9 o- c* l
      "<td>" + bom.getProperty("quantity") + "</td>" +
* T8 a; Q' T3 W* O5 l( n4 k    "</tr>";
" p) L* M, t9 ~" P} 8 J0 n7 k. l) G9 L( ^- s
content += "</table>"; - V2 ~- m( `2 X9 V& y4 V
6 s! Y' \: b  H) q
return innovator.newResult(content);   r( y( r) V/ n7 A6 q* o! \
, ]7 W, }# l. c% N8 E+ ]- ]

  t8 P3 u& q* F$ T" H  _, j5 v# K" J, U

7 W! H3 T' a! H) Z2 j! a: P: k; b

+ C, ~& ~( s7 {3 Y) ^" ]
+ `4 Z: R0 A8 m1 m) y, P- e    Page 46
% ^. T1 g6 W5 Q) C
2 D: V7 t% c( eCopyright   2007
; n6 {6 I* J9 d: P9 U* s1 CAras Corporation.  
5 W$ y/ W4 L  P' [& h+ pAll Rights Reserved.
, i$ G# [$ n7 t' g( g* w6 ]3 jVB.Net  
) x5 K  x( L" k, d( \Dim innovator As Innovator = Me.newInnovator()
6 B6 o' B7 L! s- d  c
- w0 c6 X0 H" m' Set up the query Item.
! j+ K; c6 T4 H& ?7 }- K/ nDim qryItem As Item = Me.newItem("Part","get")
2 e0 t, V: O2 l4 }1 CqryItem.setAttribute("select","item_number,description,cost")
8 `& G1 j7 g% ^% eqryItem.setID(myId) ; Z+ l2 v4 P8 o; D" u
/ `7 u, P7 Q: G* {
' Add the BOM structure.
; {, Y! [! y/ [) }, V) |; x% hDim bomItem As Item = Me.newItem("Part BOM","get")
- E- f. T+ I( q/ b) K1 [  ybomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ) {% }* r. u$ s, A/ i
qryItem.addRelationship(bomItem) 6 D5 r9 {6 k- q% @  C: v

3 x3 z, b2 _( m& T: K/ X9 w' N' Perform the query.
* b8 V0 q; w/ mDim results As Item = qryItem.apply() / @5 }% Z" ~+ R8 s7 Z6 k  ~9 y6 i4 x
. t9 l  x' y! F; U
' Test for an error.
) ~: c- y% F. kIf results.isError() Then
+ B- n0 G6 E' s$ k  Return innovator.newError(results.getErrorDetail()) % }. _; ]5 z$ q: S( B* \- j: y' S
End If
0 Y6 r& T" y! h / x2 i* x( J, v/ _  }' w
' Get a handle to the BOM Items.
: E, q8 T, i; k: qDim bomItems As Item = results.getRelationships() ! L* G0 y0 C! _; Y8 j1 S! b; A
Dim count As Integer = bomItems.getItemCount() 4 {& ~% Y0 x* Q' F5 l
Dim i As Integer 1 Q- {# r$ ?% ?  ]
+ \/ Q6 ~$ N' v* Z7 j4 @
' Create the results content.
2 u+ E" n, y3 ^" d+ R2 `# ]Dim content As String = "<table border='1'>" + _
, ]/ j' f. g  A! Y* C* @  "<tr>" + _ / q/ m5 i( A8 \6 P7 z$ c
    "<td>Part Number</td>" + _
3 F$ p9 R7 H- u- E    "<td>Description</td>" + _ 7 V: q. K( r" p
    "<td>Cost</td>" + _
! L, c$ D6 W1 p. k, j    "<td>Quantity</td>" + _
8 O' d, ~7 @5 `6 i  "</tr>" 1 j4 V" }) }5 J; x! }! T
% I+ q& O3 {* b9 ~. w5 J
' Iterate over the BOM Items 1 a7 X( |1 W$ |/ q7 P/ E, G) B
For i = 0 To count - 1
3 M1 s" z2 G! O$ @2 b, C* {$ F& V' Get a handle to the relationship Item by index. 3 G1 W% d! R: A* s
  Dim bom As Item = bomItems.getItemByIndex(i)
4 N+ ~* X. b/ z& ~# S' N+ t
4 {# f% k3 @4 [6 N' Get a handle to the related Item for this relationship Item.
: k. l* i+ H4 L1 y. a1 b8 E  Dim bomPart As Item = bom.getRelatedItem()
4 K3 |8 G" p' d; P7 O' A & |% l% E0 G/ H' v  T$ @
  content += _ ( C# Z) ^" b0 Q) U3 s
    "<tr>" + _ 6 X8 P# @8 W9 q8 j+ N, V/ k" T" Q
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
4 I+ s- {0 m" p  G) g) C; }" [      "<td>" + bomPart.getProperty("description") + "</td>" + _ , r" ]/ t% [$ _$ q
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ : S( \$ H' b$ Z
      "<td>" + bom.getProperty("quantity") + "</td>" + _ # y" x9 @: v) M4 u3 t
    "</tr>"
! ~2 C; O1 s/ r  v( k6 dNext ' p; ^$ Z6 {- x; r
content += "</table>" 3 q8 G, y0 B7 d8 n0 z" y# K& f/ n1 _

0 T! t) \2 K2 Y& r* yReturn innovator.newResult(content)
% ]; v  l6 k7 ]+ Y' h: ^9 a. j8 A3 _2 X" M- v% Q" d: }% t
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了