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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  ' E$ R: J! H5 m$ [1 @$ q  j/ ^# [/ D
To query for an Item and retrieve its structure you build the query as the structure . g; G6 r, `& I4 y- f
you want returned.  Use the IOM methods to add the relationships you want and 1 W- T/ h% P9 f# i1 }5 A
build the structure in the Item.  The server will return the structure that follows the
* B- I7 V9 ?- z; z8 r* ~request structure. ! N7 f! v& @. \1 g
This recipe illustrates several related concepts together, which are how to get a set ) {* ?0 B8 a. {! v6 q- Y! ~
of Items from an Item and how to iterate over the set, plus how to get the related ( L& q: u% d/ [9 [/ W
Item from the relationship Item. . O' P6 P/ S1 C! o0 _
JavaScript  , j7 M; R) f: Q* [8 c0 v
var innovator = this.newInnovator(); ) d) x7 X" e* o# H8 V- F
+ w. l: t( e1 R4 y
// Set up the query Item.
2 R2 s, G# h7 ]/ |var qryItem = this.newItem("Part","get");
0 ?  V1 X1 M0 g0 B+ v# FqryItem.setAttribute("select","item_number,description,cost");
  U* J7 W4 `8 M1 f" n& B/ }' j7 `qryItem.setID(myId); + m! l0 e. c  g

! A$ T' {) D+ O  F// Add the BOM structure. 7 _6 g6 ?/ E2 c: a1 R, D. x
var bomItem = this.newItem("Part BOM","get");
' I; V* t! y  O/ ibomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); & [* [; r, |6 n. Y2 D
qryItem.addRelationship(bomItem); / }& D  S" a. P/ z0 J
% X9 N( f8 E* p2 Q+ U, k7 A5 z
// Perform the query.
  n- A  j4 s  d3 w" D' fvar results = qryItem.apply(); / G& e$ U9 T- R/ C# G: G
2 u/ r8 }! q, V7 H
// Test for an error. 5 X/ {" A7 p2 l, ^9 m# b+ b. z- V
if (results.isError()) {
; a. y' o8 N; V# [  top.aras.AlertError("Item not found: " + results.getErrorDetail());
1 x2 w2 G4 [' N1 u) B  return; % o9 V0 k' P& m# C2 Z
} ! F" u4 `$ D+ Y7 s

( z- s% V6 e- d- A- o) ?* K// Get a handle to the BOM Items.
1 ?- z7 y! b% J: q! @3 [: kvar bomItems = results.getRelationships();
% d/ E& A5 c- ?0 j& _) Gvar count = bomItems.getItemCount(); / x6 F8 @! ]6 V$ V/ \8 e6 h
9 b, c' X1 b% A2 G
// Create the results content. . u" g, v  K/ A# i5 j
var content = "<table border='1'>" +
2 M  c$ t, p# _5 B+ h# [5 \) H  "<tr>" + . u! T! q+ N+ _4 b
    "<td>Part Number</td>" +   G9 ]) m* S4 W* ~; w
    "<td>Description</td>" + ! G6 d8 w! d: k" C
    "<td>Cost</td>" +
* C4 A; Y4 O5 P' ^+ \& ^# U( Z    "<td>Quantity</td>" + / |5 V' Z; o3 Z; c5 u. M8 i. D  q. G$ q
  "</tr>";
1 s( g0 [" u% E( |+ Y$ q2 k; r
& J+ P! U/ b, k// Iterate over the BOM Items.
6 Q. B- u8 X" d# Jfor (var i=0; i<count; ++i) 7 z( v, k4 C* _- c
{
1 r- r0 x3 M" p$ m! N7 K5 ~// Get a handle to the relationship Item by index. " P# z! T# _" g' z" g
  var bom = bomItems.getItemByIndex(i); 7 W& O$ p- l+ m* I9 P3 h2 ]
// Get a handle to the related Item for this relationship Item.
5 V+ ?0 n5 m$ A4 @  var bomPart = bom.getRelatedItem(); 9 U8 V3 V' F. n# w. Y

4 C1 e, w# g- [1 h, F* N- n( F  content += "<tr>" +
$ `2 H* k! F) E      "<td>" + bomPart.getProperty("item_number") + "</td>" + , ~. d. ~* M. l9 F1 e* M
      "<td>" + bomPart.getProperty("description") + "</td>" +
0 p& J/ j" N) u+ K0 k" Z      "<td>" + bomPart.getProperty("cost") + "</td>" +
# U. H. P& G3 b: i  K0 p      "<td>" + bom.getProperty("quantity") + "</td>" +
7 Q5 ?: _" l) K, b    "</tr>";
4 d" D) q3 \( l} " s* t0 U6 D  Q- B. ~5 g
return content + "</table>";% X6 x4 L, r* i1 g, h

; {+ ]# G$ `, a7 E- ~) j- b5 R

3 ^3 m' B. d) T6 }$ Z" |. f
2 r  ~$ P% \  W, g4 [. M+ Y7 M

. J% Y+ i& F' IC#  - V  U: ^+ {  R) Y7 Y
Innovator innovator = this.newInnovator();
, j4 D% }2 b5 E! Y% a
# Z% n; C4 `0 \// Set up the query Item. ( G. ]6 B+ y  A9 R, `3 c6 e" i
Item qryItem = this.newItem("Part","get");
) N7 u" M. }! EqryItem.setAttribute("select","item_number,description,cost");
( k% z" O; T/ O& ]9 WqryItem.setID(myId);
/ O" M% f6 L: p# d
, n+ H9 O9 w: R  t0 X" H// Add the BOM structure. 7 Q) ^& b! Z% k3 a1 I. N# c
Item bomItem = this.newItem("Part BOM","get");
* X* n' R- t. H. ]bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ' Y9 |& ^/ a) y' `
qryItem.addRelationship(bomItem); 5 N  k- q; X1 V5 W6 T

