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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  1 l- Q! U' }; s- X3 V( H
To query for an Item and retrieve its structure you build the query as the structure : S0 @  @5 B/ D3 |
you want returned.  Use the IOM methods to add the relationships you want and 8 Z9 T" l# c/ }% P9 L, O5 b
build the structure in the Item.  The server will return the structure that follows the % z: ^3 d) B9 J8 R# T
request structure. 2 n6 ?) o! [( t
This recipe illustrates several related concepts together, which are how to get a set
. K5 p3 }' h, Y. j& Uof Items from an Item and how to iterate over the set, plus how to get the related
5 K9 F' T  k+ W/ K; L. E( g' _- F7 _' KItem from the relationship Item. : G4 Y, u% i# ^' B+ W( a: n6 o3 h  P
JavaScript  7 G) ~' N& a9 I  T" Y' X8 L
var innovator = this.newInnovator();
8 A* ~. K1 f* `) M( A* N* }( h , ]7 ^( H% C: _0 Y3 N
// Set up the query Item.
$ H) z2 Y9 A1 _/ c. `2 evar qryItem = this.newItem("Part","get");
2 t- `+ ~( O# iqryItem.setAttribute("select","item_number,description,cost"); 9 Z* M& G/ A! E" w+ I( V+ q& g4 y
qryItem.setID(myId);
: M2 @- t0 i; p- r
5 V( u4 S$ l. o- U7 `( j// Add the BOM structure.
  \5 {6 `* e, w+ |- ?# B6 jvar bomItem = this.newItem("Part BOM","get");
; ~) n8 c) D" h* ^5 C9 N9 Q$ c" TbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 1 @6 G& e' P+ ~( M
qryItem.addRelationship(bomItem);
, _+ G" Y* |4 ?6 E, m) Q* Q ; [- X' ^5 n7 u( Y
// Perform the query.
& l$ _. {9 }1 D/ ]/ ]& {5 ~var results = qryItem.apply(); & j6 a8 c9 z4 h% V) p+ y6 J6 }1 Z( l) A
0 J& n0 O2 a" O- I. ?9 n5 \1 s* E9 t+ ~
// Test for an error. " i! a( m8 o1 B9 i
if (results.isError()) {
4 b- T8 D( B, k6 |+ c3 e# B  top.aras.AlertError("Item not found: " + results.getErrorDetail());
4 e9 d" `* g. u0 P& B& H  return; # D9 N8 I  P5 q% j! B# H. G7 V' d
}
# e, H- e: |5 c. G4 F
) ~8 O: r5 z3 b# A9 V3 O' N// Get a handle to the BOM Items. ! l. n$ ^/ }" G3 B3 [+ b6 v
var bomItems = results.getRelationships();
0 @) r; N' M$ d1 {var count = bomItems.getItemCount();
& E, I% U6 ]. r; B1 c
4 |; c5 R  G9 m# m- A5 f  Q// Create the results content. # u  G2 N' D. B# L# J2 \9 o
var content = "<table border='1'>" +
5 x; l/ A  N9 j  "<tr>" +
& w4 k5 T6 V; ^* c9 T    "<td>Part Number</td>" + 6 o8 |% n5 F2 ^/ U9 C
    "<td>Description</td>" +
