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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
$ t: e- y: R6 V& r6 NTo query for an Item and retrieve its structure you build the query as the structure
; S2 A' Y" S  v% Ayou want returned.  Use the IOM methods to add the relationships you want and ( W3 c# C- K  M; Z* ]
build the structure in the Item.  The server will return the structure that follows the / r8 i. i9 h( P% i$ R8 ^% ^2 K- k- f. j
request structure. - m* }9 u2 I/ \( |* m: {% Q
This recipe illustrates several related concepts together, which are how to get a set
& _: J6 a$ ]9 Pof Items from an Item and how to iterate over the set, plus how to get the related
  Y' S: R8 y; M* s$ V8 NItem from the relationship Item.
1 h% }& o% K$ n) y5 `! {3 [JavaScript  9 @. `* b: C" l& q: ~8 ~1 t7 i
var innovator = this.newInnovator();
  p% r) ^, C4 V9 f/ u) V
3 Z, `0 \6 }$ l9 ?2 Z$ p. b// Set up the query Item.
4 t6 S7 y1 K! u- Fvar qryItem = this.newItem("Part","get"); 1 E- w. {" p0 ~# K
qryItem.setAttribute("select","item_number,description,cost"); 3 m( ]! t$ K* f( U* c) L
qryItem.setID(myId);
8 m0 m* H$ g# y2 q4 M% S# B! x
2 {- U# ?# g9 n  a; _# g5 Z9 |& D// Add the BOM structure.
8 X5 ]. g* R, |& M6 Pvar bomItem = this.newItem("Part BOM","get");
% S9 t& p; b* a9 o# P' Y" kbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); , U3 C  I8 _5 P. C$ T
qryItem.addRelationship(bomItem);
2 X4 V) M% n  v
, l+ c' U4 M6 m& \+ S& @5 i// Perform the query.
6 b* I8 K4 B2 H( V- I6 o( Wvar results = qryItem.apply(); & [3 Q- _( D" A/ b( N9 V6 y

% z0 v) c4 ]% u, k/ }// Test for an error.
3 D5 r+ s. k# K3 {' \if (results.isError()) { 8 E: f9 C7 U, Z/ L/ r; u$ s
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 7 N$ E3 i) ^3 u2 z* w
  return;
# y& L* x9 C3 B- n+ N7 g' H} & x3 i6 J/ J. w2 }
4 x+ _. B4 [5 Y# f; `. U' y3 i2 o
// Get a handle to the BOM Items.
& v6 k; K* }% K* R/ ]5 Mvar bomItems = results.getRelationships(); ' p; s) S. j0 W5 T
var count = bomItems.getItemCount(); 7 m2 o! Q3 X5 v9 B4 Y$ h
& H5 I' c5 f. L" B9 A
// Create the results content.
& X; ]& ?' q+ V& ~' evar content = "<table border='1'>" +
. P+ A# q0 _) n+ Y5 }0 G  "<tr>" + ) a& Y& x  ?5 Q% f
    "<td>Part Number</td>" + 3 ?; {- e& s, Q+ f0 P# y
    "<td>Description</td>" +
  O6 l, f! P* f* g    "<td>Cost</td>" +
7 a0 J7 @9 p, G2 f* t# S% [$ @    "<td>Quantity</td>" + 6 a* m, K5 `* ?) i
  "</tr>"; 8 ?# f4 i. k6 @2 ?2 B

, ^" \% @$ e; `1 Z8 l" ~8 u( J7 S// Iterate over the BOM Items. + u4 I! v2 H( _1 T! K% z' h7 O: u
for (var i=0; i<count; ++i)
# F( e" }% n/ t) c$ h5 H! h{ 7 K8 a5 B; R8 o$ U
// Get a handle to the relationship Item by index. & H$ R' K7 ]! O
  var bom = bomItems.getItemByIndex(i); ; h2 m* i  v( R5 `7 k8 O
// Get a handle to the related Item for this relationship Item.
( U6 C, B) j9 z- U  var bomPart = bom.getRelatedItem();
& Q9 H: ]0 H' [$ G9 z 8 m+ I/ L  }# D# w6 r/ p
  content += "<tr>" +
' i9 H! F  h+ l5 O' h2 e      "<td>" + bomPart.getProperty("item_number") + "</td>" +
& \  K. `1 C) d* z% g: M  m- W      "<td>" + bomPart.getProperty("description") + "</td>" + . L9 i2 ]& s2 z0 `
      "<td>" + bomPart.getProperty("cost") + "</td>" +
! E/ e3 c% ]7 k$ j/ d0 R* \      "<td>" + bom.getProperty("quantity") + "</td>" +
) V, |0 J" A9 V3 `( l- }* L    "</tr>";
6 z: k0 X9 x# C/ M} 3 [7 l" t$ L! b
return content + "</table>";3 R. h- D  v  @0 y" p9 x! r
) e# x( z1 R( M8 `, j. |& Z, K

