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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  ' C& w8 K. C: E5 g1 J
To query for an Item and retrieve its structure you build the query as the structure
6 f2 q7 `% @0 f* W; G# Uyou want returned.  Use the IOM methods to add the relationships you want and
: \/ t+ h# q# W8 K0 |5 u' Gbuild the structure in the Item.  The server will return the structure that follows the
& i1 D" g' o& B4 A: erequest structure. " i. u# C; |& x/ |; h
This recipe illustrates several related concepts together, which are how to get a set ( m* d7 K  r/ d; ]0 q1 H9 s
of Items from an Item and how to iterate over the set, plus how to get the related 0 l+ q& A$ I0 q  G
Item from the relationship Item.
6 Q  ~1 c( b" E  v* R( q% D7 GJavaScript  - W/ _; D" E/ e* I: z# U- H
var innovator = this.newInnovator(); . T/ \3 T0 V3 R# b( y
# L0 c0 T& \' @  J/ D5 f1 ~
// Set up the query Item.
) [; ^/ }; O$ ^7 [" P; W% o5 E  }( Gvar qryItem = this.newItem("Part","get");
- u1 Y& f% s! @0 ?0 {qryItem.setAttribute("select","item_number,description,cost");   Z6 x' X. j: U5 w4 _7 s  F
qryItem.setID(myId); - d. @% W& ^7 [+ C' c
. N' m& o* r: X- ?( \' s* j
// Add the BOM structure. 3 b: q* c8 z' q0 P
var bomItem = this.newItem("Part BOM","get"); : R" F# `5 F* O& |) n5 s  m
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 6 b# N) t/ ^8 W0 I% {! \
qryItem.addRelationship(bomItem);
  Q* X! b0 ?2 w8 x% d7 p
- D2 g0 s9 J+ S/ y2 n$ p// Perform the query. % S9 s" p+ w- |  t" C3 I
var results = qryItem.apply(); ! s8 U9 T2 d! W7 l2 z0 i2 u
$ t  |7 V7 q6 A+ O
// Test for an error. 9 j+ `' W* i/ R+ X
if (results.isError()) {
  `. ]0 ?" ?1 P7 G; W& i  top.aras.AlertError("Item not found: " + results.getErrorDetail()); . A$ P+ L$ [/ p$ p- a; w
  return; - A. m1 a3 p$ y  \6 t
}
; J+ b0 `1 q3 H: W   N( x* x8 y2 u3 e, B6 X; I
// Get a handle to the BOM Items. # B9 n/ Z( `- C# t- o6 O7 T( }
var bomItems = results.getRelationships();   n# ~3 S& |2 P& z
var count = bomItems.getItemCount();
" [% `7 i" Z( B+ ~$ _$ s * D  y6 W" i7 p6 C" t. S
// Create the results content.
* D& b/ y, \% u8 y/ kvar content = "<table border='1'>" +
' Q# r+ E0 d" z  }) [2 Q+ G+ S+ I6 O% G  "<tr>" +
0 G5 h4 G2 }! X0 O. }/ x    "<td>Part Number</td>" + / e+ H* F3 f6 s
    "<td>Description</td>" + 7 D$ h9 S5 E& X) l; C; w7 G7 H
    "<td>Cost</td>" + 4 F- D9 c/ _3 m) f. w6 F
    "<td>Quantity</td>" +
