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

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

[复制链接]

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

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

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

x
Technique  $ G; ]4 }# o2 a1 ]$ t; p  M
To query for an Item and retrieve its structure you build the query as the structure 8 O" U8 q1 N) r
you want returned.  Use the IOM methods to add the relationships you want and
7 K% P" A- F- r5 ?0 i* l$ j& lbuild the structure in the Item.  The server will return the structure that follows the . p; D& A6 B3 v8 s
request structure. + D! J, W4 H" F" t
This recipe illustrates several related concepts together, which are how to get a set 5 L+ u0 B: n' f( F0 r7 I
of Items from an Item and how to iterate over the set, plus how to get the related " \2 ]; I. ~! I# D5 K$ s9 ?4 P
Item from the relationship Item. + J: f4 D& F2 y* H' c
JavaScript  
1 S( S( q+ G4 j" U) o6 ?var innovator = this.newInnovator(); 7 f1 e) o3 O  {- ?+ [
7 f. ~1 Z/ l8 O8 Q/ \. j+ ^* i9 V
// Set up the query Item. , o: A; N5 ^/ b5 f' b
var qryItem = this.newItem("Part","get"); ( ~7 h( f8 e8 l! `* u& w1 R9 D
qryItem.setAttribute("select","item_number,description,cost");
: T, \5 |$ ^& H( [  v' s: ]  xqryItem.setID(myId);
# g9 X  }& z  S 4 o+ k! v, a- W- s
// Add the BOM structure.
2 ~* y$ @/ ~' Q. f0 ?( F; c+ h- pvar bomItem = this.newItem("Part BOM","get"); 5 \! l0 O3 r9 y4 S7 L
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
: p( L! `4 [7 N! ~) `6 X; f8 PqryItem.addRelationship(bomItem); & Z! p% J: i, m3 B( F

/ _' B+ j) g5 d. {* I, g0 K// Perform the query.
+ z. M6 y5 b9 q& e; o/ Lvar results = qryItem.apply();
3 }! q8 k5 @8 }5 B* y % N5 {- N; d8 ], d, d' o5 C+ g
// Test for an error.
" k( h# Q9 q9 T, q5 Y0 ^/ Wif (results.isError()) {
: }4 |' E* `. _- i; y1 w* F8 ]4 u  top.aras.AlertError("Item not found: " + results.getErrorDetail()); ' w+ i) {4 |' {' c! c8 t
  return;
8 o9 _) l$ A5 B/ V  s} 7 n3 Q" Y4 R: B- l% U$ t9 m
8 Y! @) B1 N5 G* F6 D- N
// Get a handle to the BOM Items. 8 d$ ]; {8 S' T- L1 Z  i
var bomItems = results.getRelationships(); * X# L' ^$ w. x5 z7 t) y7 |& M
var count = bomItems.getItemCount(); * v* y3 z. }1 a

7 o0 y; b8 \  X/ J5 D9 j// Create the results content.
2 S/ G9 S/ D0 _2 Y: Ovar content = "<table border='1'>" + / ~* o, T$ Z$ N/ j6 I
  "<tr>" + + N4 A6 f& i  O: T; {/ V
    "<td>Part Number</td>" + 3 D- ~: ?1 A8 ~# p4 H/ B1 u
    "<td>Description</td>" + ( _* E- I$ t/ I8 r+ ]
    "<td>Cost</td>" + 2 X; D) x2 z6 G+ p. e" l2 _
    "<td>Quantity</td>" +
: ~: q* \0 F8 f5 t  "</tr>"; : Z- n; K6 h  i
8 X5 `5 i0 U+ w; g- J5 _
// Iterate over the BOM Items. / W3 w( d: d2 k
for (var i=0; i<count; ++i) 8 Q. l, z( R- o+ z+ V1 T5 f  g( o
{ ! I" |3 z( M( V; F
// Get a handle to the relationship Item by index.
! E. C; ^! z' u, L3 L2 g+ {0 c3 j. p  var bom = bomItems.getItemByIndex(i);
4 N# ]. T8 R5 M8 D; i9 ?// Get a handle to the related Item for this relationship Item.
  ?4 q: c$ }2 d; U" w4 Q  var bomPart = bom.getRelatedItem(); $ C# \. ?) i" ]3 Y- r$ f

0 S; T/ |  y% v% V  content += "<tr>" +
8 `' {4 O! W2 N/ D  Z9 |- B& q      "<td>" + bomPart.getProperty("item_number") + "</td>" +
* v1 U& l/ H% k# t2 h8 l! @* V      "<td>" + bomPart.getProperty("description") + "</td>" +
1 C2 E) u" ]1 y5 Y1 t9 [, I      "<td>" + bomPart.getProperty("cost") + "</td>" +
, S8 t; [5 T" J      "<td>" + bom.getProperty("quantity") + "</td>" + ( t$ u/ J* `1 O. `  T7 Z8 T! X
    "</tr>";
6 D7 V0 `6 ^, d$ D} 7 D( n+ B! [% }6 h  I# W! p# V
return content + "</table>";
* o0 a  b7 ]3 f+ Y5 B7 s8 e2 D( Y) H& M( A% o

& w, v1 i/ @9 y! b& o$ b( G$ J1 X, X2 L' h: y/ \) i5 t

; A9 A& @# i! `) c$ ~, fC#  $ W& H5 O5 o+ T8 r8 `3 |
Innovator innovator = this.newInnovator();
5 T8 u7 ^, G4 o  j; e: t! O $ h# o$ G- ?( Q
// Set up the query Item.
5 }) E1 R4 L* A. d: |' q3 kItem qryItem = this.newItem("Part","get"); $ w" z& b7 b9 x0 s+ k+ ?% H1 I
qryItem.setAttribute("select","item_number,description,cost"); , `' W* X$ B7 w2 i/ N
qryItem.setID(myId); 6 J% H8 u" n: R
7 a$ b8 Y  i+ `3 d3 k6 h' P" l
// Add the BOM structure.
/ p) @8 _* d) o2 u% zItem bomItem = this.newItem("Part BOM","get");
  y5 h  ?4 X$ i$ U3 K' s/ CbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