4 `5 r0 z" {; ~" z2 E$ B    "<td>Cost</td>" + / g2 G/ _. O1 e  J4 c$ s/ _
    "<td>Quantity</td>" +
% P2 B  w- ?; F' n+ z# P( j) a# b  "</tr>"; : Q- s! K& l" m; o( c0 Q
7 n: L( d0 R& `* C
// Iterate over the BOM Items. 5 [! S8 p& A& U0 P
for (var i=0; i<count; ++i) $ @. Y% q4 a( n9 k" Z
{ ' \1 U, C: R9 ~, Y: E. t
// Get a handle to the relationship Item by index. 7 V: J* k+ b8 U9 \
  var bom = bomItems.getItemByIndex(i); $ E; A/ S, Q- |; j5 B
// Get a handle to the related Item for this relationship Item.
2 l1 Z6 }' Z9 H9 r; e  var bomPart = bom.getRelatedItem();
9 T8 T2 S, e8 y * Z4 n  z; B4 w# ?/ I& T& h# H, r. X
  content += "<tr>" +
* q2 P5 b) u! G      "<td>" + bomPart.getProperty("item_number") + "</td>" +
! K3 a" n' \; V* o3 Q      "<td>" + bomPart.getProperty("description") + "</td>" +
  o; h9 ^/ U9 X) r! X0 `% R+ p4 |      "<td>" + bomPart.getProperty("cost") + "</td>" +
, B$ M7 W" L; n/ A      "<td>" + bom.getProperty("quantity") + "</td>" +
4 I; p' ]4 i; K    "</tr>";
/ u( ~) M. I6 Q% H7 F}
4 ~& m7 `& }: S! m- b! H( R7 |: freturn content + "</table>";3 {+ m$ U+ G8 ^! Z7 o+ s

9 T9 u( i: P/ c
* c8 x6 [) y: [1 H
( M' D' f  s$ A

* M4 \- i6 K& _C#  5 J: k3 k4 P3 g, p. Z0 S! l' j
Innovator innovator = this.newInnovator(); - U7 a3 L: g% y4 W& y6 o

5 z6 P" m" Y. V2 `6 A: b" r7 D// Set up the query Item.
( n% G/ s+ @2 ^+ mItem qryItem = this.newItem("Part","get"); " c7 n5 A& k. ]( P$ Q4 N
qryItem.setAttribute("select","item_number,description,cost"); 9 K$ `' q0 L4 C+ ^, r  A! i0 Z7 e) N
qryItem.setID(myId); + t6 i& b' q( O. p' d$ S# _
' E1 F0 H: O( z* S- W  k4 g5 m
// Add the BOM structure.
  f5 b: \+ F) E3 O. M7 ZItem bomItem = this.newItem("Part BOM","get");
# w" v, Z& W$ R/ a8 k7 Q' y4 zbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
* r2 T# j/ H7 y4 H- ?1 v' ~  {6 qqryItem.addRelationship(bomItem);
  }% P0 L& E9 r. _" j $ M, N3 [5 {7 y; r$ z0 Z! |
// Perform the query. ( p; ]1 s2 h8 b' Q- E/ @
Item results = qryItem.apply(); 3 B4 y4 E- t- i9 }( g% Q- u
& e) Y4 x2 O4 B8 b
// Test for an error. " F+ ?! h' F$ C! K4 I( o
if (results.isError()) {
$ G% g; c1 {0 i6 |$ W; u  return innovator.newError("Item not found: " + results.getErrorDetail()); ! {$ F2 e& l/ S  t3 B$ l
}
1 C2 `3 J8 H* w  O! d6 d 0 j; [$ n8 |5 S7 u  H
// Get a handle to the BOM Items. % F+ a% k- j" Z5 Q3 O$ R
Item bomItems = results.getRelationships(); 4 ~% I7 G4 J' D2 u9 Q9 m* X9 {
int count = bomItems.getItemCount();
& j% Q3 p% m* a3 X5 `# a2 p8 _int i; 5 f5 U& @' G" Y' i9 c
2 m2 [, \( i& }6 D
// Create the results content. 5 ?/ T7 g, c4 j, W* Y# l
string content = "<table border='1'>" +
( Z9 ^) Z% }+ E1 ?0 [' e' u$ Q0 b0 }  "<tr>" + 6 \+ _5 \  Q, J! H( O7 h1 D) C
    "<td>Part Number</td>" +
. F9 \  H9 L3 g( {3 g    "<td>Description</td>" +
2 V1 P0 f/ f9 B6 b: N" H" q    "<td>Cost</td>" +
% i2 ~0 ~+ U' o9 l6 [- Y: D( E    "<td>Quantity</td>" +
5 o$ q( i) X, [  "</tr>"; ' |. J0 }3 S9 L  i) V, s9 E$ t

7 y/ t* f9 |3 L# C1 a// Iterate over the BOM Items. 0 b  X$ [( k/ C, Q
for (i=0; i<count; ++i) ( A4 Z2 p! @( ]. w$ R& b) F6 E6 s
{
" o9 t; n  e0 O3 _( g// Get a handle to the relationship Item by index. 2 C! |9 }' I# j+ p# I! |$ S+ V
  Item bom = bomItems.getItemByIndex(i); & @, N7 |; ]) v; S) D( G
// Get a handle to the related Item for this relationship Item. ! Z9 v0 I; [0 R; _+ |! D2 v
  Item bomPart = bom.getRelatedItem(); 4 H  l  ]% g9 p1 ^
+ ~9 w* D: }7 f+ \( C- w3 P- ]
  content += "" + + l+ l9 }) ]2 H  \$ a
    "<tr>" +
; D8 c; `9 _: p" e8 K3 l# A      "<td>" + bomPart.getProperty("item_number") + "</td>" + 1 Z2 o% j/ ?4 ~# h6 a. a7 B
      "<td>" + bomPart.getProperty("description") + "</td>" +
6 @$ i- n- a  n/ {      "<td>" + bomPart.getProperty("cost") + "</td>" +
5 c0 Z8 r% k6 R# l      "<td>" + bom.getProperty("quantity") + "</td>" + 7 H( F5 p( r3 i% ~) N& f
    "</tr>";
) L" }6 ~6 ]( E" w}
+ Y2 ]- _( `1 Z# D1 F1 z# Wcontent += "</table>";
2 q% {: c8 m/ {! W: T
& u2 B/ o2 Y  h8 _$ t2 treturn innovator.newResult(content);
0 e( q4 t/ D7 z/ Z3 N
) F* Z/ Y" ~* {+ k/ D: f2 y, z: V: M
$ w. e  q) U) ~

$ N+ Q% P6 E- M( R3 K* s

2 z' r1 Z" C$ ~$ n: K2 u: K" H
& A. N, R+ R! ~% \
: k( X/ p9 A. |/ n

0 F8 k& M/ i5 M' h3 ?    Page 46 - P+ q3 d( w: g) Z" O: R& ?
. E" a4 ]) y: A6 Y# S
Copyright   2007
5 \3 O6 Y0 |. K- E+ _Aras Corporation.  : f/ k& U6 p) @7 J
All Rights Reserved.
% D( k- s* B+ h- g' L& o1 xVB.Net  
8 ?/ h- P4 m" P' h- u( sDim innovator As Innovator = Me.newInnovator()
6 o* C  c- f! U2 @: z2 I ( c4 o/ N$ [* t4 m$ U2 S5 K9 Q
' Set up the query Item.
; [# A* I6 H* }3 U0 v+ qDim qryItem As Item = Me.newItem("Part","get")
3 a: V& U+ N& B: a/ C; ~2 yqryItem.setAttribute("select","item_number,description,cost") ; I- N- _* v6 [/ M' L
qryItem.setID(myId)
% I2 m$ G" T9 i5 g8 e: U9 g  V" P8 m) V
& r% {( X  X3 U" ]' Add the BOM structure.
, U- w8 u8 }6 w- v% |, y. }! }# hDim bomItem As Item = Me.newItem("Part BOM","get") * s: j3 O$ q, G: x
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! ^3 G7 p* M2 a! e& bqryItem.addRelationship(bomItem) 8 M; w+ @3 Z2 y/ k
8 b; d4 G7 q0 `0 y4 Z/ M! k# K
' Perform the query.
$ b" z1 I6 h) a7 l: a$ ?7 hDim results As Item = qryItem.apply()
1 F" V/ F1 X$ t; Q3 X0 d! a6 W 2 F) ]3 R; P5 h" v  n( \
' Test for an error.
. q) \0 B! C9 x2 xIf results.isError() Then 1 r/ }1 J, \/ \5 S/ ?# z
  Return innovator.newError(results.getErrorDetail()) $ u5 A( `8 \6 R. L+ M; h
End If
3 D; z  d( ?3 h2 Z
1 s+ c/ g9 _) W3 k& K' Get a handle to the BOM Items. ( ~; ~2 }& a2 M; g
Dim bomItems As Item = results.getRelationships() 7 j$ V, @4 N( f1 t) p; i4 V
Dim count As Integer = bomItems.getItemCount() % i8 Q% p  k4 f5 x/ J% p" E
Dim i As Integer
$ h9 D0 \% V& t5 _" |
9 m, r# N) S0 d/ u/ b' Create the results content.
) g' n1 z% w# x1 dDim content As String = "<table border='1'>" + _ ' Z6 b/ j) P7 x/ A
  "<tr>" + _ 0 b7 {' _2 U' B
    "<td>Part Number</td>" + _ 2 `7 i' K  H6 _
    "<td>Description</td>" + _ " P$ o( J. q- G6 g" K4 |
    "<td>Cost</td>" + _ 1 J: a# G7 t* e% i3 z+ C9 p
    "<td>Quantity</td>" + _ + ^9 ~4 g  t  \& h
  "</tr>" / J$ O9 |1 A3 |& r! }/ O+ _
6 k  |" @5 @7 G9 r( x
' Iterate over the BOM Items
- l4 O2 q& I0 L4 N# B0 z2 M4 e* [/ BFor i = 0 To count - 1 5 A% A& T6 k! _. f3 C
' Get a handle to the relationship Item by index.
$ Q/ ^; g0 ]  R8 \- L  Dim bom As Item = bomItems.getItemByIndex(i)
" [: Q8 \( N/ R! R2 e " t% K( v8 Q! r( l8 C% z" s
' Get a handle to the related Item for this relationship Item. 0 q, Z/ e1 k, k' g
  Dim bomPart As Item = bom.getRelatedItem()
" f3 h' \2 Y/ j# k" e; N! a
* ~& f( @8 O6 G  content += _ ) o; ^3 B5 Y6 E
    "<tr>" + _
: R2 C" I, e$ f5 q9 K! E, h4 `      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ # n: i! a( P* R5 y& U8 ~$ R6 `
      "<td>" + bomPart.getProperty("description") + "</td>" + _ 7 ^0 I! k& S# k: @& @3 h* B
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 7 P; ?0 \+ N" P* }
      "<td>" + bom.getProperty("quantity") + "</td>" + _ 6 ^- I, C9 l1 W) w7 G6 N" C
    "</tr>" 2 t) ?- }( P; A
Next
- a7 n/ T* [1 _( J; _& M' t% g. xcontent += "</table>" 0 z( N" G0 h7 n1 Z6 z
2 E6 l7 G0 t+ A' s  Q
Return innovator.newResult(content)
" X1 K/ v* ~3 u$ r7 ^" L
9 L. m1 ?; o1 ^9 Q$ V
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了