4 d6 r( n# Z3 ?
5 e' j2 u# n( E, z& E

$ K) [! N4 F. Y+ V( ^C#  
  G+ H0 B0 ], C  _5 tInnovator innovator = this.newInnovator(); % y7 A/ A' s2 U  N' Q
, b: F4 U7 j  m( H
// Set up the query Item. 0 g6 K( F5 u, m% w) W# z
Item qryItem = this.newItem("Part","get");
6 ]: v) {8 s: Z, i6 T5 o3 ^# mqryItem.setAttribute("select","item_number,description,cost");
* x9 Y% c4 _+ h3 W2 L, E- SqryItem.setID(myId); 9 D/ K4 \, @5 X: f5 k
* V9 ?4 B! n* i3 y0 v9 ]" {
// Add the BOM structure. 6 j  T4 O# \# C! W7 x: ~+ I
Item bomItem = this.newItem("Part BOM","get"); & o5 Q2 h& N' h& U
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ( o, H7 e( M; e9 s9 f& V% _% D$ B
qryItem.addRelationship(bomItem); - o6 j. g. O; C5 ?4 b1 ^) x

  r- q3 w! n$ t7 ~6 z// Perform the query.
2 R3 ^2 J/ @7 q2 FItem results = qryItem.apply();   m$ U" P" i, t+ m: ?

4 j9 c4 y  u5 P! Y// Test for an error. + |% `" ^% ]+ f; ~& S. `: M
if (results.isError()) { 4 d# Y  ~8 z6 h" X
  return innovator.newError("Item not found: " + results.getErrorDetail());
' J8 e0 n* [2 v}
$ ^' C0 @' S- X9 }6 S' q7 {8 r
2 g. c2 ]/ d- G, `// Get a handle to the BOM Items.
# G! e  T8 N; OItem bomItems = results.getRelationships();
" ~! f+ x/ S6 H+ ^int count = bomItems.getItemCount(); $ ?6 j2 p) w8 M3 b
int i;
" q: G) w: W5 @   I* S5 r8 ~' s# H; _$ M% [
// Create the results content.
3 L) T2 c% L1 vstring content = "<table border='1'>" + $ x# E0 y0 V! o
  "<tr>" +
$ e: o  W& b# Z+ R# ~/ c5 _    "<td>Part Number</td>" +
8 `2 O$ D  A3 A" k1 K- s" E( `    "<td>Description</td>" +
5 d1 p4 g) Q+ I0 s- @7 x+ b" ^    "<td>Cost</td>" + 7 w8 [# ?$ G, c7 m# t
    "<td>Quantity</td>" + 1 v+ t; X7 u1 s, |
  "</tr>";
" z3 r- s( u- S+ i& M* A
4 }: R) l; o) C$ Y// Iterate over the BOM Items. / Y, }# g% r% d- m; U1 s. g0 b
for (i=0; i<count; ++i)
" A' y8 V2 Y1 A& Y$ c5 k' V. N{
8 H) @% r( m* H' X$ J" P// Get a handle to the relationship Item by index. ! |1 O/ S. Q9 o9 v1 H
  Item bom = bomItems.getItemByIndex(i);
( x4 o2 i" K2 v) Z. G, |$ K3 p// Get a handle to the related Item for this relationship Item.
7 \' r" Z1 c# C  Item bomPart = bom.getRelatedItem();
  |( O" v3 _# J- b/ ^+ W! _4 K# L , F# b! w9 z8 M9 ^+ f
  content += "" + 3 d# D% N; Y4 S! f9 v
    "<tr>" + - e) ?, _: S$ H" Q# M# z6 _' e
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
; ?" ^) m7 w! C( r      "<td>" + bomPart.getProperty("description") + "</td>" +
% R+ k5 }' @7 F; y/ Y      "<td>" + bomPart.getProperty("cost") + "</td>" + 4 F% X/ z; G+ a! Z* b
      "<td>" + bom.getProperty("quantity") + "</td>" + 8 w( ~4 r/ A( \8 C
    "</tr>"; ' {9 s- t% @9 Q. x1 \/ J6 A
}
0 O0 }0 k5 h* P- @content += "</table>"; . V9 |! @$ U3 Z- {: R

$ u& @+ V4 Z- |/ \+ d  o9 jreturn innovator.newResult(content);   G) k2 y- d/ J7 c" |: s8 B
! l/ u! S1 e' R" Q

, h& T2 {( g* r$ o, N$ r, Z) |1 C$ ^9 O

( k7 a7 N' Q6 r9 D
( ^$ l# M+ h: n. u9 C# G, o9 i

: I. B/ m6 g/ ^
: X( U  \8 a# o+ m9 s    Page 46
% q; ~1 g) H) }4 C' u  O
% [# g7 G0 d! ^6 n/ j0 |Copyright   2007 ! n( c7 S1 \1 e* g/ f  P( q* q9 n! K
Aras Corporation.  
) K2 m! k' u5 P0 ]  T2 g  [$ Y% TAll Rights Reserved. * Q3 w/ ^  x2 U/ ^# k: c
VB.Net  
0 r8 W$ w3 {% N9 v# o8 K2 sDim innovator As Innovator = Me.newInnovator() 3 C4 _; Z) t( }+ e9 l2 x! k8 F
7 j0 ?) ?% z5 Y0 b; H1 w4 C
' Set up the query Item.
* f  V6 u: c' y5 L" ?8 [3 Q  w4 g4 xDim qryItem As Item = Me.newItem("Part","get")
7 e3 T8 G# F- x( PqryItem.setAttribute("select","item_number,description,cost") ' A' u) s2 Q2 d" x: S) X
qryItem.setID(myId) 8 f  ~* e$ q6 M# }! o
6 {  w2 U/ {1 r. X" B
' Add the BOM structure. ) ]1 l9 y" H& r+ z% W* I
Dim bomItem As Item = Me.newItem("Part BOM","get") 8 ^# C% ?, [3 _! @8 G
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")   a( d2 o; g! K  a! k2 P$ _8 t* ]) F
qryItem.addRelationship(bomItem) 6 U3 z* y8 x% [# K6 @) ?9 b! Z& A% R

6 a: v$ z+ A# w* J0 v% {, ~8 M) V9 J0 Q; ]' Perform the query. " R/ n- c1 @% G4 c/ y! S; ]. z' l
Dim results As Item = qryItem.apply()
  \1 y/ d7 [& M' Y% H8 q# h
1 g# q1 ~8 e: ^; L9 ^0 Z) B' Test for an error. * U+ V1 B) y" x4 x, c6 Z6 [8 {
If results.isError() Then
0 c0 m% s5 ^9 x7 X4 y  Return innovator.newError(results.getErrorDetail()) , n6 h: c' |. h6 W0 `+ J
End If * P+ p* E/ t5 w$ Q$ E! p$ h

/ c* O8 v0 p3 R# n& q' Get a handle to the BOM Items.   F6 B1 w. q+ T5 d. _0 A- J
Dim bomItems As Item = results.getRelationships() + o6 R  T! R) }( \) @* h. ^; E
Dim count As Integer = bomItems.getItemCount() ' O4 g. V$ z. O# m
Dim i As Integer
' y; y% ^8 H! J, w; K ; f* ?- S9 {& o
' Create the results content.
5 M% U5 Q4 X  U2 G- b: I8 n% YDim content As String = "<table border='1'>" + _ " R- a8 C$ }% E% o: y" ^7 Z) i
  "<tr>" + _
