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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  7 r# s1 A) N) D# ~/ R
To query for an Item and retrieve its structure you build the query as the structure
2 |  h0 Y  D* A( s- uyou want returned.  Use the IOM methods to add the relationships you want and $ x$ A/ o, q/ E0 M' s
build the structure in the Item.  The server will return the structure that follows the & a! t# l/ l- H+ b' }% V
request structure. 7 @# X, I6 \9 |5 w( t, y8 P) l% T
This recipe illustrates several related concepts together, which are how to get a set + C9 H2 K' T  z* _
of Items from an Item and how to iterate over the set, plus how to get the related
& ~' f. ?; X% g3 K1 @0 y% OItem from the relationship Item.
! U5 a  ?+ K' M0 I$ Z  vJavaScript  
5 a+ ^* ]* J  b0 H: K2 cvar innovator = this.newInnovator(); ! f/ i6 E: S' k" m

4 ~: w2 Y' y7 G+ d4 @* V% b" W// Set up the query Item.
, n# H9 ?/ A, Q% Y% Y; ?/ Z; \var qryItem = this.newItem("Part","get");
) f; j* M' ?* w+ F" h. _9 z( VqryItem.setAttribute("select","item_number,description,cost");
5 F0 b" A5 i- t/ uqryItem.setID(myId);
: f& o* ~) U9 i! E : T* E5 |% z/ q
// Add the BOM structure. , |& H* w5 |  ?" Q8 V
var bomItem = this.newItem("Part BOM","get");
6 \% }9 z/ x/ Q/ z5 B  B0 y6 mbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
' y8 B8 L% M+ h* k* |qryItem.addRelationship(bomItem); 5 l+ _0 [0 Q6 i. |/ b: r9 D) n
/ F4 n3 z' B. ?7 K
// Perform the query. 1 t* N4 K7 ^# e5 b
var results = qryItem.apply();
& Q$ @. }1 u4 d$ J
, z- b7 J- H) T  f// Test for an error.
6 a; y- P- c* D" S+ z3 \if (results.isError()) {
3 g7 `0 {, |# m* X  top.aras.AlertError("Item not found: " + results.getErrorDetail());
; s' ?) F% J; b9 d' |3 o# a  return;
/ o0 \% f  v: g2 ~/ t) i$ P# K}
& _! U, _( O6 s6 q* a4 K
# @) Z2 L$ F* N# b( V2 D3 Q6 V$ E/ N// Get a handle to the BOM Items. ' r: ^" |# [" v& q
var bomItems = results.getRelationships();
& L. V7 p, e* V) ~' f, b0 D+ y# [var count = bomItems.getItemCount();
9 q" S5 M1 P  T0 q% L  Z ; L  v/ S9 k, e$ C# [
// Create the results content. 6 R, A2 y* \8 @$ Y- e/ I" H2 B
var content = "<table border='1'>" +
" x1 U- S3 C3 _% c# y2 w/ R( n; ]  "<tr>" + : m5 H9 n5 z' Z0 F5 d7 ^6 L
    "<td>Part Number</td>" + + {) O. w/ }2 g4 s* i
    "<td>Description</td>" + % u# |8 C% c# _0 C( _# I- d: I
    "<td>Cost</td>" +
5 X1 W) b0 |- y9 l, B    "<td>Quantity</td>" +
! C) E9 Z4 r3 I' L' ^/ r  "</tr>"; % {/ [; b4 C3 h9 K, A

, e7 W( N( ^' y' l; j9 `+ Z" r. h) x// Iterate over the BOM Items.
: e9 r. j- P& x; T& hfor (var i=0; i<count; ++i)   l$ ~9 ?+ D9 P/ Q7 e2 C/ Q! N7 e
{
; S6 u! Q5 n: k9 R) a// Get a handle to the relationship Item by index. / U  }4 Z2 G7 b7 k$ Q, O' u+ e
  var bom = bomItems.getItemByIndex(i); & e5 w5 G/ M5 e" \$ W1 l1 f
