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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  - w7 s. t8 r8 y1 r8 ~6 N' V  M
To query for an Item and retrieve its structure you build the query as the structure * o/ y5 T4 E6 E
you want returned.  Use the IOM methods to add the relationships you want and % p) }  y6 e4 r4 t! `: ~) Z+ e3 Z
build the structure in the Item.  The server will return the structure that follows the - B9 C; i% M9 T3 S" U4 M! A
request structure. 8 ~6 A3 N# B$ o# e* I
This recipe illustrates several related concepts together, which are how to get a set
, D! W! w3 f! r- y1 ]6 }! eof Items from an Item and how to iterate over the set, plus how to get the related
8 X6 T  w0 r% o* Z. x4 wItem from the relationship Item.
2 K; U3 e; p0 T8 E9 \: |' K. pJavaScript    _% f9 t8 G$ {# H0 m  _3 W
var innovator = this.newInnovator();
8 T; O1 T+ r% N9 _, i6 ^9 o8 l, H, | 2 @- x. I) a, _) \( ?* f- r
// Set up the query Item. ) \) {" T  R2 v+ x
var qryItem = this.newItem("Part","get"); $ }& h. T4 G6 O+ P0 ]5 u: D/ [
qryItem.setAttribute("select","item_number,description,cost");
* b% n- R! L; FqryItem.setID(myId); 7 ]2 J! m+ K9 p7 u1 q
$ v  l$ e4 `0 J9 A: v! w' T# T. X  P
// Add the BOM structure. 9 ]$ Y# Y, a( J( A
var bomItem = this.newItem("Part BOM","get");
) t& X' }" k7 c% u) a7 LbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); , @- c! T% z! F, F! D* z% ]: P
qryItem.addRelationship(bomItem);
% X/ H1 l" c$ L$ e/ Z+ m
: z% {+ K) g* o// Perform the query.
4 r. R" w; z/ O/ l9 x! Mvar results = qryItem.apply(); $ M  b6 o4 ?+ S. z
6 Q) H% }6 |3 h4 h* K7 m* q
// Test for an error. 1 u3 [6 Q5 K9 P+ L6 [% g; l( `
if (results.isError()) {
  ?% d; q# o! a  top.aras.AlertError("Item not found: " + results.getErrorDetail());
/ N2 X. Z( j, D9 @# Q8 s9 o9 t7 j! `4 ]  return;
$ t$ g' T$ S0 b/ F0 K}
- D1 }0 p9 y( b0 C/ o9 ?
! @( S# g9 q/ E7 W: g5 V// Get a handle to the BOM Items.
& S' l7 t0 n6 G$ ?var bomItems = results.getRelationships(); 2 ~8 X  s6 j  F8 l+ N
var count = bomItems.getItemCount();
( z$ [/ v$ u! Y9 A
! b. R7 M) x" Q8 j1 L; t// Create the results content.
9 @$ q( H, c7 ~( t0 g* f3 gvar content = "<table border='1'>" +
9 C' v/ {; [4 X  "<tr>" + $ g6 @# O% f9 C) w* Y
    "<td>Part Number</td>" + # Z0 J, |$ u  S% O0 U
    "<td>Description</td>" +
8 a) r! s! \* P1 `3 J    "<td>Cost</td>" +
& a; Q- @) j2 Y& S    "<td>Quantity</td>" +
, @2 V. ^) ?  [& u, |  "</tr>"; $ \4 z! H% l& E$ J. Q

0 O6 I; a; H( ^$ U% A+ n4 i) {// Iterate over the BOM Items. 4 f! t/ x1 R! Z- w6 M" O
for (var i=0; i<count; ++i) ' J" i- l; i. x. B/ M5 B. C7 ^) X: D
{ ) Z4 z! W% V: ?
// Get a handle to the relationship Item by index.
: U3 l7 R4 X0 p  var bom = bomItems.getItemByIndex(i); * N: N; x5 P2 y  e0 x7 I- _
// Get a handle to the related Item for this relationship Item. 2 R7 ]' n- S0 J+ ]; T
  var bomPart = bom.getRelatedItem(); 0 w% G  k3 P% A

, X0 z  X& E$ ^6 y: p  content += "<tr>" +
0 f! f0 P/ I4 x' S* I      "<td>" + bomPart.getProperty("item_number") + "</td>" +
5 m, Y& c4 @9 E/ r, Z      "<td>" + bomPart.getProperty("description") + "</td>" + ! r7 L8 R$ m, h* O
      "<td>" + bomPart.getProperty("cost") + "</td>" + 0 A7 {: P9 [9 _' T, Z% h$ D- A9 r; E
      "<td>" + bom.getProperty("quantity") + "</td>" + 9 {0 l" S8 x/ Y$ d: b# H
    "</tr>";
1 }3 F& A! K* K}
7 _% V: l9 A. V% b" Oreturn content + "</table>";
- F# `$ E+ b# M# y6 _7 M+ f0 N/ K& J$ ^4 Q% S# U

2 w8 O! r$ J3 u, b  ~! \- I
& T8 w& m$ {. A; w
0 u4 y1 t6 b, e! k) ?" q/ S
C#  9 F+ _) G4 H* G& h6 F( ?2 a2 C' q/ e
Innovator innovator = this.newInnovator();
3 D( V6 b" D: Y) \2 n0 @6 s . c. n- P+ M6 |, L
// Set up the query Item. 5 B  [. ^' e+ W  R  Z
Item qryItem = this.newItem("Part","get");
) i5 B2 H, m- h6 f# lqryItem.setAttribute("select","item_number,description,cost");
6 \8 ~, z  P* N" n% A6 _6 tqryItem.setID(myId);
  M1 v- ^. D1 @+ w# R 7 T4 D) _5 R5 q% c6 \
// Add the BOM structure.
8 N* E1 n; g7 F+ iItem bomItem = this.newItem("Part BOM","get"); " W$ J  t9 i8 T9 J2 W
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); * v! L$ @7 u- V6 d. D6 v/ y2 _
qryItem.addRelationship(bomItem);
& e2 d4 K) A9 s' n
+ R9 ]5 ]7 {4 V  S1 z// Perform the query. : \4 W- U+ y( G7 Y5 Y2 R
Item results = qryItem.apply();
; Y. Q  f6 S* B* | 5 `3 q; \. m' w7 ]) n: T
// Test for an error.   I% y: N- c- `' p. a! B
if (results.isError()) { " }& Q6 `. n9 F. ]- ^, O- K
  return innovator.newError("Item not found: " + results.getErrorDetail());
& M6 s6 T4 q5 h9 z# z- t' h}
+ g. r, e6 ?6 R& N' [" y( d) H
! F2 N2 J1 T  z: e4 H2 F/ A( T// Get a handle to the BOM Items.
$ b& O6 Z$ ]* n& mItem bomItems = results.getRelationships(); 7 o+ m3 j3 N6 a2 f- u/ Z
int count = bomItems.getItemCount();
! Y4 n+ {: o0 h. ^/ ?int i;
- B9 ?5 m! ~. W
9 E" p5 }; S$ ?# O1 k// Create the results content. 6 @' O$ E; A6 l5 P7 t- @" ~; I
string content = "<table border='1'>" +
' d0 J6 d- G4 D% g% Z4 p3 f  "<tr>" +
" {. E( d; `4 }! z0 k    "<td>Part Number</td>" + 1 U: [( ]& `& K) N, }7 p  e* ]
    "<td>Description</td>" + $ D5 H& K9 g* W3 V  v
    "<td>Cost</td>" +
4 d; e. Z  h% o3 n6 {    "<td>Quantity</td>" + & Q) {% c) D8 k5 p" y: H$ I: H
  "</tr>"; ! E: |  L2 b) q* r

( \8 l# f. r" {: x) @7 w% q- V+ ]// Iterate over the BOM Items. ) E5 ?; l- ]! A) E" f. L, J1 c
for (i=0; i<count; ++i) ; i$ V& ?- c* {0 z
{ 5 m- {  U* H4 }! z2 f8 E/ V, F- j
// Get a handle to the relationship Item by index.
; k* f0 Q4 Q; t, w" C! s; O  Item bom = bomItems.getItemByIndex(i);
0 {( F0 F. K% H& z# q// Get a handle to the related Item for this relationship Item. 0 I/ o+ a( z: \  F8 u5 Z9 h0 s
  Item bomPart = bom.getRelatedItem(); 5 z+ x8 h3 k! b% Z
8 B, f5 L& O0 s. ]/ j
  content += "" + 3 \4 T/ _6 M  X0 Q" w2 x1 P
    "<tr>" +
: {" v9 Z; H7 U# @; I& n      "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 |7 U0 n) f& j5 }. G$ T      "<td>" + bomPart.getProperty("description") + "</td>" + ( R6 }, r+ i1 l* }" |- V9 ^. X$ k
      "<td>" + bomPart.getProperty("cost") + "</td>" + : [' W' q# B' F3 [
      "<td>" + bom.getProperty("quantity") + "</td>" +   y! A: {. y) a2 Y' n. c
    "</tr>"; " q* U0 _+ ~$ I' w% P1 M8 }
} 2 g, l9 j# z+ r( H' \6 `: q7 U
content += "</table>"; ; Y" Z0 N9 D( t1 ^. k
6 ^$ o  V% F" ]
return innovator.newResult(content); % G& A6 }! z% K( e1 }! b0 S

. D4 S; L, R% C9 _2 w; R( Z

' `8 p. w3 o0 f4 P9 W9 p, W& D! g6 b
+ L2 }& Q5 B) r: z4 W2 P4 }$ p
" ?$ }# d7 a- C

2 E2 i5 a6 T- o/ u. c8 X% O% ^! e
4 E# B0 ?% p8 ^+ }    Page 46
3 x; z) P6 c! j5 a% u 7 ~/ a& L( B' F; Y
Copyright   2007
, m: L0 i! S+ k7 p: R9 A0 T+ IAras Corporation.  
* d: u. o; O* T; MAll Rights Reserved.
( P& H. H5 x  i! W: I' @VB.Net  
& Y& g! c8 T) R1 U& `8 x  xDim innovator As Innovator = Me.newInnovator()
; g+ @/ Q+ O+ }" D
5 N) G5 P! t) x7 k" g' Set up the query Item.
7 ~( R- q/ @# @3 j6 LDim qryItem As Item = Me.newItem("Part","get")
  \" \4 D0 u) U& s  M0 lqryItem.setAttribute("select","item_number,description,cost") ! K/ k  b0 U- g0 {
qryItem.setID(myId) ( ~0 H. u$ Q) Y" n% T* `; M( |

1 l: G7 N& K# a' Add the BOM structure.
! q1 H" ~) m. L: oDim bomItem As Item = Me.newItem("Part BOM","get")
; V4 z! a% Z7 ~% R3 XbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") % p; l1 H3 g! @$ z6 v2 S
qryItem.addRelationship(bomItem) ; j, B; N( F  K& w9 \2 C$ k
/ r! w. h4 |& b' x3 K
' Perform the query.
/ d; m. }4 z; UDim results As Item = qryItem.apply()
6 L; q6 G. W2 a* q+ h) J# w
+ j* l  l+ i- I8 ^' Test for an error. * E& I6 [: |4 K8 Y% V$ m
If results.isError() Then
. t8 l1 J2 D4 U, O  Return innovator.newError(results.getErrorDetail())
6 T- a* Q! J( N9 \1 |- TEnd If # V* `- ?, ~5 i. C1 |: l0 {. Q2 f3 _

. }) u0 ~# t9 I  Q) z' Get a handle to the BOM Items.
5 P# f" Y9 V6 J. aDim bomItems As Item = results.getRelationships() 4 f) C$ T: X( v$ h% n9 i
Dim count As Integer = bomItems.getItemCount() 3 s9 N, |$ S$ n+ J" ?$ S" H
Dim i As Integer
/ t* W, J; @" X5 D
$ {: X3 ]" d: I, Q' Create the results content. $ t5 Y4 j) ]0 f1 F6 A, c: J. r
Dim content As String = "<table border='1'>" + _ ; I, R' \5 W+ o1 o$ R
  "<tr>" + _ , _  x, }5 i  [- b  x
    "<td>Part Number</td>" + _
/ e( z# |, E* p; B2 ^    "<td>Description</td>" + _
9 V$ d) l5 R5 z    "<td>Cost</td>" + _
! P! T4 Z7 `# h: w$ _5 H    "<td>Quantity</td>" + _
) ^; ?' f9 x8 Q  g/ o  "</tr>" : L+ }$ @8 S" M! _$ j

) j6 ?- o) {' E* Y% L+ [' Iterate over the BOM Items
3 b! X6 j! q3 `) ]7 s/ @For i = 0 To count - 1 ) v/ H, ]0 y% [! `1 M3 Y
' Get a handle to the relationship Item by index. 6 q8 Z2 ?2 s. [, q/ `# j2 E& @
  Dim bom As Item = bomItems.getItemByIndex(i)
6 T/ u  O3 o9 s" w
7 F1 }; j$ ^7 I; V1 X. t' Get a handle to the related Item for this relationship Item.
) l( X8 H8 p1 X  Dim bomPart As Item = bom.getRelatedItem() ) [# N' Y' v5 Z; e+ Y9 F# ?, Z: w

5 M  M# I5 h. \9 _  content += _
% K1 s: ?: o7 ?8 \/ [/ g& s    "<tr>" + _ & `. f6 P9 E! m4 ^
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ( Q) i' A6 U9 M9 |  N( C7 D1 |. i
      "<td>" + bomPart.getProperty("description") + "</td>" + _
' B) [) _1 s3 O! J4 m      "<td>" + bomPart.getProperty("cost") + "</td>" + _
% Y) v6 h8 Z9 K+ b      "<td>" + bom.getProperty("quantity") + "</td>" + _ ' P5 Y; z% Q3 X; o( O4 v* B
    "</tr>"
. f0 Z" c, v1 i0 F( `) T+ GNext   ]& Z$ K: M; Y  u+ w" U' l
content += "</table>"
2 {8 X2 V9 y+ p1 m- q5 H( v - p, j: L: e8 g4 [0 `; O
Return innovator.newResult(content)
# I8 D4 G- x1 ~  U1 z: C7 T. t! l  R
# Z- O2 d% H7 ^' [( S8 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二次开发专题模块培训报名开始啦

    我知道了