2 P/ q; L/ L! }2 }    "<td>Part Number</td>" + _ 5 }) b( L( q8 ^: w* r1 R$ P0 l) R6 e( B! o
    "<td>Description</td>" + _
4 A/ \2 V  }0 I7 Q    "<td>Cost</td>" + _ / T6 \- s1 d* J
    "<td>Quantity</td>" + _ 4 r7 C0 D* Y' S
  "</tr>" ! |1 o$ P. ?* E& x: a) d! k$ @
- p# B% \$ z* Y* v- g
' Iterate over the BOM Items 4 @5 Y. L! j3 D
For i = 0 To count - 1 6 C4 i/ b% M' T
' Get a handle to the relationship Item by index.
4 K3 S# |) J" h- j$ E% p  Dim bom As Item = bomItems.getItemByIndex(i)
5 s& h& W5 s2 h$ E; s9 X
' S+ O/ v, H, M$ j& c' Get a handle to the related Item for this relationship Item. & _: O* S% G% W, Y1 j+ H
  Dim bomPart As Item = bom.getRelatedItem() & ]- o# b* n9 X+ t4 c: N0 |

2 K8 L3 M) ]. |  Y0 o7 S, `  content += _
9 ], T! N1 q, L' M1 Y8 J0 k    "<tr>" + _
: ]! b5 h7 U- z0 I6 o, l. y- g2 H      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
# C/ f2 j% Q# h+ D      "<td>" + bomPart.getProperty("description") + "</td>" + _
& c6 ]( |9 w3 Y6 n/ m& G# g5 z8 j9 L      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 1 M- {; `9 e' H: G* x
      "<td>" + bom.getProperty("quantity") + "</td>" + _ 2 g4 L1 A& u! e
    "</tr>" # Z0 s4 R1 b5 s! T- _* R+ N3 }* S
Next
3 U2 N: S; ^! G# @) L  _* ccontent += "</table>" : g9 B  d- e$ M, ~7 n
$ z- w& p  F; Q  {
Return innovator.newResult(content)
3 x& r% `, ?9 a0 b3 Q( x5 N
. w- E, Z7 K' R- E
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了