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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  7 d% }5 c  M& e% ~6 x0 g+ K, r
To query for an Item and retrieve its structure you build the query as the structure
* o) z4 y  F. Ayou want returned.  Use the IOM methods to add the relationships you want and
( i) K- |" M/ \" Xbuild the structure in the Item.  The server will return the structure that follows the - R' c: X3 p+ z( ^
request structure. 6 q. q' i$ t1 B2 e, r  g
This recipe illustrates several related concepts together, which are how to get a set # r& l* m- }0 l4 D3 G# M5 r' _4 I
of Items from an Item and how to iterate over the set, plus how to get the related
( b+ f+ B5 V# L0 D0 GItem from the relationship Item. 1 N3 E# Q/ h# `, d) h; d4 T, |' M
JavaScript  ! r5 C# H( T; G5 M! {" u! m
var innovator = this.newInnovator();
: V1 r& `" n% ~4 C" J3 a( m
' L6 G$ S  P- \0 k' e/ E// Set up the query Item.
3 N4 ?* H4 b' s; q6 jvar qryItem = this.newItem("Part","get");
8 T" V9 }  H+ ]4 MqryItem.setAttribute("select","item_number,description,cost"); * g/ O: e( l$ o7 l, c
qryItem.setID(myId);
$ q- m# Y* U7 y( x7 F$ A
# ~4 P2 V2 T+ F9 m// Add the BOM structure. 1 F! A( _8 }" Z9 o- j' F
var bomItem = this.newItem("Part BOM","get"); - d4 s, m5 j# h$ R
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
6 a+ D3 y; Z% D1 f% u) Z) Y% ]0 LqryItem.addRelationship(bomItem); 8 Z3 \/ k+ h9 x$ J! W5 h5 f
/ j7 F; z( K7 t3 S% o4 ?$ l
// Perform the query.
; H' _: r& S* avar results = qryItem.apply(); 6 t6 j9 G, D/ \" l5 p) D

( I$ L. e8 y, N1 ~5 Z. B// Test for an error. ) F( U* K3 `6 D& ~& M, O6 u: x
if (results.isError()) { + |1 p+ o. }! @$ s+ M* c
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 0 E) ^! V  ]6 G" R2 U1 [% |
  return; * S( B2 }$ h6 l- c
}
6 W% l7 u1 r. M
' R) U  g% r. ~) ]( B# x// Get a handle to the BOM Items. 1 O2 t: q/ t+ B
var bomItems = results.getRelationships();
& T( o: U3 G, o# c& j( gvar count = bomItems.getItemCount(); . Q5 R1 M- s$ q8 f
$ C% I/ g2 h. L6 O) }  I
// Create the results content. 2 ]) ]8 Y8 f% j+ ?% J3 T. }
var content = "<table border='1'>" + ' O6 t- V/ H% z* U# S: e5 ?
  "<tr>" + ' w% Z2 ]7 L+ `0 i$ [6 N# X
    "<td>Part Number</td>" + / c$ M% K, \7 ~3 ~
    "<td>Description</td>" +   l6 Y6 h7 R1 ~- A3 |, x6 S5 b2 ~
    "<td>Cost</td>" +
/ w- v% H- D) B4 Y& i    "<td>Quantity</td>" + 3 _" N, w0 D( _% ~9 A; ~: Q2 {! R
  "</tr>"; ) }0 J4 l8 l' m' ~; |
