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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
/ ^4 w/ [- M# n8 [) \To query for an Item and retrieve its structure you build the query as the structure
3 {" M! V2 H' K7 X5 jyou want returned.  Use the IOM methods to add the relationships you want and
- L8 r, M' @1 l3 r; d! J" f6 V. ebuild the structure in the Item.  The server will return the structure that follows the ( |  c3 K9 }, f# `; P
request structure. & s2 Z- u& ^3 ^) W$ o4 l$ ~7 ?
This recipe illustrates several related concepts together, which are how to get a set ' [; W8 x$ v$ r1 b
of Items from an Item and how to iterate over the set, plus how to get the related
5 `' z. @9 ^; B& X! |1 UItem from the relationship Item. 1 t* h) S! ^2 y5 L" A7 P
JavaScript    X$ P  L" u/ O. \
var innovator = this.newInnovator();
1 B/ b+ _6 H# r8 u
0 V, \4 ?0 k2 I! h' H' j// Set up the query Item.
% w$ D  K( M; E! nvar qryItem = this.newItem("Part","get");
2 K/ X* F* @6 u: eqryItem.setAttribute("select","item_number,description,cost");
* a" r# E% D3 l' l3 [qryItem.setID(myId); 9 o! {* v9 Y; y: c4 l- s8 U* ^
+ E3 m9 w8 k4 h/ x
// Add the BOM structure.
1 F4 _" l) G) L1 ?2 @var bomItem = this.newItem("Part BOM","get");
3 o' p+ H; u7 J, PbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 4 m5 Y+ I3 x  B* C9 z! u! j/ z% H3 L
qryItem.addRelationship(bomItem);
( k+ r' }1 i, \' C# W , C; t3 O2 o6 l( V. y: g6 ]) [- g
// Perform the query.
3 e4 M2 ^# R' h% o5 b: d7 V# Evar results = qryItem.apply();
# i. N! s! s1 l3 l2 y
6 |: u' o2 d+ b4 }( F5 n// Test for an error.
7 i. J/ N3 q0 l, m' f3 kif (results.isError()) {
) f4 h9 g, j" U# h( H( M  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 1 ]3 E4 w( E$ {( I+ \1 `
  return;
- t6 q9 b5 }. P% A! P} 1 ]( X0 \; }+ M7 ?; A4 H3 s1 n

- Z* R8 y2 P! }// Get a handle to the BOM Items. 3 e" r' y( f) ~+ y8 C
var bomItems = results.getRelationships();
4 r3 j5 i( b4 n4 M1 s  t. ?var count = bomItems.getItemCount();
8 ]5 Z$ w+ d8 X! P( c2 l
+ ~* U; k$ X& ]: d3 s3 H4 `% z// Create the results content.
1 y" k4 {! u( Z6 [) \7 Pvar content = "<table border='1'>" + 6 G0 g# R6 b' r0 m* g5 d
  "<tr>" + : p* f' X& i1 R- Y4 M9 ~7 i' w
    "<td>Part Number</td>" +   t- D; g1 `) N& x" [4 E
    "<td>Description</td>" +
# \" v8 Q" n5 U) |  d1 {    "<td>Cost</td>" +
: x& m+ w" I. u/ k    "<td>Quantity</td>" +
7 k) a3 R! P5 q3 T# ]  "</tr>"; 7 n3 m6 {: h0 b2 R2 A/ |

