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

【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  
9 l* a7 P7 M1 b" x/ z9 k# ^To query for an Item and retrieve its structure you build the query as the structure " K+ i$ S4 H8 o/ p$ J; f
you want returned.  Use the IOM methods to add the relationships you want and
7 ~( q1 O7 s1 |2 ~build the structure in the Item.  The server will return the structure that follows the $ g: R/ A8 W  T
request structure.
6 I$ l/ F9 b3 w0 gThis recipe illustrates several related concepts together, which are how to get a set 2 n1 s9 ?1 w: _4 T
of Items from an Item and how to iterate over the set, plus how to get the related
9 }( p0 l$ i; N7 I& PItem from the relationship Item. $ c1 |: t6 R) P1 x
JavaScript  : i. |( U' K1 h3 E3 d: K
var innovator = this.newInnovator();
7 e# u+ ~* s7 m' T4 ?: o 3 d3 P7 e* E7 z' ^2 o
// Set up the query Item. : Q- h. o# |$ _# O& `7 y
var qryItem = this.newItem("Part","get");
3 g$ g, K7 T  g7 L: f+ hqryItem.setAttribute("select","item_number,description,cost"); : g" D6 z$ ^# S) [$ ^( o
qryItem.setID(myId);
/ F2 A3 V( K- Y5 Z  j 6 L2 \0 I- [6 ]4 V0 N) J
// Add the BOM structure. ; O- S. V5 N* E1 E
var bomItem = this.newItem("Part BOM","get");
. W* y( s( v4 KbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 3 F1 W! k# Q3 I) s  V
qryItem.addRelationship(bomItem); / M% W5 c4 \- Y3 g) A  @. t

+ P+ l2 D; K& }8 H5 Y// Perform the query.
( v. N8 `8 }2 R7 }) U8 ?var results = qryItem.apply();
" z- }' K0 A( N: z# K; c( x . c& _9 J+ A1 O  O- q8 `4 Q  B2 c
// Test for an error.
) g8 {5 ~, \# _9 Uif (results.isError()) { % ~5 j9 I& R  X6 t; t/ B4 ^5 Z( O
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
0 k4 p) {4 g4 v4 R; h% ]0 Y. r( m  return; , D, N7 R0 C9 x: E
} 3 N; W5 v, ?8 b+ y  U9 s" @
+ S9 H, ^3 R! J& m5 c6 c2 s
// Get a handle to the BOM Items.
! N9 g' n; b9 G0 f( ?) p% lvar bomItems = results.getRelationships();
, s- }0 `+ ]% l' j+ A/ E  dvar count = bomItems.getItemCount(); 9 l/ G, ~' J+ i) Q
8 k( J! [/ z6 x& T5 C
// Create the results content.
, Y7 A, Z" |+ _7 S7 C# R6 ~var content = "<table border='1'>" + ( K8 S+ W+ h2 L
  "<tr>" +
7 B( n: G! m9 G' g- c* Y7 K% D    "<td>Part Number</td>" +
7 z& P" e! H. _4 R) l! {2 y0 x  W- \+ p    "<td>Description</td>" + 6 {1 O, b( F. v. E% ^2 l" j
    "<td>Cost</td>" +
  t0 p/ S6 ^! W. G    "<td>Quantity</td>" + & M  F: ?6 y9 r, ^" ]
  "</tr>"; 3 [5 p' u# Y. \& K% i  }! ^. g
$ d* ?8 l" y3 A: x9 t
// Iterate over the BOM Items.
! F! c6 U7 O1 p3 z& s5 Efor (var i=0; i<count; ++i)
9 M' a, i5 [& H{
8 V# Y8 U3 R) I+ `* a// Get a handle to the relationship Item by index.
( O$ y0 s8 _! I" t  d. p& c: Z- h% j  var bom = bomItems.getItemByIndex(i);
, V( X/ S! p$ ^8 m# Y7 ]' O3 M// Get a handle to the related Item for this relationship Item.
$ U0 ?8 _5 u6 v8 ?3 P: u  var bomPart = bom.getRelatedItem();
) G# b  W( g  p# x+ K
6 `/ ~. p. t: c2 y: y) G/ V5 Z  content += "<tr>" + 0 {+ Q1 ?' |  @" S1 [2 O
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 5 k8 P' H% b0 Y( p# i0 c
      "<td>" + bomPart.getProperty("description") + "</td>" +
, V; u3 U% J& c2 w; P! T+ m6 N      "<td>" + bomPart.getProperty("cost") + "</td>" + 3 ^4 @" @, h# ?1 c
      "<td>" + bom.getProperty("quantity") + "</td>" +
; l( X5 c# h; ~4 \# ~    "</tr>";
8 ^1 d; {. X3 ~3 S7 M8 w5 @6 I}
2 Q3 D, X+ G- A0 _return content + "</table>";5 h% C+ O. ~0 ]/ ]; I7 Y
6 C# w3 h" w/ G# B

9 H: k: A/ \7 p5 [6 y$ A/ {$ m% n
& ~$ v2 d1 T- F; j$ Y. D8 E" \

) g" ?7 ^3 [  p; P# j* ?0 j+ C) KC#  
3 g) J- [! C" g: u; k! gInnovator innovator = this.newInnovator(); , F& n$ l, p( f5 P7 ^
2 M, `6 y+ ^5 E3 ~0 D6 p' P; W
// Set up the query Item.
8 z% `$ H; D8 {$ ]% {! uItem qryItem = this.newItem("Part","get"); ' |5 X% O, R) T7 ?! C5 T# `
qryItem.setAttribute("select","item_number,description,cost"); ! t4 C% D& y! s- l3 P2 l+ C
qryItem.setID(myId); ) L* I  `/ f0 N$ T
. v" A! S/ p8 j* H3 y
// Add the BOM structure. 2 U* c% o% m* h5 v' G* K4 n" D
Item bomItem = this.newItem("Part BOM","get"); 1 N4 _' t. k  z9 U8 n
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 0 e, v) f* ^$ g- Q4 x7 `
qryItem.addRelationship(bomItem);
9 Y( |% ~  U9 a4 G6 g+ j
% X$ B7 y% o2 S1 X3 |& W. P3 ]// Perform the query. 6 G& I: ^) N+ x% t, N  z
Item results = qryItem.apply(); / T6 {1 l, Z& Q
6 x" g* G; l9 A6 V) b, e
// Test for an error.
; H6 n: |( G- H% X3 hif (results.isError()) { , E; @8 |' E/ v4 K
  return innovator.newError("Item not found: " + results.getErrorDetail()); # s4 [1 C* `" j4 V1 L" S
} 4 k3 h. c( ~. }- }
. D) K" A6 L; A3 O0 q
// Get a handle to the BOM Items.
: v! a( M. M+ u( }Item bomItems = results.getRelationships();
& P. _9 {) B* c9 Uint count = bomItems.getItemCount(); ( O, W& k: }5 u# c9 x; o
int i;
! q7 E2 }: {2 W
( d* R/ k3 a8 |! K$ @) D& C8 L// Create the results content.
) Q: Y3 m0 z; h1 @9 I) l( tstring content = "<table border='1'>" +
) T# d4 ^. }: ]: o( E  "<tr>" +
2 O! _0 T! C) M8 S* J' B    "<td>Part Number</td>" +
( V+ y* v, P5 `4 U3 g+ m    "<td>Description</td>" +
- X2 X' X! G' j% n' m2 c    "<td>Cost</td>" + 6 K: d# t- t9 ?( A7 Q
    "<td>Quantity</td>" + ( v/ M! d- C1 a7 u. Y8 n8 D
  "</tr>"; 3 c2 o& q* R7 h+ d& f1 s' Q. C

) h& g. q: y8 N; d& m' b// Iterate over the BOM Items.
7 w- c% @( G  E' z% Q  g9 Z5 k2 efor (i=0; i<count; ++i) " P* Z4 R8 C" U+ Z7 [- i7 U2 O
{
. j# S1 r  R) t6 X6 B4 J( q// Get a handle to the relationship Item by index.
1 i  G7 E' R  t- c9 j0 t4 {5 @  Item bom = bomItems.getItemByIndex(i);
4 V, |- r. D1 A: v6 c// Get a handle to the related Item for this relationship Item. 3 ~. e4 ^9 `+ j, F+ k2 p" s9 z# P0 A
  Item bomPart = bom.getRelatedItem();
% Q8 H! e% X9 W) r . S( x; T' \. |; }4 H! @; [9 u
  content += "" +
7 x7 d& A! ~/ q8 P    "<tr>" +
! T6 \- |7 O" Z! E+ ?' a0 g      "<td>" + bomPart.getProperty("item_number") + "</td>" +
; Z3 C4 q% F7 I0 f5 O6 k4 R6 w, L- V  l. w      "<td>" + bomPart.getProperty("description") + "</td>" + ; D9 P& W- [2 |2 n$ m5 m
      "<td>" + bomPart.getProperty("cost") + "</td>" + 6 y. E" D& N' G9 E" c
      "<td>" + bom.getProperty("quantity") + "</td>" + ! u7 [1 s5 V+ a) o# C% M
    "</tr>";
" e& z) ?" {8 ?2 X* D} ' E5 P9 R0 Q5 O  j2 E
content += "</table>";
- s4 R2 ?. B3 A+ I
  ]% M- _, g, H8 _' S: D6 kreturn innovator.newResult(content);
9 M% E- d1 g9 ~& c* k  N2 @' b: ~: ^; y# P2 q* {/ }3 T4 y5 t! n
0 J0 b+ H9 V- g: I$ g) ]
3 i8 @; p! h, O* i, o9 @  D

