PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
6 Z) k% I! c4 X# M/ TTo query for an Item and retrieve its structure you build the query as the structure & u4 y8 y4 W! \7 P( {, A% r1 m( \
you want returned.  Use the IOM methods to add the relationships you want and 9 c# ~1 _. s' Y% p
build the structure in the Item.  The server will return the structure that follows the : t8 T) h. h$ U' @9 z
request structure. ; ~, }' Q! Q' n
This recipe illustrates several related concepts together, which are how to get a set
+ y, Y4 j$ z% r$ V! Dof Items from an Item and how to iterate over the set, plus how to get the related
' d( |0 P, z. i+ S4 p' GItem from the relationship Item. 4 B# Z  q' R0 r& A7 R
JavaScript  
! `4 t, g& n1 B1 O( ^; Yvar innovator = this.newInnovator();
/ ?, [' t8 ^% ^( y6 R$ R
9 [3 V5 U8 G( H& Z// Set up the query Item. " B- s- e5 k: Y! m
var qryItem = this.newItem("Part","get"); 0 t; s) ]  D9 }, ^$ B
qryItem.setAttribute("select","item_number,description,cost"); 2 o! N0 Q( g( B2 a
qryItem.setID(myId); 1 k5 ]7 r% c) @6 T7 l
$ ]# R1 a. u  b9 |
// Add the BOM structure.
. P3 e! A( \. H% _# B: Avar bomItem = this.newItem("Part BOM","get"); * ]) I4 I! Q' G+ L9 q
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 1 F6 c9 a( S$ e5 W) J9 O+ B2 i
qryItem.addRelationship(bomItem); 2 u  V3 ?, p' x6 U2 R) v. t

# k$ O  q& `& d/ v6 E// Perform the query. ) n' M5 {4 }- e' x5 \: J; F: ?
var results = qryItem.apply(); 7 \% X( v" c! D9 k0 [' \1 f

7 x7 C! i$ s4 J; x/ J// Test for an error. 5 g+ B6 B' w' I1 r+ D
if (results.isError()) {
  H" Y! k' B# t  top.aras.AlertError("Item not found: " + results.getErrorDetail()); ! M- n1 g7 }* u9 s
  return; # ]4 X  ^: i1 Q; f9 J
} 6 L+ @) Q6 j6 H

