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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
  G* i8 }* e, o( CTo query for an Item and retrieve its structure you build the query as the structure
0 l/ x9 F& ~! |4 G& y$ [you want returned.  Use the IOM methods to add the relationships you want and 4 ~. e4 a) k2 S$ `7 H( N2 Y
build the structure in the Item.  The server will return the structure that follows the 6 i) [5 e& Y6 Q# a. s. R, j$ o& ^
request structure.
9 E7 ?: n6 f6 nThis recipe illustrates several related concepts together, which are how to get a set
  y( V& D7 |- y+ @: Cof Items from an Item and how to iterate over the set, plus how to get the related & a0 k, P& b3 e' ^+ e3 X
Item from the relationship Item.
+ `7 y/ r2 V( SJavaScript  
* W1 }. Y( v; H" ^var innovator = this.newInnovator(); 0 R+ c; v; j, |/ s0 S- m4 n

; ^0 `7 N. P- N$ g: X% G// Set up the query Item.
$ [4 [  Q2 Y) |& G; i( k' fvar qryItem = this.newItem("Part","get");
: L- l' q4 Y/ A( @qryItem.setAttribute("select","item_number,description,cost");
2 F$ ?! p) j4 k* J, g4 X4 J7 mqryItem.setID(myId);
' @" f! W. M- a3 D, L+ a* c" v " P+ q+ O$ [& y2 n
// Add the BOM structure. 9 s+ b; n, h, b
var bomItem = this.newItem("Part BOM","get");
7 c& z( l' Y: M' |' ?7 d5 r0 XbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
7 L: g0 }( y/ M) S( gqryItem.addRelationship(bomItem);
/ V2 M9 ]( Y5 L! X" U) T ! V6 R7 p4 w$ c9 s# e% }
// Perform the query.
1 V* P: a* l! b6 o+ fvar results = qryItem.apply(); ' r- n; ~- V0 [
6 |/ J" N4 S( k  @0 J
// Test for an error.
) t; P, S  v7 z  o, M/ S. nif (results.isError()) { - x: B6 \8 e, f% y$ m0 g
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
2 K2 R* [$ `" }4 T. ]& ?0 x  return; # y3 u8 p/ I5 n$ K
} " L! z$ h+ |. w" w1 j

& J" Y$ d' E3 s* m// Get a handle to the BOM Items.
" e4 Y2 B, x8 D: |& W1 c' lvar bomItems = results.getRelationships(); 6 v, J7 l* r  E( J% k1 P6 W0 U2 u
var count = bomItems.getItemCount();
# O& D+ d  f+ \8 w 4 Q# J0 B1 l- w1 w
// Create the results content. 2 V; Y7 ?& T/ a- h0 `) h" r. r
var content = "<table border='1'>" + ( @% y: ?- D, y/ e
  "<tr>" + ! R3 E, M/ G. X' [
    "<td>Part Number</td>" + 1 j2 L) \' Q7 M
    "<td>Description</td>" +
3 t) F2 o0 @2 k" M5 x    "<td>Cost</td>" +
- x1 H% }: A# |" _2 f. _7 U3 E. f    "<td>Quantity</td>" +
4 R4 Y- D7 k! N/ |+ K5 L" I; R  "</tr>"; 5 l; M4 r5 W0 a1 b, b' a

  H/ ^& H" c/ T  k// Iterate over the BOM Items. / ]  R) t' c8 i4 E- ^  p
for (var i=0; i<count; ++i)
% t# [1 p- m7 X2 ~2 [{ ) q4 ~3 q4 \+ _8 N6 w2 ]
// Get a handle to the relationship Item by index.
# l+ ^; C# S1 ], p  var bom = bomItems.getItemByIndex(i); 0 p* C* W: P$ B5 u2 N( Z6 v
// Get a handle to the related Item for this relationship Item.
7 X6 j. n7 [1 E$ s, R  n4 y  var bomPart = bom.getRelatedItem(); " u7 `& ~6 h4 @7 e

- s7 m, X  P2 _  content += "<tr>" + ( L1 h# r7 B+ |; V
      "<td>" + bomPart.getProperty("item_number") + "</td>" + , [; L$ M% |/ w
      "<td>" + bomPart.getProperty("description") + "</td>" + ( j/ g; ~8 |6 ]
      "<td>" + bomPart.getProperty("cost") + "</td>" + ; j2 T0 O" x  u& {
      "<td>" + bom.getProperty("quantity") + "</td>" +
7 e4 a* k: j- Q8 v    "</tr>"; " m% B( l9 z/ |% t$ w2 x& q* M1 b' k  A
}
! Z2 k" P4 D0 e& \return content + "</table>";3 ]' `0 h8 T9 b0 h8 f
" M+ J- z( r7 R* t. ]
% c! f- ]4 g/ ?. }: D
$ L" k/ x. T$ }; ^! [+ H- h
7 z9 V; T/ l, Y5 `$ U! d; b
C#  + t, b. d$ w( q: _& G1 R5 J
Innovator innovator = this.newInnovator();
* [: i7 ?1 n2 D" F& p
9 m' z; A/ k1 G6 {// Set up the query Item.
0 F, y" O, f6 w! T& oItem qryItem = this.newItem("Part","get"); - X7 r5 ]" D9 H0 ?
qryItem.setAttribute("select","item_number,description,cost");
6 u2 O: d. s9 `) gqryItem.setID(myId); ) U! M" L" q- f1 _% k. d, U
  J! ]' x' h% X" i* p0 k3 L: ~