0 M! o' x: r( F4 {" ~& h" q- @; y* V, w3 b

0 @: o) t5 X0 \8 H" U4 j& s 5 Z9 R3 b6 z& ~  T
    Page 46
- J6 O7 M4 X3 O% x6 n
8 O8 ^$ [! G1 [# zCopyright   2007 0 J+ ~6 `/ L1 d! O
Aras Corporation.  % @' G  j% n+ k: {$ g- y4 v
All Rights Reserved. 2 N* k  Q! K1 O$ p& [% C1 U' A/ ]
VB.Net  
+ m! }; l3 T+ X6 L9 \* GDim innovator As Innovator = Me.newInnovator() , e) K% _. X5 \2 Y* `& v) w7 @6 w

4 k/ k1 w, l9 x! W6 r% n, ], l, d' Set up the query Item.
! s$ B- z- i6 ~) L" M8 W7 T7 N4 Z8 UDim qryItem As Item = Me.newItem("Part","get")
+ U) O- t( a0 F. [3 v2 eqryItem.setAttribute("select","item_number,description,cost")
, g; \" g; n9 p# WqryItem.setID(myId) . V1 U- u! W" d) Q( D$ p$ R6 f

7 p& {7 [/ F" u0 l8 K% e4 ~' Add the BOM structure.
- d; v9 n! B  O+ N+ eDim bomItem As Item = Me.newItem("Part BOM","get")
" m7 Q/ ]1 l0 d2 `; Q# jbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! v0 f: Z2 A0 e0 H7 R% i+ \qryItem.addRelationship(bomItem) , `% E7 q; {) S6 A4 K

; g5 G# O/ b) x4 j; K. q: h: R' X' Perform the query. * w; }/ n4 O# `
Dim results As Item = qryItem.apply()
" c+ j4 D* a6 V1 ^
% S' D" a3 h* b0 m$ S4 Y' Test for an error. 2 u/ X; |5 J! f
If results.isError() Then . F! D8 _& a! A0 {9 w
  Return innovator.newError(results.getErrorDetail()) - \- W5 q( ^/ a/ e- `
End If 0 _7 C  m# i; a. i' m# a3 M8 @
  a. @( D  d, s6 b% t2 x+ n
' Get a handle to the BOM Items.
, G! @& ]' L, p0 bDim bomItems As Item = results.getRelationships()
2 e( ~) k* B6 ?8 t2 G0 aDim count As Integer = bomItems.getItemCount() ) t* j8 E3 W9 X1 c, e
Dim i As Integer ; n7 l) s2 j4 |0 b
2 z( K: B% T+ e7 u+ S5 d
' Create the results content. % w& h0 B+ G. l" B% L5 X( G
Dim content As String = "<table border='1'>" + _ + f1 \# k5 I! b" M
  "<tr>" + _ $ F: |0 ^! }  @; [
    "<td>Part Number</td>" + _
& @  u  `" E8 q2 U% {    "<td>Description</td>" + _
3 M; I) c6 J( c& [7 ^7 B; N( V9 G7 t    "<td>Cost</td>" + _
; t, |( h7 q6 Y# [- d1 o    "<td>Quantity</td>" + _ ; x& A5 W8 J) r! l2 W  @2 N
  "</tr>"
1 E% o  Z1 n0 _& N+ e! J: Y - Z) N; x6 L6 I9 T! l8 |* ]
' Iterate over the BOM Items ' O, x9 v# h' D  m! e/ B
For i = 0 To count - 1 8 e+ t% K' f. j. }& s
' Get a handle to the relationship Item by index. 3 ?2 m7 J( v1 r
  Dim bom As Item = bomItems.getItemByIndex(i) 9 c* O6 n6 s7 ]2 z8 m: c, J
+ N$ R9 s, p3 g) s+ U% m. G
' Get a handle to the related Item for this relationship Item.
$ c$ C7 i% y) ~  Dim bomPart As Item = bom.getRelatedItem() ! j6 X2 F6 d5 g# D+ r+ X; h

3 m" [2 x( G/ l$ a2 p  content += _
& E  i; X3 q! m, A# x    "<tr>" + _ 0 E2 X0 N  c% q- |$ g5 D" S$ l
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
& v. Z3 U- X+ N1 J# m4 B      "<td>" + bomPart.getProperty("description") + "</td>" + _
- b1 \1 \! W  F/ d9 N      "<td>" + bomPart.getProperty("cost") + "</td>" + _
% ]6 n! f1 _5 U/ k  g) U! j: ]      "<td>" + bom.getProperty("quantity") + "</td>" + _
4 P7 ]2 P  N7 }( b$ K    "</tr>" $ @6 y9 V' D3 U4 ?' ?2 }
Next 0 C( D9 O& _  g* n, ]2 Y$ J: n
content += "</table>"
) S. L. k. u8 V 9 v% j% `- M* \+ N
Return innovator.newResult(content)
8 ]" o0 u  L4 x. I8 F# T6 `8 [' u1 a( k" ]+ d* e- l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了