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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
% b% \8 p* q" J1 ~$ _$ rTo query for an Item and retrieve its structure you build the query as the structure
  w+ i, M8 a0 {3 w5 X8 Q  eyou want returned.  Use the IOM methods to add the relationships you want and
4 _0 C! U, }. P; p+ e- @: Ybuild the structure in the Item.  The server will return the structure that follows the ) ?- Y. Z1 q/ C- `" X
request structure.
) g8 V4 K) s, ?9 P4 f0 aThis recipe illustrates several related concepts together, which are how to get a set " M$ J* x6 E3 b4 |* w+ C
of Items from an Item and how to iterate over the set, plus how to get the related
. @) {; |0 t2 E3 W/ w" y1 a5 WItem from the relationship Item. 8 y! R: C. F% _4 M  n
JavaScript  : ?* V. R4 e+ A# c% Z$ b$ \
var innovator = this.newInnovator();
# ?) @9 R; f& j0 p
$ y9 \& I7 \8 ~7 K5 T1 m; G" ?// Set up the query Item. ; ]' i" O( Z( Q/ }. q# C
var qryItem = this.newItem("Part","get");
% R6 K0 p: o/ F1 `# A6 vqryItem.setAttribute("select","item_number,description,cost");
: [, }) L- D, F' c# H/ iqryItem.setID(myId); $ Y) a2 ]/ C- l  K5 E: ~
% s1 u" P0 t2 X& F3 ?7 \# G3 Z% {
// Add the BOM structure. ' z$ L0 s' M" P* H; ?2 j
var bomItem = this.newItem("Part BOM","get"); / F. r) z# L) L# p
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
8 |$ }, k2 q: `2 D/ mqryItem.addRelationship(bomItem); $ `3 M. ]. L( z+ V* R5 P
& Q3 f) r) D) [, U; k
// Perform the query.
  r) U6 ?! s6 C( h: W5 Bvar results = qryItem.apply(); % K3 j6 p# ~/ X3 Y  k+ z' w
% [% J! D, c- v; I5 B
// Test for an error. % C2 b6 t8 T+ Q' C) V
if (results.isError()) { ( X- A* s: [" v3 c: K
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 1 K& u+ r2 W* [0 ^, Z
  return;
" b+ u  z) i5 {} " l( ?7 |& r+ t$ @4 V% o; B
) u- N8 h' h' g+ S7 D5 o  m
// Get a handle to the BOM Items.
8 r9 ^0 f7 T: ]0 Vvar bomItems = results.getRelationships(); ' Y- ?2 l' j* c$ L& h
var count = bomItems.getItemCount();
0 ^) I$ v6 j: ?
, k1 [6 T- U0 T: ^" U- Z* k/ r: C// Create the results content. + R+ j) v6 O3 e2 O+ C4 c
var content = "<table border='1'>" + . n# `( d0 }- @
  "<tr>" +
$ H. W5 u3 O& i! b- W8 V    "<td>Part Number</td>" + 5 e) c# _- h' L! L  m6 M" ^, j+ k
    "<td>Description</td>" +
* G1 z$ N5 h& l& A    "<td>Cost</td>" +
( {4 e$ C7 B/ v1 q    "<td>Quantity</td>" +
% x9 d0 {1 I  J2 C  "</tr>";
/ E. K# z$ j, e. F+ v  ` + Z. Z: V, Y0 m9 ]' ?: I
// Iterate over the BOM Items.
+ j5 r8 D- D, c2 H( {* f( c4 kfor (var i=0; i<count; ++i) 7 [( f6 H& N( Y8 P: u# w
{ - Q8 B, V4 y5 k
// Get a handle to the relationship Item by index. 4 W: F% e  D- y: Q! w; r
  var bom = bomItems.getItemByIndex(i); 8 F! I0 z, V7 m* S! p' R: Y
// Get a handle to the related Item for this relationship Item.
7 S7 l! Y  U3 K2 a. Y) G& b5 ?  var bomPart = bom.getRelatedItem(); 3 I% P9 U7 Y1 K* Q8 F- e4 E
; _* Y; B! [7 g( n/ d
  content += "<tr>" +
7 P- L. r& h) M      "<td>" + bomPart.getProperty("item_number") + "</td>" + $ F5 t. y7 v9 ]- e
      "<td>" + bomPart.getProperty("description") + "</td>" + " z' k1 |; Z( v& D
      "<td>" + bomPart.getProperty("cost") + "</td>" +
; I$ v) Z  k0 ^7 T  j* @: t      "<td>" + bom.getProperty("quantity") + "</td>" +
) }0 x: z  S& g3 ^5 Q6 J# u( |1 v    "</tr>";
( `5 c6 L0 M" a  n/ j9 t6 @0 ~} ! i  u) z" d  B- S
return content + "</table>";- K# a7 A- A  f7 d2 G

) L8 a3 P/ h" T/ m; R$ F% e9 O
% i7 }) Z# E5 R, f. V0 l
) z: a$ t4 K4 I! y( n9 i& P" L! i

/ Z* R' c& H2 N, ^C#  
. Z: G5 i2 z4 \& o- B2 E9 XInnovator innovator = this.newInnovator();
9 W7 L8 h, u) C9 O' W  z 5 G, [2 p0 a' K  `
// Set up the query Item.
: N/ ?% Q" [0 U5 N. N, {" V5 ]Item qryItem = this.newItem("Part","get"); ' ]& R7 y- F# F
qryItem.setAttribute("select","item_number,description,cost");
% }+ u# U6 a% EqryItem.setID(myId);
0 y( j( V8 }# S$ r
. f( d+ e' i& O6 M$ H// Add the BOM structure.
! m: `3 m: s' XItem bomItem = this.newItem("Part BOM","get");
; }# c) N8 _5 ]- ^- d& G6 h4 z; bbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");   F: h6 E9 ]7 k3 {* ?3 O% h/ ?
qryItem.addRelationship(bomItem);
1 h/ O  W6 ~# E8 ^7 }. [ 8 w7 w1 M' M2 X" W
// Perform the query.
6 B+ f; A1 w% v3 l# d" I) zItem results = qryItem.apply(); 5 L0 T# a$ }! j
# J4 p+ M- D+ y/ r* N
// Test for an error.
7 O! K8 ~/ p6 d9 r) P. n1 {1 Aif (results.isError()) { $ V& q' `3 h# ?/ N4 U
  return innovator.newError("Item not found: " + results.getErrorDetail());
" F6 N6 ~9 ?2 r+ ~}
& Q! N4 ^4 @4 T4 F+ n% j8 N# |+ L* M5 K : i$ a% l8 {" V8 y6 `5 e
// Get a handle to the BOM Items. - J  r5 U- S. m0 P# L
Item bomItems = results.getRelationships();
+ i, s$ {: L4 _  qint count = bomItems.getItemCount();
5 b  J% c9 ^5 R1 R4 X3 L* Eint i; 2 q) V" U# t* S  U7 m

' R: J+ @( P* r' P+ j! }% p// Create the results content. ' j4 i- ~! K. Z/ [) @
string content = "<table border='1'>" +
* |' P2 y1 ^6 O" c2 G  "<tr>" +
7 s! r9 M8 G; s) [' ^    "<td>Part Number</td>" +
# N7 l! T% S! ]4 G- y/ @    "<td>Description</td>" + 0 d7 p% H, |. ^! N9 m
    "<td>Cost</td>" + " Y0 l. c' ?& |0 k. x
    "<td>Quantity</td>" + & \/ P; F4 X" F6 J# d
  "</tr>"; 7 U4 A, [5 C3 T% _$ J8 ]

" @- E. N/ y, A& t  y! U// Iterate over the BOM Items.
- L/ e8 o7 R8 x! Y7 R, @: `for (i=0; i<count; ++i) # Y' P0 A1 |2 Q" h% b8 j
{ 2 K1 e1 ^( _0 Z3 r! n: U
// Get a handle to the relationship Item by index.
( [4 u6 E. d% k2 C, h  Item bom = bomItems.getItemByIndex(i);
" }2 y+ M" o! x! |4 s; V5 f- \' K// Get a handle to the related Item for this relationship Item.
/ U' h. ^7 `( ^  @+ J" Z; l4 p  Item bomPart = bom.getRelatedItem();
. T/ c. ]) ]# ]  A
5 \" P( z# J+ T7 N: D$ W  content += "" + : v& K) ?  G/ F+ I' U! S
    "<tr>" + / x- g7 a/ l8 f8 d) f% X: [1 L
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
* r6 k9 g- Y+ Z6 V. Q      "<td>" + bomPart.getProperty("description") + "</td>" + 0 l5 g& ^( j- U% ?( P
      "<td>" + bomPart.getProperty("cost") + "</td>" + 8 }0 e1 r# ^8 D. ~% T
      "<td>" + bom.getProperty("quantity") + "</td>" +
4 ~- v; T& ?8 v' U7 G/ D1 u    "</tr>";
2 g9 |- ]* f! m} 4 k2 h$ S- _+ |$ D& K: x
content += "</table>";
$ P) T2 J# U5 p) b( z6 \& @3 r % _  z! N2 l0 v$ j6 a
return innovator.newResult(content);
& i  W: d# f1 J# I  P0 b" ], @  W' V: g3 z2 E" ~9 j
/ g3 W  _1 Q6 v. I. ^5 ~
! [1 ?+ o2 v- U' v

: I6 X" ?5 N: ~0 \( B9 V1 i; `3 [
0 X  x1 d; s: F

: D/ A: V! x2 h
! W, S0 |+ O, A9 M( ]9 y  T0 U8 d  e( w    Page 46
, D( n( A' `& { $ N) D4 ?9 b% G, z5 N5 D' G& ~
Copyright   2007 , v2 b( `% r0 @1 t4 M4 o
Aras Corporation.  0 m# M7 b1 n7 O0 V1 X7 O
All Rights Reserved.
# c6 n# a! t6 p. O8 j5 E( E* u$ TVB.Net    v1 c( T9 D+ r1 m
Dim innovator As Innovator = Me.newInnovator() & P2 s% ?' s& m; x. W% q9 \
3 v5 t  F/ P, A4 X' k% `3 K5 _
' Set up the query Item. 5 r2 Z0 ?: P. D' z
Dim qryItem As Item = Me.newItem("Part","get")
  k$ H! }7 c5 f8 x: z$ SqryItem.setAttribute("select","item_number,description,cost")
- Z- _; V  r; fqryItem.setID(myId) - l; c. r7 }7 k1 H( e7 z# I

# Z8 K5 }$ Q8 ?0 g  u, x8 p+ y' Add the BOM structure.
1 A7 y! w: a+ Z) U5 I! @* i( \Dim bomItem As Item = Me.newItem("Part BOM","get") : h  E; h: D7 x5 i. K2 E
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
  `0 f0 O* m0 b- n7 yqryItem.addRelationship(bomItem) . Q. G& F$ G9 t0 d

, m* l+ c1 `/ i  E: }' Perform the query.
5 _$ a8 x5 d( D9 K- JDim results As Item = qryItem.apply() 3 j7 f1 p  f. M! u

9 u2 n1 S' N; s' _* R' Test for an error. + a6 [$ e" |3 C0 x
If results.isError() Then
- [  {! F4 p% e8 {. q6 A  Return innovator.newError(results.getErrorDetail())
' e4 F9 E  |; qEnd If
1 H$ \* ~: t- V. i$ z . @6 v: z  i1 _5 w
' Get a handle to the BOM Items. / V8 `5 P! ^" ]$ Z
Dim bomItems As Item = results.getRelationships()
. K0 U3 b  q2 pDim count As Integer = bomItems.getItemCount() & W& _; M  K; K& v/ {) r: t
Dim i As Integer : d% f# m; J2 @7 K9 c
" K) }" j, Q% \  D
' Create the results content. * C2 y  j7 c" @' b- N. a
Dim content As String = "<table border='1'>" + _ 2 m8 o# M4 A1 W. D
  "<tr>" + _ 6 O! _2 l. k+ @6 j/ C& g
    "<td>Part Number</td>" + _
# `$ R! z- s' M; U3 \- U; q, g$ m    "<td>Description</td>" + _ ( D" ^% l' x; O5 A; S8 I  h5 {
    "<td>Cost</td>" + _
  U  q8 L7 G; {: W& T) m; L0 k    "<td>Quantity</td>" + _
1 _) K$ {$ ^# ^3 u6 |( ^  "</tr>"
6 Z2 m# K# j/ r* P4 y+ }" @3 q + {$ d. ]. U8 J$ I* N& F* c. W
' Iterate over the BOM Items
3 f# U- Q2 c3 ~' r& o; \For i = 0 To count - 1
+ n! I( p* c$ b. n" ?' Get a handle to the relationship Item by index.
8 a5 B8 {/ ]* @  Dim bom As Item = bomItems.getItemByIndex(i)
' P7 i; u4 q7 m2 m, c8 f7 W8 u. T! ` - a  \, x* `- ?$ a
' Get a handle to the related Item for this relationship Item.
  G. R& X7 }4 }2 C+ P+ s& C  Dim bomPart As Item = bom.getRelatedItem() . C: e/ e( I7 a

) w# Q- s. ?$ o0 J  q  p+ N: p  content += _ 2 k+ G9 f. ~/ v% |6 X! q
    "<tr>" + _ $ w' H1 m( k/ y7 J0 L7 \0 d" M5 b6 g! k
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
2 \, a& G6 o" B9 J$ `3 I8 H      "<td>" + bomPart.getProperty("description") + "</td>" + _
2 b. a& _% G0 G; }8 I3 j& I      "<td>" + bomPart.getProperty("cost") + "</td>" + _
- H  m; m) [+ F& }      "<td>" + bom.getProperty("quantity") + "</td>" + _
2 D$ S# V, s; X, @/ D6 A    "</tr>"
$ e' h( d% F8 u$ f" o& V' _* NNext
- |: {+ g9 J; k$ q, x  J$ a4 Econtent += "</table>"
8 j0 l1 ]3 D4 Y0 P4 J7 U2 x. \ 4 J$ U  R% j( {6 [5 P1 n3 v
Return innovator.newResult(content) $ ~* e2 {- |% S' v- W& l# C2 V6 E
" s  W7 d2 L7 N/ [; H0 ~  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二次开发专题模块培训报名开始啦

    我知道了