3 z1 q% ?* i( X* M" ?# v/ B' t- l% N  "</tr>"; 5 I0 i: c2 m: G. B4 a- W- y( G; ~
* I& ^9 P& [' i: x' h) Y8 m
// Iterate over the BOM Items.
1 A5 A1 F5 ?( K6 |, e$ e- |: @for (var i=0; i<count; ++i)
/ U6 o% U% h% }- m- Y1 g{
7 u/ a9 ?5 A( Y0 y* [$ \- g" S// Get a handle to the relationship Item by index. 9 W/ C8 L8 M; e0 H) E$ w- r
  var bom = bomItems.getItemByIndex(i); 6 \) {- ]! K* t# y5 L
// Get a handle to the related Item for this relationship Item. . ]! y( `+ {3 j# R0 G9 u
  var bomPart = bom.getRelatedItem();
' K) @4 z; V! p) W
% u# K" `5 w2 X' R1 y, V5 W  content += "<tr>" +
9 p  ^" \8 r6 ?# w) }0 ~/ _: U      "<td>" + bomPart.getProperty("item_number") + "</td>" + $ Y4 `% a8 ]1 S: B1 h: O5 e
      "<td>" + bomPart.getProperty("description") + "</td>" + 0 H3 x5 ~! y8 @8 [, e; C
      "<td>" + bomPart.getProperty("cost") + "</td>" +
0 t* K  L5 x% J      "<td>" + bom.getProperty("quantity") + "</td>" +
) l. ]9 c9 i5 \0 |    "</tr>";
3 l' |1 S5 ^1 i" X3 |}
! o$ T" J6 e( o; b# A: \return content + "</table>";& t9 }* l) w% K9 l7 {" Y1 j
- i2 W; E' m1 _( z" R
8 p$ \/ P( p) u$ ?1 h/ v
4 i, q2 r# ~* T6 a
6 q$ }' t7 H6 P
C#  + W2 F. r  z. K+ O% }9 g0 |- m
Innovator innovator = this.newInnovator();
. y+ O# O' r% Z3 m* O% p ; Y1 H+ t- M0 T; @# A0 g/ u+ I
// Set up the query Item. $ ]# c0 u$ M1 v1 |5 b
Item qryItem = this.newItem("Part","get");
8 Z  Y- ~6 G' F* lqryItem.setAttribute("select","item_number,description,cost"); ( n! E4 r) ]: Y# }6 o" I
qryItem.setID(myId); # _  x8 ^  i+ E& s* A/ m
/ M& m8 p; f$ ~8 S( h7 Z! I7 R9 X
// Add the BOM structure.
1 G- }) n. b* A0 v# n- Z& FItem bomItem = this.newItem("Part BOM","get");
/ N* g5 u) {, Y7 q- |9 IbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
6 @3 F0 L- ~  v% X# I! yqryItem.addRelationship(bomItem);
& ~8 i' ~- U  p 7 ~0 W! V  T0 E" D
// Perform the query. 4 v$ a3 x8 B) j, V& P; q6 y; K2 Q
Item results = qryItem.apply();
# C% v& P+ ?+ X9 ^
* F( P5 M& ], z: ~// Test for an error.
: a7 J, x, H) q2 b9 b  Sif (results.isError()) { . y# m5 J0 u. I; B5 E
  return innovator.newError("Item not found: " + results.getErrorDetail());
2 j! V+ ?. \( Y3 y0 [7 Y} & g5 z* ?# J4 b

+ g- {) D& u% k; ~& g$ c- ]' G// Get a handle to the BOM Items.
! S9 R/ C; r; g3 K! U# AItem bomItems = results.getRelationships(); ! U1 g6 E9 _' o. V' g$ [: t
int count = bomItems.getItemCount(); ; M( C/ I0 Z. c( }9 w8 G
int i;
) P  b5 k8 W. V5 y, j5 K
7 B& D$ F3 O" U6 @  y// Create the results content. % }! a. H9 m* ]5 _# o( f; [9 l
string content = "<table border='1'>" + - ^* p, G5 N( w, H
  "<tr>" + ! m+ D; S$ e. j$ K$ r
    "<td>Part Number</td>" + ' B- m- ]: o9 P! q
    "<td>Description</td>" + / z2 F% t8 P$ ?: n1 Q# a) ]
    "<td>Cost</td>" +
9 L  T7 a, r/ Y/ {& z7 o" z6 ^    "<td>Quantity</td>" + . `2 c! h6 U/ d! d! c+ J
  "</tr>"; 9 O" l4 @6 a+ Y+ s8 q/ h
* W+ `% c4 P) h6 [( S) w# T
// Iterate over the BOM Items.
( k9 J+ |3 |" d* x: Bfor (i=0; i<count; ++i)
- i" A' }, C5 U0 v4 s{ 4 V5 R) E, y- _( U4 o$ I
// Get a handle to the relationship Item by index.
2 X% p7 a5 e" u  Item bom = bomItems.getItemByIndex(i); . g; }/ l/ K& D- g# ?0 s
// Get a handle to the related Item for this relationship Item.
; E$ r. ^, ?! D" P, W  Item bomPart = bom.getRelatedItem(); 0 N+ |1 {! n. [# B' S
% |3 N3 f/ {+ o& \: U
  content += "" + - Z4 V5 |9 @3 c3 ^$ s
    "<tr>" +
( x& h! s) C9 W. D      "<td>" + bomPart.getProperty("item_number") + "</td>" +
% d: |& H8 _- ~9 D1 G% G+ B; e      "<td>" + bomPart.getProperty("description") + "</td>" + 7 B1 Z7 S" F3 j# J
      "<td>" + bomPart.getProperty("cost") + "</td>" + ; T% n% L- I# r
      "<td>" + bom.getProperty("quantity") + "</td>" +
4 E; e% p1 u. q! u. v    "</tr>";
$ Y9 ~6 p0 r2 G2 O}
2 \3 x7 M8 g8 [, x, }7 g9 |content += "</table>";
$ B2 {2 g( i5 C9 z& Z
) f0 q( J" Z* g; ]0 v. _) i: U7 n6 dreturn innovator.newResult(content); 2 h* K* V( X7 @2 ]- g. e* U: n5 h: h

% ~5 P9 D5 v/ z: R

( n) `- A, c0 h7 t) ~- r0 M, [/ _4 S7 }) ^6 I
0 ?% g/ n2 f! y0 k* u' R- w$ K

. ]: ~* D) ?1 t9 R/ C5 P