// Add the BOM structure.
. [- Q  \! k8 P! `Item bomItem = this.newItem("Part BOM","get");
" o! U% n3 B- P( BbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); , q9 H/ `/ n) K  R
qryItem.addRelationship(bomItem); ( \  ^( V0 t0 a2 u+ ]; J; w

% [. o% d/ T6 o6 o7 u6 E* W' m/ }% p// Perform the query. * b( w  c( R8 Q' h
Item results = qryItem.apply(); ! _+ ]9 ]% M) c
9 r3 y/ G( f& z3 ], b% o
// Test for an error.
  O, _: W, C4 n! H2 h0 Q; G$ q5 mif (results.isError()) {
- y$ M8 ~% x' T  return innovator.newError("Item not found: " + results.getErrorDetail());
7 Y) `5 R9 e, R6 Y( ~% a: ?} 8 `. K0 V2 r0 Z/ s
; ~% T; R0 |7 W
// Get a handle to the BOM Items.
+ c1 D. d/ E* J$ s0 ^, }4 e6 KItem bomItems = results.getRelationships();
0 |# K( K; J7 h6 ^6 s" z$ iint count = bomItems.getItemCount();
' R( u) I5 t! c7 w! dint i; 7 Q: ]6 I' s* O0 `

: E  C. f1 D4 a* u* [// Create the results content.
" A' v; u. H1 S2 q6 Sstring content = "<table border='1'>" +
: w7 z# N4 g  R% E* i  "<tr>" +
, s( h8 E3 i+ ?& `0 h    "<td>Part Number</td>" + + j3 D+ W3 ]- |8 ?4 Q
    "<td>Description</td>" + , W+ }4 b* e  q0 C* i' p6 U6 d
    "<td>Cost</td>" + 6 Y: o( P  B( u
    "<td>Quantity</td>" + ) e; S. f5 l% g  O! m3 {/ }/ L
  "</tr>";
! E0 A4 y, ^3 `  g" @
0 o- d: \/ l& ]0 c& k0 f) U( F// Iterate over the BOM Items. 5 g" e, p4 E( o
for (i=0; i<count; ++i) 7 ]. y3 F' Q  S2 }4 M! T1 ?
{ 9 k: }4 L& G. S8 ^! }
// Get a handle to the relationship Item by index.
5 v1 J) }/ L9 Y! A4 f  Item bom = bomItems.getItemByIndex(i); ) v1 i4 W; I+ v6 `4 g* k  M9 A
// Get a handle to the related Item for this relationship Item. - y/ k& I; T  I: ?3 d
  Item bomPart = bom.getRelatedItem(); 0 R+ {% A! B: I# b( W1 S- L
- P6 O, A0 c- U7 Y3 N! J+ s
  content += "" + 1 n( O. a+ p5 l" F" G$ l
    "<tr>" +
5 k+ b' c+ O) e8 R$ p      "<td>" + bomPart.getProperty("item_number") + "</td>" +
2 k& u7 l( }" e$ ]' G      "<td>" + bomPart.getProperty("description") + "</td>" + + s. ~$ x; j2 H" b+ x* o5 ?5 |
      "<td>" + bomPart.getProperty("cost") + "</td>" + ) B$ ^9 K, p. @/ o: o
      "<td>" + bom.getProperty("quantity") + "</td>" + 9 K$ ^7 w2 n2 P' n7 J
    "</tr>"; . k% S: e6 F/ f& p: T, G
}
" w: q) z  |2 D# L9 }9 \; f/ D; Scontent += "</table>";
* w5 q% w5 y- g8 a. I ' Z& y' y; e0 v* t
return innovator.newResult(content); 4 B3 s' M/ W4 A: Q9 G1 |
' I: H/ r1 Z- c3 s
; T. k' v9 A1 E; @7 `
& U' {% Q# \8 T+ [( f; s2 @& w

4 [0 r0 O( N% I2 a7 F
4 J1 K5 n. B' q  ]8 z4 O5 ?# A
$ a! d4 A- s, @+ G
0 J4 E# F0 r/ L* b5 `9 {: G
    Page 46
* X. o* L7 L6 } " _: C; e8 C+ X
Copyright   2007
: G, j2 T' W! a; y8 o  BAras Corporation.  
) S; j+ c1 n' O5 E3 oAll Rights Reserved.   K0 @2 Q7 h1 d+ I% Q3 }
VB.Net  # o! h7 o, T7 \+ A: ^; }' i! ^1 e
Dim innovator As Innovator = Me.newInnovator() 0 Y/ B9 N, E# o% B/ N. h! L

" h5 l* {  s& N/ U' Set up the query Item.
% g+ ?- i# C' O; a: |Dim qryItem As Item = Me.newItem("Part","get")   {! o, h. }- V; Z( \# w6 p
qryItem.setAttribute("select","item_number,description,cost")
$ b! C8 u+ E, MqryItem.setID(myId)
9 r) @: R0 T; k6 i. L* l; K : [4 M+ j7 f! P" _' b
' Add the BOM structure. $ N8 [5 h$ N4 P: Y0 W+ t/ a. g
Dim bomItem As Item = Me.newItem("Part BOM","get")
, Z- g6 |5 s5 k  xbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
* e0 ~# v" o, XqryItem.addRelationship(bomItem)
  N- @8 ~% q9 ^: A# M6 b( ?
6 S$ m7 ]0 X4 c. r  b' Perform the query.
' N) N) K1 b% oDim results As Item = qryItem.apply() , r! T0 R% |" P- {' U; V