6 L( B; s0 V9 Z
// Iterate over the BOM Items. . I1 j9 \4 B7 |' Z$ d3 c
for (var i=0; i<count; ++i)
: f3 x, D; m' K% s8 g2 _' c/ c{
* a4 h1 ]* x& ^3 Z0 a// Get a handle to the relationship Item by index.
% v( e/ T' {8 k  var bom = bomItems.getItemByIndex(i); " B2 a! n4 ]. d4 a3 z& U6 a; F# B
// Get a handle to the related Item for this relationship Item.   s* e4 T& C  @
  var bomPart = bom.getRelatedItem();
7 V6 B4 c/ i- u4 u, p- w; K
* [. j# a: v4 W( V  content += "<tr>" + / D6 k% h2 `' z* ?. |1 c
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
) d: x7 h1 _3 X/ V2 N% J      "<td>" + bomPart.getProperty("description") + "</td>" +
% i3 ~" c3 G: Q9 b. K1 X/ z, M      "<td>" + bomPart.getProperty("cost") + "</td>" + / w$ h% H. B' f
      "<td>" + bom.getProperty("quantity") + "</td>" + / i" q% C. T, m& G: s) A0 W1 X
    "</tr>"; , K/ `/ U6 @6 P' c) _
} 8 r1 y, d2 q, w; x- F2 m
return content + "</table>";
' s' p4 t5 D8 E/ l3 J( Y( a! Z1 h9 x/ P/ x, d' f) q4 V$ U
$ F2 [  q, W0 |  k9 `+ D, Y6 U
# e# e" ]* U0 E; x' Y3 Y

- h6 G7 l9 \! e* v+ {$ M: d$ f/ rC#  
1 s! `# b5 F/ s, p; @  `Innovator innovator = this.newInnovator();
; c# y! Z. }* W4 v' O: R7 H
4 |+ F0 @, q0 f) u( u7 w; V9 p// Set up the query Item.
& s, p; W% s$ @1 C" b- ZItem qryItem = this.newItem("Part","get"); ( q6 S, @- q' ]
qryItem.setAttribute("select","item_number,description,cost");
3 P5 E# P) V4 K3 \* R: iqryItem.setID(myId);
/ q  b2 S4 ^5 c
( x, p% ?: a- |// Add the BOM structure. - K/ Y* Q7 D9 w5 e- D; |
Item bomItem = this.newItem("Part BOM","get"); $ E% S$ s6 G8 }1 b) a7 v
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
" F. e9 z. R, q7 B9 M' l, N+ oqryItem.addRelationship(bomItem); , p1 N+ A0 z: v, p9 W" E$ c1 Z$ p
) m+ k. R& d% ?( G
// Perform the query. . @, m& w; s$ f+ `8 L1 F& x
Item results = qryItem.apply();
9 z* I, i- m7 I
9 b& k' E1 P/ _+ [1 w  A# l& ~// Test for an error.
: z2 @+ g7 y& z) T) p2 Q0 W. dif (results.isError()) { ( D0 h" \$ V( j
  return innovator.newError("Item not found: " + results.getErrorDetail());
$ g' B2 M& ~8 u+ `" ~! q# b}
. _, J, j8 \. D+ |1 F" ^0 X
& Y' m- D3 u+ P! U6 y$ U+ S- V* c- F2 ]// Get a handle to the BOM Items.
$ E% y9 P3 u/ s$ K- s' U5 CItem bomItems = results.getRelationships(); 0 y. w6 d' N* K& a; I3 X
int count = bomItems.getItemCount();
1 F  \) x& J5 [% gint i;
2 T% S( Y8 W+ d & g, ?$ n3 G: n6 F0 O- L$ Q" J. C
// Create the results content. ; x( ~5 K) o) l7 w
string content = "<table border='1'>" + - T6 j2 {. T% o
  "<tr>" + 6 E/ Q; M1 Y! c$ X& C: b7 t2 `, S
    "<td>Part Number</td>" +
2 K& F: Z, {# }* N    "<td>Description</td>" + 8 A( G% h: e7 q! G) @
    "<td>Cost</td>" +
- R- ?+ \/ X. p/ t7 p3 t. B    "<td>Quantity</td>" + ! Y) `7 z' K2 S' g
  "</tr>"; $ g) w3 K/ A3 k, C- {1 W( b

$ \1 R( j0 W# i3 ?# P- T3 V" a// Iterate over the BOM Items. 9 ^0 W: B3 p! d0 |) g; e! i
for (i=0; i<count; ++i)
6 h; f: H/ e% }6 m& E+ N( Z8 i{ , b1 Z5 z4 M$ f4 s: n
// Get a handle to the relationship Item by index. 1 y" B- `9 D0 Q/ B
  Item bom = bomItems.getItemByIndex(i);
. ^0 |0 O/ E: L) @3 D// Get a handle to the related Item for this relationship Item.
0 r# g9 ~: p8 c* |  Item bomPart = bom.getRelatedItem(); / t$ e% |, `; E+ I$ I
( {, ~4 `; z9 P- j/ K
  content += "" + * L6 b9 k3 \. ~& @' F
    "<tr>" + . R: n. Z3 Q/ {$ w
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
8 u) D! j+ e! x: S- X* l* A/ v, i: I      "<td>" + bomPart.getProperty("description") + "</td>" + $ b( W/ A8 c$ p1 K
      "<td>" + bomPart.getProperty("cost") + "</td>" + ' |/ A7 {3 @$ g
      "<td>" + bom.getProperty("quantity") + "</td>" + + j2 b$ ~) a. p* O
    "</tr>"; $ i& Z! |; [0 t) B2 E; A, [# |
} 7 N- q0 D" c  D) W6 a
content += "</table>"; # @" B* e; R0 ~' J

- i* R- r: b) A- l! V* h8 Ureturn innovator.newResult(content); 9 j+ f; `6 Q% y1 Z7 p' R* |
) w, Q7 c) \8 @+ V! g1 T8 G

; c7 r0 ]; c+ t/ T4 |# z# W
3 e0 {6 m6 B0 f% D* B! n
# A7 i4 X/ W0 a: o

$ L9 \/ s* y) W$ b0 J, K

/ J# m! \2 t3 u. P6 [  Z
  w5 F0 V8 [, f    Page 46 # J& @+ o  z+ A+ c
2 O" G9 l6 L! ]4 g# {9 d! m! W
Copyright   2007 % \; @% g; p5 g7 z2 r" C" G) c( M
Aras Corporation.  
  X# F4 ^/ u/ F3 ~' _8 {All Rights Reserved. $ N" D0 o; r( n, u! ^
VB.Net  
3 t, t, q6 u* A5 Q! B8 pDim innovator As Innovator = Me.newInnovator() - n" \" j6 Q0 G" z( H
2 g) ]: O/ w+ t  O  W( x: R: u# Q
' Set up the query Item. 5 U; h# t: D; B6 F$ f, l; q4 z* k
Dim qryItem As Item = Me.newItem("Part","get")
6 ^' w3 U5 l5 n: A- _. XqryItem.setAttribute("select","item_number,description,cost")
. Q; Z' a$ E' ^* t. T% dqryItem.setID(myId) / j( H. m8 c( I8 }- z% |4 r
! f* W+ W+ P6 |' e- j
' Add the BOM structure. 7 _/ r8 O! |$ V' \" ]' Z% R* C' j
Dim bomItem As Item = Me.newItem("Part BOM","get") 2 i. v  v, W5 x2 M( @# |; A% V
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
# l% u6 G8 v% ^9 h& o  z2 v) cqryItem.addRelationship(bomItem) $ @% m. k% l) }7 y% v- N

* c& U* d2 f8 \# c8 L' Perform the query.
" [: x$ {6 m4 H3 ], s% FDim results As Item = qryItem.apply()
2 w! r: ~# r# G; g6 i3 n, w; F) L( r % h" p% W/ D$ B1 R; B) S' A- L
' Test for an error.
; D9 a7 d0 ~1 H# L8 N. D  cIf results.isError() Then
% M; ^+ F* p# S- `3 D, j* {$ b  Return innovator.newError(results.getErrorDetail()) - m6 E; R6 p3 S( \/ H
End If
) X" F( p2 i% @- W- u- a 1 A/ J! z1 ~4 f+ z
' Get a handle to the BOM Items.
0 n! K3 y; r# ]8 EDim bomItems As Item = results.getRelationships() 5 v/ z& ]$ w1 @9 {6 g2 G3 @- e# y
Dim count As Integer = bomItems.getItemCount() % ]4 V6 j. Z2 P3 z$ j/ V7 _
Dim i As Integer ) }; w( H) B. ^% L7 F
( J3 D! o8 A8 a: v( x( X
' Create the results content.
, H1 L5 V$ v; \) H/ I; a9 GDim content As String = "<table border='1'>" + _ . R  M% C! [0 x0 F
  "<tr>" + _
* N* T% w- B# ~  v2 y    "<td>Part Number</td>" + _ 7 p& b$ G4 \& Z0 G( m- ]9 ~! R5 \8 h
    "<td>Description</td>" + _ 0 ~" N9 P% v9 o
    "<td>Cost</td>" + _ % Q  h% N+ A2 @9 n7 @
    "<td>Quantity</td>" + _
# G0 }3 u; Z/ |6 ^# L7 K9 F# B  "</tr>" ) j* ?4 r+ |2 k" Y3 L
* _( Y/ @! Q) d8 [) Z' A
' Iterate over the BOM Items 1 k+ u' [8 v; @  A, y. ~
For i = 0 To count - 1
- S# N; a* w8 O' Get a handle to the relationship Item by index. , m! ?+ e0 `7 O! E* N' C* }8 I
  Dim bom As Item = bomItems.getItemByIndex(i)
: @9 ^, f  V" d* L + S/ i4 }+ F! C, t& V
' Get a handle to the related Item for this relationship Item. : e" o1 g2 P# p) ~2 L
  Dim bomPart As Item = bom.getRelatedItem() # V2 g) b/ Z3 H& D4 V9 f& k
. x7 h$ D4 f* p  q+ O* h5 P7 t
  content += _
& r% i% d/ l8 `. r5 ~    "<tr>" + _ " L. j% Z8 j, \* l
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ; D! w+ k1 K4 p/ ?5 F
      "<td>" + bomPart.getProperty("description") + "</td>" + _ 8 W' P; {# L7 M* b0 d
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
- l, c4 \/ r; a% C      "<td>" + bom.getProperty("quantity") + "</td>" + _ 6 l$ M/ X( d& i$ d2 P# U2 z
    "</tr>"
$ i0 U1 g, v: L: S" h4 u  G- UNext $ G7 W* Z. {- k8 x
content += "</table>"
6 R* y/ u* u% @6 M ! K$ \  s' ]) C" F& A. H4 E
Return innovator.newResult(content) ' d  Q0 T. g6 R9 n

( F) x% B# C# {9 \+ L# d0 i
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了