' r! _- V. b: l// Get a handle to the BOM Items.
  ^) V  A+ ]. }% _var bomItems = results.getRelationships(); + [* F0 P0 K! B# N) n0 F) M
var count = bomItems.getItemCount(); 2 i. `/ z2 [1 C1 @" R8 j7 r
& @) z6 X; Y% J7 \/ R
// Create the results content.
+ x: _0 @0 O  \# s1 M2 Vvar content = "<table border='1'>" + $ ~& V: P2 d% U" Z- k! N
  "<tr>" + ! Y/ J  K* n0 ~( B& N5 J  A
    "<td>Part Number</td>" +
6 ?/ {  i. x' l0 e    "<td>Description</td>" +
; ~% c2 M0 `% f; E- j% m    "<td>Cost</td>" +
6 d) B4 |9 P1 Y+ ]4 w0 o    "<td>Quantity</td>" + & D1 [/ l# i) j) t
  "</tr>"; 3 u( f+ ]: q$ u& n, P2 N

! p1 j4 |$ ~7 R1 Q4 Z1 y% J// Iterate over the BOM Items.
0 F7 }0 T4 X7 l, Jfor (var i=0; i<count; ++i) * w. i5 H9 W" F' F
{ 3 p, A% x+ z  Z7 k8 i
// Get a handle to the relationship Item by index.
/ [  R, n- }/ x1 z2 q  var bom = bomItems.getItemByIndex(i); * g; O% h3 b0 l
// Get a handle to the related Item for this relationship Item. ! I2 v( }' U7 `+ J# p/ k8 T4 e, x& p/ H
  var bomPart = bom.getRelatedItem();
9 {1 D: E/ o- P( K 3 h1 D" ~6 z4 K9 `4 v  C. {, z0 j  l
  content += "<tr>" + + r  [6 _- m3 G. V  D- }
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
% l( c2 j+ k( K% [/ K0 c( d      "<td>" + bomPart.getProperty("description") + "</td>" +
8 j$ S, v5 w( ~5 K- J% i# |0 [      "<td>" + bomPart.getProperty("cost") + "</td>" + 4 `6 |1 h, Y) S; w  o' y3 V% r. D% v* F
      "<td>" + bom.getProperty("quantity") + "</td>" + / o3 l7 P6 I/ J9 v! v) |
    "</tr>";
. X8 ~5 h' Q: O}
0 c, {' b$ D' q! ~& rreturn content + "</table>";* _% ^) L1 g4 E5 G% k+ N; F

* E6 C- S) F& m
8 p" W' B/ `  Q1 {" E% t& R+ E

4 y6 h( {1 r2 q2 |- K- m( k

6 ]% [6 `+ g/ V' r% E4 [C#  
" C; |! h+ V) w: a5 R% Q8 dInnovator innovator = this.newInnovator();
. ?' V3 d  }  K8 c2 A+ G
+ |  v, D* g1 D9 m! O; [9 X// Set up the query Item. 5 N' r$ z  ]+ a* _4 m
Item qryItem = this.newItem("Part","get");   z6 q0 y4 G1 g4 v! y
qryItem.setAttribute("select","item_number,description,cost");
# j% \* Q( Y5 r  [+ |; U! VqryItem.setID(myId); " t$ R5 Z+ T6 M& d4 }
! E' z& B* a& B4 }8 R
// Add the BOM structure. $ {  o, k8 K+ I' {1 A: f% \
Item bomItem = this.newItem("Part BOM","get");
0 i' n9 d- U- ~  \$ {; AbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
8 l5 c! m" ^! z* B- X) F3 I( pqryItem.addRelationship(bomItem);
1 y! p! `3 V; Z4 C# f$ g  W6 o2 W
2 ?% g6 A, \& O& _+ v7 g4 ^// Perform the query. 0 M% v( _  L7 d: I, o+ ~1 P
Item results = qryItem.apply(); * H  n5 t. o! f- M! \5 O; L, J
2 t) x8 `1 t) |2 J; G6 e
// Test for an error.
8 q8 Q/ R6 L9 O) [5 ^6 U1 Kif (results.isError()) {
5 o- J$ F* z3 @. S. g2 }  return innovator.newError("Item not found: " + results.getErrorDetail());
* P0 Y( g- Y* k/ Z3 n  l}
' l2 O$ A" g; l% v " L& L5 v/ |: v# c8 ~
// Get a handle to the BOM Items.
7 K: M/ q8 f5 zItem bomItems = results.getRelationships();
/ c- |3 V2 M- S8 Y* oint count = bomItems.getItemCount();
) U& c; e6 h5 Lint i;
) ~; @2 ^1 t. V9 b, @& [ " f# @1 w, g4 \
// Create the results content.
/ a7 J6 [2 B4 Q: fstring content = "<table border='1'>" + 0 o8 j$ p7 L: |, T
  "<tr>" + 3 s" F' Q2 Q: t4 d1 N; w9 k
    "<td>Part Number</td>" + " {7 S# a0 c9 ?! X& x- t% P0 w- J
    "<td>Description</td>" +
# C0 B6 f) y. Z1 V9 i4 A. y0 \; ?    "<td>Cost</td>" +   y( m. y" b2 f3 [- X
    "<td>Quantity</td>" + 0 x) U/ l  S) |; D
  "</tr>"; - A  b1 Y4 a; l

9 |, s& j. r. C/ W// Iterate over the BOM Items.
4 ~: ~" M' U# o; k: c; ifor (i=0; i<count; ++i)
. A" m; o$ b- `) z& K) ~/ S{
! k+ a5 H: f6 K! a// Get a handle to the relationship Item by index. ( L! e/ h$ |3 C
  Item bom = bomItems.getItemByIndex(i); & h# X& |+ v0 F0 R) J8 B
// Get a handle to the related Item for this relationship Item.
/ O1 ~7 Z3 @" n3 r8 Z3 _- Q4 @# c  Item bomPart = bom.getRelatedItem();
3 ^( C7 f' d8 |4 i2 l ; J. V( ~/ _8 x% \! {1 T. Z: ~4 h
  content += "" + : q; s3 ]8 K) z" i' {: B7 K; w5 c( j+ m! P
    "<tr>" +
6 F. I" `7 ]- T6 [- A. E8 c* E* Y8 [  i! j      "<td>" + bomPart.getProperty("item_number") + "</td>" +
: B; [% p4 Z4 H- p9 p9 K0 v      "<td>" + bomPart.getProperty("description") + "</td>" + ( _3 E- G8 E  Z4 u( |
      "<td>" + bomPart.getProperty("cost") + "</td>" +
# `( r" C2 |( l+ ~      "<td>" + bom.getProperty("quantity") + "</td>" +
& p5 V, c% S6 D9 h# A    "</tr>"; 4 y0 C6 U8 q  s9 S1 e' ^
}
9 H4 w* M" h6 x# |' @7 H6 S" _content += "</table>";
' m% v! x" f; r& i4 d) w) F$ ]- c7 ] : U0 H; z/ M# N9 i7 m" N- J
return innovator.newResult(content); ! E" `9 V' d" \; L1 g9 c# C

, {6 Z$ u! `$ p; t0 q
3 j6 C; t+ R4 A# n( {% c$ \
5 d* B$ G% L% E- p5 P3 Y0 V

+ S2 L8 ~7 k, H+ P  u- o( b  s+ L- o- L7 y; L$ @- v$ {5 ?$ t

  [) A! {. u. G' k & _; \) b1 L) B" {" ~" C
    Page 46 2 }# X* {0 Q3 R4 R
6 n/ q. p" x. j7 M9 D
Copyright   2007 ! ^) N% u# Q: i6 [6 K  U+ e8 s6 b
Aras Corporation.  " ?6 }7 a- S* n5 M3 Z0 `# t7 O* s
All Rights Reserved.
; k" f* c( u: d* EVB.Net  
" m- Y4 N. Y/ E6 u7 CDim innovator As Innovator = Me.newInnovator() ' C( ?* C) x- O6 |
; B# Q5 d" c# e- z
' Set up the query Item. % |6 b: H$ C5 T, A) [" E
Dim qryItem As Item = Me.newItem("Part","get") ' Z2 r" W% }6 E
qryItem.setAttribute("select","item_number,description,cost") ; Q) Z6 N0 B/ A) Q7 a
qryItem.setID(myId) & e+ r0 x( F$ v4 R5 d# M9 |
) t% f3 u* ~8 m4 u: t; q& k
' Add the BOM structure.
2 c+ V( ^/ [1 B! D0 ~+ Y" s/ i5 \Dim bomItem As Item = Me.newItem("Part BOM","get")
' l2 y8 y. `4 }" {4 J% C0 {) PbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
/ g+ O: L* y9 A' O7 M9 {) g5 }" pqryItem.addRelationship(bomItem)
4 V' h, l5 ?  j5 e4 E; m6 B, t / q- g' w6 ~" Y  V
' Perform the query.
4 O4 `1 i& `- z# W, S  KDim results As Item = qryItem.apply()
7 e/ l1 \4 B" k( C. R
4 T1 q% u2 g) M# K' Test for an error.
# y# k: G+ k! d, b  X2 r; gIf results.isError() Then
* L- w- w8 c& ]5 G8 W  }  Return innovator.newError(results.getErrorDetail()) 6 J, x" _( r& U% X; L4 H* ~
End If " f" {4 Y* V, n9 x& z4 K0 D

" Z1 R7 Z4 h) I8 m' Get a handle to the BOM Items. " v+ ^- w3 y( N- V; E/ a7 O9 v
Dim bomItems As Item = results.getRelationships()
; W6 P+ i3 b; e. C8 l7 aDim count As Integer = bomItems.getItemCount() 5 o6 k- H" s# Q7 u; Z( t
Dim i As Integer
( H. B4 _) ?$ z  t5 A# _  E% I# _ 1 j) q+ L! C, K0 s8 u# d
' Create the results content. ( s7 E7 P- d2 ?$ l3 ]
Dim content As String = "<table border='1'>" + _ / Q/ g9 }% w' ?% a9 y. s1 l
  "<tr>" + _ 3 }0 x0 w6 ?& M  u% ]8 [6 M
    "<td>Part Number</td>" + _
9 N; F! ]( Y1 i7 O5 B4 A    "<td>Description</td>" + _ * b& N2 \2 V% B* k
    "<td>Cost</td>" + _
9 t1 Q$ e6 A& ~/ w) M) W: T    "<td>Quantity</td>" + _ 0 c+ Z1 r" s( G! Q3 L
  "</tr>" % o' P. \1 z+ K, d& M
4 E9 T- f" p/ J% C0 G  b8 _& C& @) ?
' Iterate over the BOM Items
: y% I8 S' B4 a; `; y7 fFor i = 0 To count - 1
2 G6 ^7 z: I4 [- m4 d" _' Get a handle to the relationship Item by index. 4 O7 H  I8 h! U$ _' C; t, Z& D( r4 X
  Dim bom As Item = bomItems.getItemByIndex(i)
/ Q; |. B, \4 {6 b' Y& D & x7 V7 S8 t6 f! }- z
' Get a handle to the related Item for this relationship Item.
. f7 {! i% u. o8 A3 D  Dim bomPart As Item = bom.getRelatedItem()
- q- E' F- u- ~ 1 m) z' H" u7 T( u* f# ~
  content += _
0 m6 C5 p: @9 j( L    "<tr>" + _ , l* ?2 y& @( [8 U
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
7 h6 f7 T0 R- o3 d& V8 A  Z; [      "<td>" + bomPart.getProperty("description") + "</td>" + _
7 M: w% j0 l9 T( {) l' _. `% I: N      "<td>" + bomPart.getProperty("cost") + "</td>" + _
$ ~1 }# |3 s8 D1 x, k      "<td>" + bom.getProperty("quantity") + "</td>" + _ : R0 E9 N& A! P( P
    "</tr>"
" p4 M" @  A0 ZNext : E) u- Q% x+ a
content += "</table>" 1 S/ c! a/ }3 m
6 S+ E- f' V& z! S+ i7 X
Return innovator.newResult(content)
: y/ L; U9 L5 ^
9 b' G% f. p1 h( ]
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了