4 c8 _5 F9 l2 _) c' Test for an error. " [3 S8 O. ?& H# }6 u
If results.isError() Then 9 D) U6 U) ~. Q. h- k
  Return innovator.newError(results.getErrorDetail())
$ p0 S# J5 k( }0 j2 yEnd If 2 ^) z1 G! T0 i3 s4 a5 V+ F
$ c( o# j2 a& p& a' \5 V
' Get a handle to the BOM Items.
/ r0 C( e/ r! I' |/ r# ]' v! QDim bomItems As Item = results.getRelationships() ; E5 A& o9 K2 T7 S
Dim count As Integer = bomItems.getItemCount()
8 j/ G0 n) o4 n4 I& R' `Dim i As Integer ; A& K- ]0 u3 l# Z# N( i( D
& t7 E6 t7 S% V# _9 u. D8 D
' Create the results content.
3 {) p; S/ b- y6 e: e8 Q( ^7 }. f8 hDim content As String = "<table border='1'>" + _ * M7 k! |. |+ ]
  "<tr>" + _
3 {. C( x' q. a  D1 U0 `    "<td>Part Number</td>" + _
% x5 f! U6 ~- _! k    "<td>Description</td>" + _
% |0 G1 y+ }8 D  `# g; Q    "<td>Cost</td>" + _
  k7 q$ P' u; E- D0 g    "<td>Quantity</td>" + _
) P8 l) y1 d3 X$ e1 X! G' k% @( |  "</tr>"   u$ T8 b, l" o; j4 k  E3 d
* l' m( ^7 H# S$ ]- s
' Iterate over the BOM Items ( h. Z4 Y5 E2 c/ Y1 S1 O
For i = 0 To count - 1 " P2 r! C7 K8 a- n
' Get a handle to the relationship Item by index. * T+ d8 I' f. x  ^. L: \
  Dim bom As Item = bomItems.getItemByIndex(i) 1 @! \' L6 ~3 Q( b9 e
9 H- `6 ?2 t% B3 w& ]' ?: t
' Get a handle to the related Item for this relationship Item.
9 L5 g$ N$ i8 V0 ]& O3 n4 X$ c% ~  Dim bomPart As Item = bom.getRelatedItem() 4 e6 d& y7 U: [+ x  t" r: ]3 o. T
9 r4 E% w! W8 T/ X& }2 T: C& D
  content += _ " `8 @2 j; h' N) o$ w
    "<tr>" + _
3 b/ l0 y# ]5 O      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
4 [' b1 o6 v) C: u+ Z      "<td>" + bomPart.getProperty("description") + "</td>" + _ + F  I# I4 z) H, k
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
. X) y- E, a3 b; a9 P. E      "<td>" + bom.getProperty("quantity") + "</td>" + _
; Y' h+ E8 n4 K: h: ?) v1 W    "</tr>"
3 w: ?; B! F" _1 T2 }Next ! c) V; b, d6 j; J; r6 r/ o7 q
content += "</table>"
& @4 m% ?! J- D9 T 7 j6 P. D1 S; ?! ]0 Q3 K% {
Return innovator.newResult(content)
9 V" _8 n& l( _7 V+ a, i  {# B, _$ k. _# }0 C
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了