- b. q( d, G" D3 h7 V  A6 k7 J& [) \// Iterate over the BOM Items.
  Z2 H/ m( v6 O% @  F4 N# T3 \1 Ofor (var i=0; i<count; ++i) ' e& `& s8 d, i9 ^3 h. R, ?' p
{
  r6 ~# P' A) P( s2 I' _  C// Get a handle to the relationship Item by index. 6 Y' D" Q* Y. n, K$ Q
  var bom = bomItems.getItemByIndex(i);
1 r$ s7 g. S/ I1 H. \3 l# x, K// Get a handle to the related Item for this relationship Item.
0 [* j3 p' j- o' o+ k& |  var bomPart = bom.getRelatedItem();
' Q9 e, [5 g' N0 S* A
! {. x$ M) i' E2 L( E% o7 f6 y  content += "<tr>" +
4 w  l. l' u" d5 c7 l+ G9 M      "<td>" + bomPart.getProperty("item_number") + "</td>" + 8 ]4 t, @, ]+ R/ T
      "<td>" + bomPart.getProperty("description") + "</td>" +
0 _/ }+ P" |4 }* F& }: x5 f" [      "<td>" + bomPart.getProperty("cost") + "</td>" + $ `6 z5 \* E& u% g' {$ m) _
      "<td>" + bom.getProperty("quantity") + "</td>" +
% s  l1 c1 l2 V% c( }    "</tr>"; , z& L, _' }! f' a! _+ A) d! G
}
) }, h8 ^) D$ E. W( Hreturn content + "</table>";
7 u8 d+ n) u; G" K
! g/ q4 V3 v' E  f( e  g- k1 ~& E1 t9 [

  c; R4 X) S4 t' p# S  m4 [  _
3 f' R7 C- V- c* \# [
+ o0 s% N' _  L& t* _
C#  $ a# r3 _; N* E# E3 A  e
Innovator innovator = this.newInnovator();
) \4 ~- Q% |# Q, [4 @
: P2 t* Q, ~  f  Q0 y1 ~: ?// Set up the query Item.
0 R7 H. O- ]6 E; j3 U* GItem qryItem = this.newItem("Part","get"); ) J- h! ~& l! u& R' y0 W3 a
qryItem.setAttribute("select","item_number,description,cost"); 1 A; E" b* B2 T- K
qryItem.setID(myId);
. p2 w0 s* V: o" F1 |
" E8 @3 n* ~& `/ M- l* W/ i6 d// Add the BOM structure. 1 m) C% J: I' i0 m
Item bomItem = this.newItem("Part BOM","get");
. u" c' B" Q# h, b' @" ^bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ( x2 n- s6 b6 @% R
qryItem.addRelationship(bomItem);
5 {3 k# A1 ^% P! R7 A/ ?& Q
0 p8 s8 A* R( [* I$ }: g8 u+ ~// Perform the query. 1 K8 `2 ~  z3 v0 o$ t6 q
Item results = qryItem.apply(); ) s0 s5 V5 l+ v+ e) B7 K
, f% H9 u6 F) k& [6 r4 p- n# P
// Test for an error.
1 Y) S8 t/ t2 |: V5 K) Q( }if (results.isError()) {
. s" r# Y7 }5 P7 x. j" ^  return innovator.newError("Item not found: " + results.getErrorDetail());
; i, `) E' U* R2 d" u}
" r8 d4 L4 P/ X8 d9 u0 H  y
( L" A  {1 E, D6 L! ^// Get a handle to the BOM Items. 3 L1 E. D- s8 w0 D( @
Item bomItems = results.getRelationships(); + n' s$ ~+ K3 C' l- |: L/ k
int count = bomItems.getItemCount(); + r8 s0 C  f1 c2 f% Q
int i; & U/ k, v" y, L9 {) e. K

8 [& w' a  x$ Z) t: u1 w// Create the results content.
7 b: R8 z' j2 @& wstring content = "<table border='1'>" +
8 u: w* S, p. j3 t% o6 _8 B8 e- d% o  "<tr>" +
+ m( D3 T# y  y8 ?& U    "<td>Part Number</td>" + : V0 E7 Z$ M( p: X
    "<td>Description</td>" + 8 D" H' r) A0 Q; e! i; i* Q
    "<td>Cost</td>" + 3 s& H0 _/ Y2 {/ Y! x' e: Y
    "<td>Quantity</td>" +
+ S, z3 ]5 Q; i! ~. r  "</tr>"; ) J6 z% w  X2 [6 Z' L8 S5 _

* V8 f$ Q1 d% O& G// Iterate over the BOM Items. ( _: x. u" b& Y3 O1 m
for (i=0; i<count; ++i)
: I1 X, ]5 B7 t1 A0 U" s{
8 u& U/ m- S3 u* L) ?  Y7 ]8 h// Get a handle to the relationship Item by index. % e6 |. U! D# G8 w$ w% l
  Item bom = bomItems.getItemByIndex(i);
8 {5 ~& c* |5 _( m* g9 N6 J// Get a handle to the related Item for this relationship Item.
# g) Q+ [! {& F* ]2 h' U. y" ]( ~" h  Item bomPart = bom.getRelatedItem();
5 B0 P3 y% w0 F( ]; c
' y0 A1 T' q* B- H6 U( C  content += "" + / Y% x" N( U' z4 W2 h1 U
    "<tr>" +
4 s# m7 l% I/ H; Y7 X( b+ v" x: w      "<td>" + bomPart.getProperty("item_number") + "</td>" +
$ z, h; h7 f  w! V6 k* N  ^# H1 a      "<td>" + bomPart.getProperty("description") + "</td>" + ) c3 z8 ]) n' H7 t
      "<td>" + bomPart.getProperty("cost") + "</td>" + ) I% b3 C: t. y' w, w7 w) F9 ]
      "<td>" + bom.getProperty("quantity") + "</td>" + 5 q% N; U0 O; ~
    "</tr>";
2 o8 \2 Q' Y: J. i3 Y$ K}
! l. I, [; L5 fcontent += "</table>"; / i8 {8 ]3 ]( `4 T  n' j

' ^' ?# v. b# v/ E. Hreturn innovator.newResult(content); 2 v% ?0 E+ ~5 n( l# ^- k
1 ~" g' [. I' I% ~; o
. w. A. j3 ^' r! U

4 a7 G* Y0 [5 n; U- q4 k

! {4 {9 V" z( h$ v; ]9 I9 S6 I$ T5 P; @# @$ w  u

( l! j* d( ~0 a6 D, \! _( {
  w6 ~9 S' `: G; l    Page 46
# {: e/ Q1 a/ k( p7 v/ O
& c/ A4 b4 |# [9 {! K% J, m. V/ t  RCopyright   2007
0 ~3 A7 H& g: |Aras Corporation.  
6 ]; K$ d7 A. w" xAll Rights Reserved.
9 y% g: k# r8 h  k  AVB.Net  
3 L9 @; n- ?7 s3 c; J* o( L! q1 QDim innovator As Innovator = Me.newInnovator()
4 ~) G8 a7 w% ]: T  O ( S9 `1 K. O3 D; `' t
' Set up the query Item. 1 ~$ c* ~+ Z- S$ C) r# _5 \8 h. a8 G1 O, c
Dim qryItem As Item = Me.newItem("Part","get") & A$ O  D0 \8 ~0 C
qryItem.setAttribute("select","item_number,description,cost")
  w1 u  K" N: gqryItem.setID(myId)
) N! Q/ a  h2 @0 i# T6 P! O! Q9 @5 ^
! b. L4 h( p/ Z9 U" I& X' Add the BOM structure.
% @* C7 o4 Z9 _1 R, G* iDim bomItem As Item = Me.newItem("Part BOM","get") 7 \- ^% b% J) W+ }$ h6 @+ y
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
# Q/ ^. i& o: |qryItem.addRelationship(bomItem)
& L# i3 J5 T$ g2 T: k" X8 H& E
4 f5 i& ^  p8 @0 O% }* {, P" s' Perform the query.
3 O. Z4 R7 g" l! V. yDim results As Item = qryItem.apply()
+ r% x* J% o" ~
/ r$ z5 e# F7 |5 z8 J# s- J# ^. W) ^' Test for an error.   c9 q7 U$ S1 r- p: U# U$ r: W2 `
If results.isError() Then
+ y6 }3 q9 V. b  S& D% k: ?  Return innovator.newError(results.getErrorDetail())
2 i5 T% ^1 L4 M. s) J. P, S. FEnd If
5 Z1 i  E+ `/ h5 ?5 i& E3 U& l$ [ # q. Y! e6 @5 Z
' Get a handle to the BOM Items. # }- t6 {, W( r
Dim bomItems As Item = results.getRelationships() + `9 r9 c+ r. V# W/ C9 i. Q0 ~  n
Dim count As Integer = bomItems.getItemCount()
" o5 a8 R. s; M/ y  o( A6 |: ADim i As Integer
" m* N* v& l" ?9 W
; Z! g8 Q# |# d. n' Create the results content. 9 S5 V4 G3 C, _. N( O" ]  ?
Dim content As String = "<table border='1'>" + _
/ _% B9 Z4 O# Z5 C% Y  "<tr>" + _ : c5 H7 B6 s: U
    "<td>Part Number</td>" + _ 0 ~: w+ i$ X) w+ A) ~0 P; D" d- v
    "<td>Description</td>" + _ 8 t) P4 F7 a* K/ h9 _) }
    "<td>Cost</td>" + _ # l6 K, }5 S3 Z( Y7 ~
    "<td>Quantity</td>" + _
