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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
  o5 h1 k( v. I  C2 T# |To query for an Item and retrieve its structure you build the query as the structure
+ {* R" c: q7 q( K1 H- Pyou want returned.  Use the IOM methods to add the relationships you want and . {; p7 @% R) S- H  u9 a
build the structure in the Item.  The server will return the structure that follows the - Z7 g. y, `9 z/ u, Z
request structure.
( T; \7 j" f8 v* q) Z" pThis recipe illustrates several related concepts together, which are how to get a set # ^: z$ s* t& ?5 H& n0 k) W6 N$ t
of Items from an Item and how to iterate over the set, plus how to get the related $ P& n" E. K# q4 R+ G, ~7 Y
Item from the relationship Item. ( X5 K5 O  Q. |( P, ^( }8 N$ w" h
JavaScript  . x: o. C0 V) L7 j' z' H
var innovator = this.newInnovator(); 5 \* v' d, T! z: Y& \0 ~+ T
3 l/ c1 F0 g4 ~1 V
// Set up the query Item.
8 K# X# N) H/ }3 \1 a8 Zvar qryItem = this.newItem("Part","get"); ; ]9 }% Y! T2 E8 ~- X$ H. v* B
qryItem.setAttribute("select","item_number,description,cost");
% n) t; ?% o% A" Q$ k' OqryItem.setID(myId);
9 z3 n: y) i7 D$ F- {1 h  G
8 ?7 L$ m2 h+ a: a5 o2 m) ]( _// Add the BOM structure.
7 \5 y3 w' o, k: _) c$ E; C$ j% Evar bomItem = this.newItem("Part BOM","get");
3 ^. d7 m/ U. L0 X* kbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
" y7 R0 i% u: T. OqryItem.addRelationship(bomItem); & p5 ]- A- i6 T) O. Y; U2 B5 B3 |

2 [9 n+ b- \. t3 G// Perform the query.
9 |; l/ D0 T3 a/ c! _0 t: r/ o6 Cvar results = qryItem.apply(); 6 r5 V8 @( [6 [5 V: D

( r0 T. \' N% c8 m6 B/ ~5 e// Test for an error.
5 V( M! _) O- A' P) x2 dif (results.isError()) {
7 Z( Y9 a( w- R: ^, }  top.aras.AlertError("Item not found: " + results.getErrorDetail());
+ w5 \0 C7 v* F* h( X' g" @  return;
4 a+ Q* |& C4 d/ I: I8 O2 E  r* g}   z$ B5 A( ]7 Y9 [9 ?

0 R6 }, b. A4 S1 d// Get a handle to the BOM Items.
. f$ e" a- q& ^1 C$ @' K4 kvar bomItems = results.getRelationships(); 3 l& z7 H1 j$ r4 ]9 F: X2 c
var count = bomItems.getItemCount();
$ r5 s5 ?4 a) G6 N8 E( [ 0 T  m; N; L$ }9 K2 W! y7 a
// Create the results content. 5 w- B4 }/ [6 M9 h  N' d
var content = "<table border='1'>" + / b. z8 i; v# ?$ ?2 n7 l( g5 H( p  L
  "<tr>" + 0 p- h: _3 g7 t( U
    "<td>Part Number</td>" + 5 A$ x7 c' N& [+ e7 W* [! Y5 D' D
    "<td>Description</td>" + # l  g( i0 S8 Z. H* T) c
    "<td>Cost</td>" + 0 ?8 t) ]( F9 X
    "<td>Quantity</td>" +
) F2 C$ }& f, _. H3 q! P  "</tr>"; , O8 z4 g, m- I* y+ o, f

# O  J) f9 _8 Q// Iterate over the BOM Items.
4 H+ Y+ X* t) Yfor (var i=0; i<count; ++i) 2 D" L* I% D4 {& |1 W3 N! V
{
* D2 i/ `0 A' \// Get a handle to the relationship Item by index. 5 m, h+ g* J* T" g$ @2 k. h8 I
  var bom = bomItems.getItemByIndex(i);
3 G* o- H5 ]8 N1 R! I8 |// Get a handle to the related Item for this relationship Item. 1 o4 Y6 W; z4 l/ j9 m+ ]8 u1 z
  var bomPart = bom.getRelatedItem();
, [  |: Y2 g9 _* |  i( `& v
6 z6 o. l2 i# A  content += "<tr>" +
' z- B0 y4 [" q* |      "<td>" + bomPart.getProperty("item_number") + "</td>" +
. M& W- B! y) b/ p) E# r' O8 j$ k      "<td>" + bomPart.getProperty("description") + "</td>" +   W9 Y0 U8 x# H# P
      "<td>" + bomPart.getProperty("cost") + "</td>" +
$ c) T( N$ e$ B3 [8 S      "<td>" + bom.getProperty("quantity") + "</td>" + ) @2 ^1 w; ]2 `. t; M6 L: G' x
    "</tr>"; 2 M8 V" T- e1 j
} & C# e0 n! @8 A4 S( p: _: ?. W+ c
return content + "</table>";
0 j! O4 U1 o1 `8 H. `' ]2 C% b! @4 h3 ~: ?

& V) D+ w% i# ~  F- n+ y
1 |$ e+ [9 q' |, q) D
  \1 W2 P7 j; \2 B# p# U7 N9 ]
C#  ( f+ J& f5 h' |. |0 T3 P2 F; ]
Innovator innovator = this.newInnovator();
0 q/ g% G8 t5 u! C
3 B: c6 k* ]* k// Set up the query Item. + N9 z; I! D3 p$ X( T
Item qryItem = this.newItem("Part","get");
% c* T) ]1 m2 ^! i1 AqryItem.setAttribute("select","item_number,description,cost");
! c! P" Z+ u5 i5 t+ R, U! L  MqryItem.setID(myId); 5 j/ D4 ?4 U; P* L6 E8 o1 E
' Q# L/ _; O- N6 ^: o8 Y& C1 ]) k
// Add the BOM structure. 9 d( B  p& h1 |' F
Item bomItem = this.newItem("Part BOM","get"); ; p$ H6 m, H2 r& J  }: ~
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
8 i; o8 u2 S3 I: ^2 b: N, VqryItem.addRelationship(bomItem); ) X# `9 g' T& c( l, K. _2 M

) C! O  G4 Z3 M7 ]" t// Perform the query.
. \  g1 ?' u: s! XItem results = qryItem.apply();
6 n. y2 H! \' A5 I/ T
+ {- U) l# J' }0 z# r: t// Test for an error.
  E$ u7 W) S1 O* ]if (results.isError()) { ! `# h' T. ]& L. t$ U
  return innovator.newError("Item not found: " + results.getErrorDetail());
" z8 D4 p! z& k# M( d( R: t2 t; s" e}
% y1 H+ G4 `$ y# ~  J" R9 X : Y+ k- X9 [  c' C% Z$ a
// Get a handle to the BOM Items. ! M; p5 N8 m" j8 M2 P
Item bomItems = results.getRelationships(); ! l& Y3 h) p7 y$ p
int count = bomItems.getItemCount();
# Z  m4 i2 |/ T  r9 u( U4 m# M: |int i;
: H: o, c4 c1 e2 |
$ u9 Q5 v& A( p* c  g6 a// Create the results content.
5 A- Q( x% h; hstring content = "<table border='1'>" +
. K! d* t! t" g8 h5 |) o  "<tr>" + ' y& B0 z& G' }- \
    "<td>Part Number</td>" + * h! t& C, F, p5 a8 b  F. o
    "<td>Description</td>" +
, ]2 q2 P' Z3 u" S5 c    "<td>Cost</td>" +
, T0 M, s! @, Z+ M    "<td>Quantity</td>" + 3 Y" i/ M$ R9 l: R$ M5 {
  "</tr>"; . {0 D( C0 N/ J# n# l& r: b# p

( G$ i. J* U' v1 A" s% L; v& u- \$ \% x// Iterate over the BOM Items. $ t5 {3 f. I5 f$ n
for (i=0; i<count; ++i)
! e& x5 S1 e' O2 D# j{ - X' X6 n; `  l& |$ V3 p8 X. d
// Get a handle to the relationship Item by index.
) t/ r  A* B. {# P( r! Z* B1 L% Q  Item bom = bomItems.getItemByIndex(i); 9 q; Z2 ~7 r7 J
// Get a handle to the related Item for this relationship Item. % q8 |, C7 r+ e+ ~  h. M% d7 s
  Item bomPart = bom.getRelatedItem();
6 n8 Q  d/ H4 f7 h% D1 |( B
! Q* w* `& I" K- }0 z4 _) ^  content += "" + 4 X  T8 J1 o1 G* c1 e
    "<tr>" +
' l9 n3 e' t& g5 }      "<td>" + bomPart.getProperty("item_number") + "</td>" + 0 e& [. E& F$ N
      "<td>" + bomPart.getProperty("description") + "</td>" +
& `2 N% r* w$ J. ]5 `5 }! O( {* L      "<td>" + bomPart.getProperty("cost") + "</td>" +
2 w* b, [6 c" s" ]9 e$ o9 p% f6 Z7 O      "<td>" + bom.getProperty("quantity") + "</td>" +
! A$ c8 w( b5 b    "</tr>";
1 g8 J+ v3 S: x} * L5 U# w( C( u5 i( D0 L+ ]6 C  A
content += "</table>"; " L; o3 K3 [; f1 L) f) E
1 ^5 n1 q( F" q% _* c5 ~- l
return innovator.newResult(content); ' ]3 a) o6 Z$ f4 b# o

7 p# F; k' K) a+ ?$ O

6 R1 l! d. K+ Z( U( W
: w* ?* g) A9 r8 u2 A

- Q- U( R; C: m: H4 s
' J: B* x3 Q3 D4 j1 W; b  i( J* @% c. I$ F

6 M/ S7 A' w# e 2 u" w- Y  _. K; E; Z- U3 B
    Page 46
9 E8 w/ i4 S# r9 X; O! j3 }
8 Q! ~2 I  R+ j1 B# C% N) gCopyright   2007
  ~; u7 N2 ?) u) ]  {2 ]- z' J/ MAras Corporation.  3 D  ~. f- ]1 K; V: v' W
All Rights Reserved.   N& K' A$ E0 q
VB.Net  
6 e" Q" A; R6 N6 t/ m0 j& sDim innovator As Innovator = Me.newInnovator()
/ e; }$ x) @& t0 S% B
/ ~! ]; j2 V- ?" N+ E  W' Set up the query Item. 2 h$ k8 \! r8 U- {: }% K" _/ F5 }2 c
Dim qryItem As Item = Me.newItem("Part","get")
5 U" \$ y; e; q/ v6 F) `qryItem.setAttribute("select","item_number,description,cost")
. H. Z: e1 w$ a& ^7 @( pqryItem.setID(myId)
# L& p7 A5 ~$ o) B 8 K4 _2 _% y5 E
' Add the BOM structure. 1 F/ {  c  U# \& j, C  \
Dim bomItem As Item = Me.newItem("Part BOM","get") & G5 D; t! J/ p6 x" i/ ^
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! D  @' `. |2 Q0 G+ t0 vqryItem.addRelationship(bomItem) 4 U8 g% E; A- }+ c8 p5 l
1 A; k9 h" d3 P( E
' Perform the query. + C5 Y- U" u! B$ f- B' P
Dim results As Item = qryItem.apply() ! K9 O1 ]- n5 V

. q# m5 \9 E% a7 Z4 T' Test for an error. - d0 a, J, L: ]+ Z
If results.isError() Then ! |' O8 z1 y& Y4 u8 T9 q1 \- W- T
  Return innovator.newError(results.getErrorDetail())
6 F* d; |* j6 ]6 g# Y6 G. QEnd If + r+ ?5 w. z3 O. S2 R# M% s