// Get a handle to the related Item for this relationship Item.
6 @) J  w7 n& i) A/ ~  var bomPart = bom.getRelatedItem(); , v- G# S, C3 G1 ~! M% G
3 ^+ ?! {- O6 }3 W
  content += "<tr>" +
) U! W! U. l: [- E3 n      "<td>" + bomPart.getProperty("item_number") + "</td>" + ! v" }5 E) }7 V6 P& Q# d
      "<td>" + bomPart.getProperty("description") + "</td>" +
8 M( z, h# s- j$ K( I4 \      "<td>" + bomPart.getProperty("cost") + "</td>" + ( Q% n- F" n! g! J7 O0 F; K
      "<td>" + bom.getProperty("quantity") + "</td>" +
, K) F/ X* L; q) t7 E$ T; ^' I    "</tr>"; 8 A1 i5 x; d4 K' T  Z
}
/ o% J& ^  [' F" yreturn content + "</table>";
3 S( W. X; }9 ]' k) c5 F. U- Y+ ^  \' T' B9 T4 j6 \( m$ S
' j6 x9 E* Y" r4 u* t

9 W: {4 P& o: P6 J2 k( ]* k& e/ Q

  h! Z% Y6 l6 l, }' M2 ]C#  
; ?, I8 z+ @8 m/ J2 qInnovator innovator = this.newInnovator();
' ^6 ?% j6 b% K) W7 o# Q + k" B; z9 `; h$ ^
// Set up the query Item.
- W; i5 u: h/ x; ^  X# P* A) y5 Z" Y  BItem qryItem = this.newItem("Part","get");
- B2 M' O# k) x# m7 A, S# h) R' n: LqryItem.setAttribute("select","item_number,description,cost");
. c/ w( R* e+ ]. ~) [* ?qryItem.setID(myId); # _  g7 t2 K8 |& `3 D
. R$ k4 {3 g9 }3 H+ ]2 [# F& }
// Add the BOM structure.
9 Y0 L. g. D( Z( }Item bomItem = this.newItem("Part BOM","get");
9 N4 i* B' J' H5 _  X. |bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 8 R. T8 W5 |! }! x; a( z5 q2 E' {+ \$ r
qryItem.addRelationship(bomItem);
% |8 s- k" o& Y+ l' i+ m% X- P $ Y! S: t9 }( a2 [4 _" p. J
// Perform the query.
; O7 B" K- z9 ^% zItem results = qryItem.apply();
% X  p* R$ T- q# R4 D6 j! e# G( p. | $ q, J# s! p: W  d9 q
// Test for an error.
  H& K: j3 Q( W4 Q# y' d! Rif (results.isError()) {
8 \( d+ d2 E  T! S# ?" s  return innovator.newError("Item not found: " + results.getErrorDetail());
, Q, n  N6 {% I} ) R( z6 D* x, W" Z

. E( k. p0 B1 I5 R// Get a handle to the BOM Items. 4 I3 a- M* q) a! y6 E! o5 L
Item bomItems = results.getRelationships(); ! n. Z# Z7 m$ `/ s8 n) \
int count = bomItems.getItemCount(); 9 [8 U3 w( I5 y! r7 {
int i; 4 }; `* E3 y7 n6 N5 j9 P$ f, t9 T
/ i% X2 C% _) }9 X: b( z. k) Z7 f
// Create the results content. # Z2 ]* _6 i4 f- ]
string content = "<table border='1'>" + 9 `8 G2 u! ^. m' Q1 E
  "<tr>" +
4 \* g/ B) A3 I1 k/ c: Z7 e# n' B    "<td>Part Number</td>" + 4 [7 M5 D( H# t5 [+ {
    "<td>Description</td>" + 3 B0 d, I- ]# w# m5 t8 ~& y1 K# c
    "<td>Cost</td>" +
% g( n1 L8 \: H- i    "<td>Quantity</td>" + - b3 I; O; P  F3 z! A( b7 R. l$ h
  "</tr>"; 3 w+ X% y5 T# x$ g0 y5 _  i% I

5 O7 ?5 `8 m$ x5 q" a! _& A: F// Iterate over the BOM Items.
1 c: w1 m8 o" ufor (i=0; i<count; ++i) 5 x+ Z0 L% q5 e) K, g" P
{
) s+ v4 J. Q3 s1 R// Get a handle to the relationship Item by index. " ]2 r' a; b% ]* Y1 E/ B- [
  Item bom = bomItems.getItemByIndex(i);
1 [( [0 X, V4 j5 O* B" h// Get a handle to the related Item for this relationship Item.
9 @* f4 N1 V- O- d4 Z) g) Z  Item bomPart = bom.getRelatedItem();
0 ?- N% x1 P- o. Y3 z1 j 4 F; T3 G, e# H/ p0 D0 a; w& m) P1 O
  content += "" +
: ?# P9 F& a% L0 \* f    "<tr>" + 8 w* E; S2 [6 m1 v
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 6 h1 W/ `; |8 Q" f0 S
      "<td>" + bomPart.getProperty("description") + "</td>" + : a" U, ]# e3 w' L* h7 e4 K& R5 z8 j0 a5 Z
      "<td>" + bomPart.getProperty("cost") + "</td>" + $ f- s3 ?" V9 E
      "<td>" + bom.getProperty("quantity") + "</td>" + - K( p: `2 ~$ {! T( i
    "</tr>";
9 Q( w5 B, f4 }% \6 Z9 B} 5 N' o( e: k# v7 c
content += "</table>"; & S+ @/ @$ ^2 s' U! b0 n

4 j) w. O7 U( B4 w: Freturn innovator.newResult(content);
& |' i! ]4 N8 u5 S' {+ j, w. T
4 s5 t) l! Z/ h$ m3 ~. ?0 j

4 h+ w( N/ S+ i. S0 L. G# d' [, B' ]. p

+ R( x1 B  k$ s$ M9 X! U- q1 b2 k: I+ |- L6 o

7 c  N" k, ?1 f" w ; v  h, R& O+ s, i0 {
    Page 46   O, T. _1 \- T( J) s& z
& E: Y  v- k, j( G0 ]0 g" E3 F
Copyright   2007
3 M  Z# u* K0 w, [" K" G; BAras Corporation.  
% x) j! i1 f) C. D4 `9 }All Rights Reserved. 2 P4 ^6 f$ C0 {# }/ k. x8 f
VB.Net  8 L) `0 x! |; y! @, k+ a) v
Dim innovator As Innovator = Me.newInnovator() 7 a. @. R9 z" B) B+ u/ J2 G3 j

1 B4 \6 a. U+ H. f/ O' Set up the query Item.
: J0 g1 u# _6 e. d$ `Dim qryItem As Item = Me.newItem("Part","get") . P6 J5 f5 `8 J" R; Z
qryItem.setAttribute("select","item_number,description,cost")
0 T( o# b) a. ^) p: f. mqryItem.setID(myId)
' Q5 E8 i7 U9 J
/ v: L0 t- t6 w$ t! h8 y; P' Add the BOM structure.
. h4 A& N9 @4 s0 ^, hDim bomItem As Item = Me.newItem("Part BOM","get") # _' i5 N, ?  b# ]+ n
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 4 E/ U* r5 R5 \: ]1 D9 S  Z) J
qryItem.addRelationship(bomItem)
* [# ^; t% V' F3 f7 h' a5 c + r; e+ X8 |4 H' e+ W: r: _
' Perform the query. 9 b" G5 n, j) ]( p" r
Dim results As Item = qryItem.apply() 0 F% C2 |% ^4 _7 r8 w- _0 ]

" `$ B- a& n  \2 l  h- s' Test for an error. 5 i. f- f0 v& b: ^" j4 H% O
If results.isError() Then # X. L# n$ a2 {3 p: u
  Return innovator.newError(results.getErrorDetail()) : r( P( W. W7 T* F0 L1 J: N, _
End If , t& [" b% Q' \, a4 ~& y

8 s0 b& G3 W2 Y+ y8 Z* q3 X% p' Get a handle to the BOM Items. - ~! @+ a' R- n
Dim bomItems As Item = results.getRelationships() * x; b* ?/ R+ w, \$ R' e
Dim count As Integer = bomItems.getItemCount() 3 I5 ?' s: V( P% h
Dim i As Integer
: J! r+ g' A5 n
1 I$ m8 z6 b: U& Y3 j6 {' Create the results content.
" }) \; E+ T7 {5 s/ T# V1 JDim content As String = "<table border='1'>" + _ ! d$ z2 B- l7 O$ _, G7 d
  "<tr>" + _
& r- p& P2 [$ V, N& h' l5 w/ ^    "<td>Part Number</td>" + _   ~0 R8 Y/ c" g7 `. C
    "<td>Description</td>" + _
$ ?( k5 Q! R3 N& b+ b# G) |5 l9 w    "<td>Cost</td>" + _ 1 I& U; }& j6 z4 x5 D+ b. h/ _/ L
    "<td>Quantity</td>" + _ * H* _2 g& O" a5 B4 ^
  "</tr>"
7 m1 o: j# p/ y, m: O! W2 ~ , v* n% w. ]: @3 K" u* Y
' Iterate over the BOM Items
0 S& F9 r: {. T$ s5 x$ W, |+ _For i = 0 To count - 1
, J! |5 N! ?' H$ b( l' Get a handle to the relationship Item by index.
. a9 i5 a4 ~4 u' S$ b+ p8 j/ O  Dim bom As Item = bomItems.getItemByIndex(i)
* L2 n4 l: n9 Y6 Z0 U2 P7 U1 a6 @ - M( U7 w$ k/ G' q+ \0 P5 ~) D
' Get a handle to the related Item for this relationship Item.
/ M* n+ p. _$ K8 E8 H  X3 V  Dim bomPart As Item = bom.getRelatedItem()
# [& n5 \$ P$ `2 \' t1 l/ ^- x
4 v0 d0 S- B- m# ?4 z7 g  content += _
# S) H: n9 Z  [    "<tr>" + _
. J5 v! q) e& C+ q' y  X      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
) a# S- g) Y9 c      "<td>" + bomPart.getProperty("description") + "</td>" + _
3 Y3 k; `. T0 V( }  i2 S      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 3 W! a# P6 w$ l  g" y% P1 a& O
      "<td>" + bom.getProperty("quantity") + "</td>" + _ % C" x3 A9 w" ]0 |6 y$ C2 A/ n# u
    "</tr>"
1 K( _2 X2 j" V9 TNext + [$ x- y9 |4 b  S& \3 ?
content += "</table>"
& b  n& B: Z) l# ~6 A  l! b
& c6 ?/ Y+ W4 y+ RReturn innovator.newResult(content)
: @1 F5 u# d; n! v4 h* \& D1 q5 u8 j/ b' S# x
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了