- d% H; Q* a: N/ t  m! i* Y4 P 3 e, o7 B3 ^1 {: H/ \" E- L4 Y8 Q
    Page 46 & Z. R% v" `( d, `1 P3 D$ z3 u

4 V- k& [( t$ u; w* i0 ~/ o, XCopyright   2007 ' h* A0 O0 m, s1 ~
Aras Corporation.  7 o' X1 \' P$ F' Y/ a( M) G7 y! q7 f
All Rights Reserved.
* j5 _( f2 z$ ~* K! @VB.Net  
1 v# [4 y6 X! \2 b9 T, B& MDim innovator As Innovator = Me.newInnovator()
5 L9 c0 j) j' Z. Z
8 M: o* g5 ^9 E# w5 \, B' Set up the query Item.
& g- P3 u+ p# Z0 C1 kDim qryItem As Item = Me.newItem("Part","get") 0 t& j5 Y( b% R( g. I+ F! T. k
qryItem.setAttribute("select","item_number,description,cost") 5 u; B2 W' v" A' L5 J1 ^
qryItem.setID(myId)
& N3 e  M8 e  S  h' S  a , ^( C$ c( w; O8 T2 k# f
' Add the BOM structure. + ^/ W& e: R% ~8 W
Dim bomItem As Item = Me.newItem("Part BOM","get")
( Y2 C) [- V, C; f! D" g6 p+ g- }3 ^bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") & T* e5 }, H) ^' s( p5 R0 @4 g
qryItem.addRelationship(bomItem) ! Y  F. H$ v4 J: R; J1 y3 a# D
; v+ r- V' G$ I& W+ {( O
' Perform the query. 0 w: L( p# q1 B* [2 \
Dim results As Item = qryItem.apply()
9 \0 D4 L- ~2 n" N) K) n: y
/ p) G' P  O. H* Z! h: R' Test for an error. 6 q9 z8 J/ C4 m: ^9 R1 q1 k
If results.isError() Then * r- L+ l# G, [8 x2 s* b: n- [4 ]( h
  Return innovator.newError(results.getErrorDetail())
( g" C, l* b( pEnd If : _$ j7 r9 v4 ~4 p2 ?; G. ]2 O

+ s. B/ x# e  K' C' Get a handle to the BOM Items.   N% f& U- Y7 U; X( ^6 f6 ~0 ^
Dim bomItems As Item = results.getRelationships() 9 S* |5 j$ _, y* J
Dim count As Integer = bomItems.getItemCount() % n. g8 M2 _" s: ]& |
Dim i As Integer
% G5 x, }# }7 e7 s: [1 S  L2 O
  x6 w# l3 k4 _+ |* ~' Create the results content. # [( W; a) ^% n9 Q' Y( |
Dim content As String = "<table border='1'>" + _
5 c: p% H7 j# [& R$ e  "<tr>" + _ : i5 P! K: o$ U. _
    "<td>Part Number</td>" + _ 1 c4 H1 k# x1 @2 w% N+ [" R- e6 x
    "<td>Description</td>" + _
3 Y( \+ u2 [6 q5 P6 Z/ \    "<td>Cost</td>" + _
  g+ x9 ?* N% c    "<td>Quantity</td>" + _ + z6 Q( `7 |1 v' I- W
  "</tr>"
+ R* R# L2 z1 X ( ~" R. V9 m0 x: F
' Iterate over the BOM Items
, x1 ~6 F/ M+ z& a5 H* z* ^' @For i = 0 To count - 1 & {4 F" Y$ |  |0 j
' Get a handle to the relationship Item by index. 1 l: N) ~9 @3 k; t/ Y9 v
  Dim bom As Item = bomItems.getItemByIndex(i) 4 e2 Y. J% |, @5 |+ i+ P

2 V/ t. b2 Q: M- @' Get a handle to the related Item for this relationship Item.
7 C( ]+ n* U: U* Q* T+ V' P" t  Dim bomPart As Item = bom.getRelatedItem()
, s( [' j" e* l1 n , r3 ~; ?& M$ c# j) K0 ~) s' F
  content += _ - \; x  W: Z  I) G( o) p* T- D
    "<tr>" + _ % A  w  E, X* X' t) D
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
4 k# `8 D) _1 @7 D) p( v      "<td>" + bomPart.getProperty("description") + "</td>" + _
  Z; T6 y" h8 O: {- Z5 k      "<td>" + bomPart.getProperty("cost") + "</td>" + _
$ b. S& i- m. k! I& c      "<td>" + bom.getProperty("quantity") + "</td>" + _ 1 X- _! Q* t8 w4 o( v
    "</tr>" 1 N5 E/ x$ f' a; e& L. B
Next $ Z- Z7 q  b4 [5 s' C# M  Z+ P
content += "</table>" 3 ?9 `- w) K1 d* Z' s/ z0 g* \2 S
8 L( e0 T5 R$ o; W3 f; K! d0 W
Return innovator.newResult(content)
/ P9 m! G$ _% o3 K4 d" z. Y
, _- M) U0 s. U5 x4 h& T& z3 s3 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二次开发专题模块培训报名开始啦

    我知道了