5 r# X6 I5 ?# }# C/ i7 O' Get a handle to the BOM Items. " B& q; `: A8 N
Dim bomItems As Item = results.getRelationships()
+ }+ b" G8 O2 RDim count As Integer = bomItems.getItemCount()
5 l  K% F: j6 H: \Dim i As Integer $ x, f7 T( D& M
) ~5 @+ V, \' H7 w: p% ]
' Create the results content.
6 ~6 _( V) F' s+ MDim content As String = "<table border='1'>" + _
1 c  A* t4 X* r" v$ F: p  "<tr>" + _ " O+ R' B: j5 F
    "<td>Part Number</td>" + _ . _* o5 C5 R8 d4 v/ p6 j
    "<td>Description</td>" + _ 5 r- Y9 O3 R/ K- R
    "<td>Cost</td>" + _
8 V3 d5 h4 z: B0 h1 }  i; O5 c    "<td>Quantity</td>" + _
! I3 O# p' {% \( a/ T* b4 K# O  "</tr>"
% [' E- G, V7 V) b& G, M
2 k: t/ D; f/ k4 H1 R% b. f4 u) Y  n' Iterate over the BOM Items   d) {/ u8 h* @* w4 {2 V
For i = 0 To count - 1 6 N2 J' d2 _$ ~, a
' Get a handle to the relationship Item by index. & M$ B2 q6 b1 U$ h: R$ R1 Y: ]
  Dim bom As Item = bomItems.getItemByIndex(i)
2 G8 j6 Q  p, q, L/ ], d 2 z3 g1 y# B  Z; s
' Get a handle to the related Item for this relationship Item.
- u  Y5 h) h3 i" L: ?  Dim bomPart As Item = bom.getRelatedItem()
5 A+ U- q) ~1 ]/ e0 Z0 K2 E* ] 3 G0 g  |9 l" U4 \- A8 y
  content += _
0 ?4 V) d% V- q+ O    "<tr>" + _ . W# r2 b, f, Y% q5 r  F& V3 n  M7 S9 x
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
  S. F3 I9 h' Q# C      "<td>" + bomPart.getProperty("description") + "</td>" + _ 7 l# `  y  r7 y& Y2 }- ~0 a
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
9 G2 |7 y, I  u+ F      "<td>" + bom.getProperty("quantity") + "</td>" + _
1 @8 m) l% U3 M    "</tr>"
  Z3 S7 p; {  p: X, }1 d) SNext
$ I+ e$ n' k  i3 Q8 `content += "</table>"
; G) F7 Z' Z6 q
$ c' a9 A. h0 W: `1 TReturn innovator.newResult(content)
8 U0 b* U) ?" V# E) |6 S
8 ]0 z  ]/ S* w* S7 U2 v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了