$ S4 |" R, a  S2 x// Perform the query.
  Y& X) _& H' b- o# bItem results = qryItem.apply();
& x2 D. x5 E2 n 1 u3 }- Y) _3 i; M7 f* T" L& i
// Test for an error. . b! @; {# _6 e
if (results.isError()) {
3 C$ Y! j( Z1 S' Z1 Q" D  return innovator.newError("Item not found: " + results.getErrorDetail()); & O8 u; q% o. f- R" Z% w* C
}
' O4 V+ |/ h9 \/ C5 v; \, ^
+ r2 C! p4 b% a, f9 |& u5 i2 {, f// Get a handle to the BOM Items.
5 ]/ E$ a: R0 K& I: v# [) ?0 VItem bomItems = results.getRelationships(); ' w- p3 Z1 u% C' ]( y( m4 ^
int count = bomItems.getItemCount(); " z9 ^, ~0 j* A: _( C7 g3 N& P
int i;
9 H, d0 @% w7 C8 d6 x6 x! {  V
7 `0 T. v3 V& X5 \% q/ r// Create the results content.
: T% ?; ]& d% m/ M* |8 Qstring content = "<table border='1'>" +
1 K5 [6 f7 k9 J, ^  "<tr>" + # T& w3 c  w1 d1 ~- L" x
    "<td>Part Number</td>" +
, o1 V  V$ C5 c0 X    "<td>Description</td>" +
( k: w5 `+ s0 n* }9 V    "<td>Cost</td>" + : b+ g5 E9 R& l! w& V
    "<td>Quantity</td>" + ! v3 H& }- z) d% B1 d# n/ N% X
  "</tr>"; 7 h( T2 K7 z7 E( p$ L% Q6 l

4 l2 q! {! g9 J8 e( Q// Iterate over the BOM Items.
9 W! s  i# Q# `for (i=0; i<count; ++i)
' P1 I. W9 D8 Y) F' z9 X4 t{
, J9 X) A# Y" j& w: u1 ?1 T// Get a handle to the relationship Item by index. ! v* Y/ D. o! c
  Item bom = bomItems.getItemByIndex(i);
3 I8 Z6 H- X0 `9 {  o- j// Get a handle to the related Item for this relationship Item. 9 e1 e. \& @6 F. d
  Item bomPart = bom.getRelatedItem();
- H) U: L& x$ X. U
0 k  J0 F; r9 u% |6 f  content += "" + 5 e8 x0 d, b( f6 S4 r
    "<tr>" +
# h5 `/ K( B6 {0 t8 B7 ~      "<td>" + bomPart.getProperty("item_number") + "</td>" + : R& ?- A3 I& e7 w9 r+ B7 f
      "<td>" + bomPart.getProperty("description") + "</td>" +
' k8 A  m# G' `5 a0 a0 b      "<td>" + bomPart.getProperty("cost") + "</td>" + ' G3 P* o: S+ r0 `
      "<td>" + bom.getProperty("quantity") + "</td>" + 2 y( x1 k) G- W/ C# u% y! s- p, [
    "</tr>";
2 c+ \, G8 ?3 [) J- _}
$ U" v3 ~3 b  E) S, `# Vcontent += "</table>";
: n# [& P0 U' t. ]. r# E+ |/ Q 1 k1 i+ G( d# a7 }
return innovator.newResult(content); ! Z' f# _7 `% P( i: u

# C4 k. }0 S& x$ ?
: r2 I2 j/ M( W

. X9 ^: \5 {; u$ O

; h- u/ r. o/ v1 q& C! K( m& B7 W! W) N9 [
! q4 E! _8 z' D- y3 E! U' ^) q+ ^. P( Z
( S; i6 @5 F" E( M* f; _" z
    Page 46 $ B3 z6 P6 C1 K$ t) y8 ~* G& V  {

3 a8 c* {+ e2 Y2 c* B: D! v: |Copyright   2007 ) C" b& u9 Q0 u$ g
Aras Corporation.  
' i% g  j' j- z; LAll Rights Reserved.
: _& c2 d( z. k; ^+ K# s$ y3 ~VB.Net  
! t* m8 E7 g& E* q1 I+ qDim innovator As Innovator = Me.newInnovator()
8 p' R, l# ]& K1 u) C/ m  y: d . k, P" p% k# _
' Set up the query Item. ' C' p* f+ B& ]  h  i$ y: u
Dim qryItem As Item = Me.newItem("Part","get")
7 P0 S$ Z8 ~' NqryItem.setAttribute("select","item_number,description,cost")
" a5 g' H3 ]8 j- Z! b$ m  ~qryItem.setID(myId) ; a7 O* j( J" }1 c' D
. ^& o7 s  ]( P1 w. u
' Add the BOM structure. 6 y7 t4 m& [% N! k" \  g3 a+ t
Dim bomItem As Item = Me.newItem("Part BOM","get") " U, A/ a3 }6 m5 \' P: M
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 8 X5 A$ E9 S9 g+ ?' Q+ g
qryItem.addRelationship(bomItem)
8 ~- ]+ p& Z0 h& M
5 C0 F0 n$ i  a# D2 {1 t' Perform the query. , O* M. t  d8 R. i
Dim results As Item = qryItem.apply() ( U+ i  _1 ?$ w0 X9 M

* Y; k' H5 g' ?4 ?' Test for an error. 9 q$ y9 I2 ?4 f0 i) j& i% I! z! p
If results.isError() Then 5 h$ W4 q: Q1 A& x
  Return innovator.newError(results.getErrorDetail())
3 Q0 y, R7 X. b. P9 P* ~End If 1 _1 v1 D- r9 p: F' v( b7 W

1 ^( n- [: }3 j' Get a handle to the BOM Items.
) j" U. d8 C9 K: zDim bomItems As Item = results.getRelationships() . L/ K8 a9 v- F- ?
Dim count As Integer = bomItems.getItemCount()
! {" S( N' ^7 T; q# ]: LDim i As Integer
$ U" T) j$ e$ e2 B1 K/ j# Y 8 [2 ^7 l* o; s) i3 V6 x; z
' Create the results content. * u0 |9 W& l# Q+ A4 H: T- K
Dim content As String = "<table border='1'>" + _
+ q! T4 T3 {; N  "<tr>" + _ 5 h% \, \. r7 z* N$ {! h% t
    "<td>Part Number</td>" + _
- K4 y( B3 k/ S* E9 H! W    "<td>Description</td>" + _
8 I5 t+ x9 K- @+ W/ a    "<td>Cost</td>" + _
- j0 c' I& @) m' g4 M    "<td>Quantity</td>" + _ 0 C# ?; M  k+ W5 D, b
  "</tr>" : O9 [# r8 ~+ r) x$ t/ v% U
) q% V* w( r$ M
' Iterate over the BOM Items / S- E& U& T, p! y% ~% @3 H" n* ~6 z! o
For i = 0 To count - 1 . t; d% _% q$ i+ M' f7 h7 R. g; N
' Get a handle to the relationship Item by index.
2 Q$ E# V+ U8 _, X  Dim bom As Item = bomItems.getItemByIndex(i) 6 e- h% W, w! S: }+ u/ z7 `

$ Z, D- C$ f$ d4 O% \' Get a handle to the related Item for this relationship Item. 7 p5 j; @  `; G3 Q8 N5 ~* U3 t
  Dim bomPart As Item = bom.getRelatedItem() ' u3 j/ j* _+ t0 o6 \! ]

' u. r" X: f5 S4 P6 a) f  content += _
. L8 E) F4 {. C& f" e    "<tr>" + _
5 X. s2 D/ ?/ m! L4 {, j. A      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
, x% {9 y* r" m8 @$ I      "<td>" + bomPart.getProperty("description") + "</td>" + _ / h  {1 W6 Y1 q) J
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
6 @6 M' h  g( S; Y7 e, V+ ~      "<td>" + bom.getProperty("quantity") + "</td>" + _ 5 _4 Y7 T, G; C, ^# P- x
    "</tr>"
6 n' Q9 a5 r' P: GNext 4 h# r# m- D: N6 P
content += "</table>" 4 Y; W2 C- h% s: A) L7 l* W

! E. W0 F1 l  H4 HReturn innovator.newResult(content)
) @% l0 f) ?! y) A) }  }2 U' l. x) W0 v) F5 ~- |7 M! U) |% G  I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了