$ o# {' H0 J2 L4 B1 y# }  "</tr>"
9 m* i4 p% N  L$ j$ s% v% W
  W! g' n! I- j1 j- K* ~8 |' Iterate over the BOM Items
4 g- o# E0 {$ L+ }! DFor i = 0 To count - 1
" T" U; O: v) z( [5 Z0 u' Get a handle to the relationship Item by index.
0 I: N( [1 `* t* ^/ a2 v  Dim bom As Item = bomItems.getItemByIndex(i) 8 k; m$ I1 w( U9 J. Q- e

/ _0 k2 G: F) @4 E4 \6 X' Get a handle to the related Item for this relationship Item. # ]' v  S5 W: q5 G* g+ G
  Dim bomPart As Item = bom.getRelatedItem()
5 e1 D. ?  |4 ^( \/ u$ ]& l
+ s/ O* A8 n  a: Y0 h+ ~2 Y  content += _ 4 x  B7 r. u# @+ u9 T& n
    "<tr>" + _ 6 V+ \7 K; o4 }2 ~' v" `
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ ~8 I4 T3 k3 l- c2 _  J$ r1 L
      "<td>" + bomPart.getProperty("description") + "</td>" + _
$ a  c* C0 T+ W& N" Y      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 1 ~$ Q/ \0 D7 K2 e8 c# e
      "<td>" + bom.getProperty("quantity") + "</td>" + _
7 ^: e( C% M, N5 P5 G    "</tr>" . y# F: x% u0 l: [. a" ?2 m8 F
Next $ A' v( V8 W" P$ f" I; ~  I
content += "</table>"
! z/ Z# r2 u7 f- B 0 O# y' m4 v4 S* [, p, ]5 @
Return innovator.newResult(content)
/ M4 p. x& [/ o$ e: F
  a! a& U# u$ g
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了