; z! q# P! c$ K5 F4 tqryItem.addRelationship(bomItem); 9 O+ @" M$ _7 g, }( a

6 g6 c  b" ?# g$ G: ~8 s: \// Perform the query. ; c& Z5 ]  U/ }! d: H  ~# T. _
Item results = qryItem.apply();
% w$ F' D/ B$ ~+ ?) K9 [$ [ " ~- V7 {7 P0 V+ u- u4 w% N: F
// Test for an error.
% X4 g- Q# [% Y7 c+ ]0 Qif (results.isError()) {
1 o% X0 a9 v% A) k  t6 q8 K  return innovator.newError("Item not found: " + results.getErrorDetail());
% f6 z! n6 F, N! Y8 t/ q}
& t, K, |9 z/ O( V" y% B  T / [3 D) z0 P4 q+ z( [- }3 ~% ^
// Get a handle to the BOM Items. ( `  L! z8 O& ~" n2 t7 m3 D
Item bomItems = results.getRelationships();
- M/ d* X- c  Y  H' v8 fint count = bomItems.getItemCount(); & w- Q2 n: k0 }
int i; % r2 [: I8 Z8 |) T  f
. Q1 n/ P5 T% J/ I
// Create the results content. % H) @$ u! R$ U, H
string content = "<table border='1'>" + $ v' t; m' S6 m% t+ R
  "<tr>" + " J: A$ i1 J. E  f7 y, [+ B
    "<td>Part Number</td>" +
( n* _* G3 C+ Q( W    "<td>Description</td>" + 7 N7 w2 C( M! @& G* H& p# v  Q
    "<td>Cost</td>" + - A5 T+ |/ ~/ l0 k3 c) R! e
    "<td>Quantity</td>" + 5 s  h, L& G# B  J# Z
  "</tr>"; ) }( L- Q5 @4 l3 y1 u! i. C

- P4 `' s9 E2 T8 P4 G// Iterate over the BOM Items.
- ~8 H1 D0 P- J7 R- |7 J$ Ofor (i=0; i<count; ++i) 0 f# P& I0 m' p3 y/ M
{
7 ]2 z. ~" ~+ v, A% Y// Get a handle to the relationship Item by index. ( ]/ A: S( f( u
  Item bom = bomItems.getItemByIndex(i);
/ P0 C8 R+ V; [( Z4 q, D; |. c// Get a handle to the related Item for this relationship Item. 8 ?4 F' e- |* ~' V6 P
  Item bomPart = bom.getRelatedItem(); 6 @3 w- h& p* F7 J7 m
) U! Y1 v5 y! @; m3 T# b* B4 y1 Y
  content += "" + ! V; ~3 O" i$ w( [
    "<tr>" + . K1 Z! x6 ]5 k, Z% w( F
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
* l7 p% F0 a* b5 M: N1 a& G      "<td>" + bomPart.getProperty("description") + "</td>" +
1 g8 f/ C7 G& s  C9 g6 H/ d* j      "<td>" + bomPart.getProperty("cost") + "</td>" + 1 v2 Q& _2 O+ E' q; R
      "<td>" + bom.getProperty("quantity") + "</td>" +
8 z+ G, }( i0 J$ o    "</tr>"; 6 s2 ]0 c+ A; f: w; P0 b( A& V
} / H" B% f6 O. A+ M# q9 I6 h& s0 x8 _( b; |( N
content += "</table>";
# @( L; l! s1 Z5 j6 b+ x, D   q* S: E3 y' y0 @" p* I0 z
return innovator.newResult(content); $ O$ v) a) |; r7 ]$ y8 _0 Y
; G5 i# b* ~4 t) P& {  i! h
  m& t  [* G0 j
& u8 i7 ]' q1 m

* s, v5 [  v$ k5 f! {* Y
: m, c% G- C0 }

) j# D* y6 L% E, M2 l' J1 p" j( ~/ _ 6 B: b4 h: [9 @
    Page 46
) A( v* v2 P4 c3 n" Z
/ J3 ]1 `) A% V2 }4 eCopyright   2007
# M* J$ x6 k, y1 R$ d; x" G! UAras Corporation.  
. e; @1 }# B5 x4 W- D: Z& rAll Rights Reserved.
( y( x* {+ u2 Y- LVB.Net  ) k: E! A* P* q
Dim innovator As Innovator = Me.newInnovator()
  ~4 G( t: e+ [  _) r! v1 Y/ V
1 X1 F1 |) n% h$ l3 L+ G- x0 {' Set up the query Item. 8 z8 K: a3 q) _( X2 N7 M1 K; J
Dim qryItem As Item = Me.newItem("Part","get")
0 }! i; b. o3 o, ^qryItem.setAttribute("select","item_number,description,cost")
8 q' B: v4 J; V1 `qryItem.setID(myId)
/ C, u8 o+ s" u, l" b2 ]) {+ o ( ?% @% M8 s4 R% A2 Z0 D3 ]8 W0 @
' Add the BOM structure. & C" B; E1 L, Q" F( U  k
Dim bomItem As Item = Me.newItem("Part BOM","get")
- u, _  q1 o6 u$ A& R8 xbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! ^  s2 B: d# f3 k, y/ I$ wqryItem.addRelationship(bomItem)
+ B7 j8 h* V% |2 |
, j; M6 e# z9 e# d( [" v9 {9 I" E& E' Perform the query. * C8 r4 A; Y& ]0 P: ^* l
Dim results As Item = qryItem.apply()
( R1 q+ C: T5 A, B% Q( f% } * Q5 W) H; H. m5 M) ^
' Test for an error. : o) Y% B% h; b5 X/ \
If results.isError() Then
  `* @! C$ F0 u: `8 X$ H  Return innovator.newError(results.getErrorDetail()) " U1 N( N  G! _9 u) J3 h
End If
/ a& o) P3 ~& `4 T5 S: Y9 ]5 r
* i# E9 G4 e% c+ ]6 j6 |' Get a handle to the BOM Items.
- D  A& N  R3 ^- i, S+ `3 JDim bomItems As Item = results.getRelationships()
) Z+ K% o3 Q6 m3 C8 _Dim count As Integer = bomItems.getItemCount()
) ?- b" f# K* u/ }% IDim i As Integer , }) w7 i- C' F, h1 M! ^

9 M3 z+ e& Q: e1 ~; L4 b' Create the results content.
4 x! h! g0 L9 X; JDim content As String = "<table border='1'>" + _
) s0 Q/ W1 h+ {- }  "<tr>" + _
& t# s7 U7 `8 c( Y. n    "<td>Part Number</td>" + _
( f7 q7 W% e( y! s0 p' Z    "<td>Description</td>" + _
# k' a4 f" P6 ]# f3 ]7 E! K    "<td>Cost</td>" + _
4 i! n% ?6 h& w; {" R- C/ b    "<td>Quantity</td>" + _
9 L: n; x3 g, [5 q7 ?1 P- }% K  "</tr>" 6 T& D1 f  r5 I- E0 B6 n( h8 f! E% p

& T% R  R3 u9 [# V' Iterate over the BOM Items & O8 ~- f8 k# B9 P2 @: @
For i = 0 To count - 1 . g- v  X4 @2 Q/ T7 F& K
' Get a handle to the relationship Item by index. : m6 ^( A' _% M: v1 X2 V% }5 |+ d
  Dim bom As Item = bomItems.getItemByIndex(i) " ~% G* J3 T; M  e5 V9 }( K& U
: Q: c- {, \5 u5 Q/ U" X
' Get a handle to the related Item for this relationship Item. " J- `& Z/ `: X- U
  Dim bomPart As Item = bom.getRelatedItem() + P, t/ ?& R4 b: z& l2 D0 [9 F& Q
. D5 |" G1 u7 @2 P4 W
  content += _
% d4 l+ r* C- p: `    "<tr>" + _
* p1 e" A0 Q. K2 I$ h- C) R      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
' ~- s0 S3 v7 n      "<td>" + bomPart.getProperty("description") + "</td>" + _
* \: u2 n6 M/ r! b' O; A2 w% X      "<td>" + bomPart.getProperty("cost") + "</td>" + _
- A( D, t4 l  M7 t* E1 Y      "<td>" + bom.getProperty("quantity") + "</td>" + _ ) }6 s% B& B+ s$ x! i7 z
    "</tr>"
& j* R# L/ R5 d, k' a! BNext ) j2 m* m( m6 y% z
content += "</table>" & Y9 S) [; ]8 u3 x

1 t1 r+ E  u- A2 k$ e+ ~Return innovator.newResult(content)
( x$ H6 [+ _+ B4 G5 G0 Y
) f; S1 ^9 v' e0 m. {( Q$ E
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了