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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
: B1 Q; P- J) ?  _+ k: lTo query for an Item and retrieve its structure you build the query as the structure 6 r7 \/ h4 Z2 `- m: j( i1 ~
you want returned.  Use the IOM methods to add the relationships you want and 2 N3 \7 r, c. @+ v
build the structure in the Item.  The server will return the structure that follows the % f% u" K4 k/ o
request structure. : g5 q& D6 a9 u0 @
This recipe illustrates several related concepts together, which are how to get a set 4 d8 Q: @: f1 X* S7 I8 S
of Items from an Item and how to iterate over the set, plus how to get the related # t# w0 s5 E* c' {
Item from the relationship Item. 2 y' k  C% d  k( A
JavaScript  
3 j. v8 w4 s+ ovar innovator = this.newInnovator();
) ]/ ]( o" o) x6 |* x4 P
. B7 M' X; g4 D! q: I# i// Set up the query Item.
3 d( m/ i% j! d1 pvar qryItem = this.newItem("Part","get"); ; q0 r/ s, ]7 f0 X3 q5 ?: J
qryItem.setAttribute("select","item_number,description,cost");
) Z3 G0 U0 `0 A6 N. E, v4 \, nqryItem.setID(myId); 2 \1 Q0 s% e- @" X: F

! A( x3 m: }5 V4 C// Add the BOM structure.
) a6 ~) E# ^1 g: r: Hvar bomItem = this.newItem("Part BOM","get");
$ M5 R5 c) f5 o! [bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 6 c8 ~; l' V& @: v* X
qryItem.addRelationship(bomItem);
' n8 O8 U) j* P1 x) O  |6 A
) R- ]* q( v5 ?: C" y6 i// Perform the query. * g) i0 V2 B' ?
var results = qryItem.apply();
" H4 `% a# j' Q6 K* g 4 ~' W& i7 [2 C. }3 |6 X% A& s
// Test for an error. + s6 {6 x" _; C* ]: r/ `9 b/ V
if (results.isError()) { % k5 k5 q( }% k! M+ F$ ^# j
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
- ~# O. T- [9 x' ^, V) x  return;
+ D( Y+ c; q  e3 G' H/ I} # o6 R) o, C, r" a- k2 r

3 d0 H% b* D& S  l! V// Get a handle to the BOM Items. ! h1 M$ c% e1 t! h( Z  @! b
var bomItems = results.getRelationships();
, E8 o7 o/ H6 A3 hvar count = bomItems.getItemCount(); $ w. }8 ^: ]" t$ f2 `. q! T( j

+ n1 A; F( @+ Q// Create the results content. 6 t: J8 v0 M* c6 T( |; r- M  P" v
var content = "<table border='1'>" + 2 e2 V3 t' i& p2 R" j, V
  "<tr>" +
0 T6 c8 P; l0 O; B9 \    "<td>Part Number</td>" +   I4 d, U* _4 U) `: s
    "<td>Description</td>" + - z/ k3 a* R1 p: f& \
    "<td>Cost</td>" + 1 J+ E0 x" ]  z% D8 Q
    "<td>Quantity</td>" + $ T; E; V: L$ M- W5 a1 E; K
  "</tr>";
& ?: D8 d/ [0 j* a+ D
2 _6 ~& b4 V9 `6 T5 ]9 p// Iterate over the BOM Items. ' O8 Q0 [! w6 b* V: _) N
for (var i=0; i<count; ++i) $ e, _1 _9 k# ~7 j6 C% n8 \
{
" n* v; C! o: ^2 a4 N" h' T# m// Get a handle to the relationship Item by index. 6 S( A1 t- j3 `8 L) l7 P# |( i
  var bom = bomItems.getItemByIndex(i); 3 m4 J# ~( J7 V
// Get a handle to the related Item for this relationship Item. % i' s5 }( D; G( o8 f* l- l
  var bomPart = bom.getRelatedItem(); & d; s( J, P+ O. a8 a$ [( f" x0 Z

/ |- q8 e5 e' t" S  content += "<tr>" +
1 D7 r2 G7 T% ], ?: S% v      "<td>" + bomPart.getProperty("item_number") + "</td>" + * A. r7 s) M/ x9 M9 e
      "<td>" + bomPart.getProperty("description") + "</td>" + ) ^+ X. |. w! E' }% ~
      "<td>" + bomPart.getProperty("cost") + "</td>" +
. J  R. e* j; K' g9 k/ }      "<td>" + bom.getProperty("quantity") + "</td>" +
6 _4 K, B: {. m: A& ^    "</tr>"; & Z% |( ~! r* {* U( r
}
+ N, |5 y/ A) C( r% ~5 ]) Yreturn content + "</table>";
- _/ m5 C- O$ L2 ~! ~- O+ j' B* n* k/ C

" Y4 n# H% c/ K# a! d) D" \
0 M# k0 s, \, J* g9 {
. a; T- _' c* y: U
C#  1 \. G+ W: J. z
Innovator innovator = this.newInnovator();
$ w$ I$ l- |. _, j 3 f8 {2 r  R1 I5 A, H: |6 z
// Set up the query Item.
* ?0 j6 U8 s6 G" v5 ]2 gItem qryItem = this.newItem("Part","get"); + e4 f, C8 K" m) X' w+ {* L# f9 F1 I
qryItem.setAttribute("select","item_number,description,cost"); # c0 @' q9 _' s: l+ y8 I
qryItem.setID(myId); " G& O9 ~- F# R
- F* ^5 n8 U# v2 A' |/ }
// Add the BOM structure.
8 B9 b. ]; E" j% o7 sItem bomItem = this.newItem("Part BOM","get"); 3 D* ^6 V# f, ~- ^; p) h
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
, S2 Z) T4 C2 \9 x' uqryItem.addRelationship(bomItem); * `4 }/ q- V' Q) W! F

3 E) k# Y3 }3 s0 z: v- }" ]$ n// Perform the query.
5 Q0 F' M1 f# ^8 M; s3 H/ A6 GItem results = qryItem.apply(); * A( D+ T- r& V! I, R7 Z- i

* b: J7 S# G8 x9 z8 r4 p// Test for an error.
8 r' }! l( w/ oif (results.isError()) { ( w3 t: e2 I" ^+ l( t) C" Z( u; u# B
  return innovator.newError("Item not found: " + results.getErrorDetail()); $ o) A3 q" q6 r$ i
} * h* I! l+ K7 k; _  X# X

8 L+ v7 e, E  Z* K7 m: I% f// Get a handle to the BOM Items. ' F6 [+ f, |1 e
Item bomItems = results.getRelationships(); ; K% }  z3 b. `  b5 e1 y
int count = bomItems.getItemCount(); 0 a. H3 y2 e9 @& v6 N8 F
int i; / X% r8 Z5 v9 t- z! F6 C
1 M+ K( w, d. H6 \
// Create the results content.
6 F0 G4 f0 W7 Y  J' xstring content = "<table border='1'>" +
* u. ]; W+ v9 _# z: H/ S: I" b  "<tr>" +
) ]+ B3 T  {. @7 H    "<td>Part Number</td>" +
! l7 C3 ?. Y6 |. ~0 w. G7 Z    "<td>Description</td>" + . ~7 x3 J1 e- N: O% P
    "<td>Cost</td>" +
4 p( n8 S" x, o" t# V6 d( k4 V    "<td>Quantity</td>" + 3 G, C7 u+ z' m( T* r
  "</tr>"; 0 i; _* b' [0 v, m1 q5 L

$ J/ b& w! H& z$ j; q2 l: A// Iterate over the BOM Items.
4 P! N0 T; K4 L9 G1 p; j0 }for (i=0; i<count; ++i) 2 }& `  F  s# L! b
{
5 W* D" J7 f+ ^/ a9 J3 Q9 ^+ n2 @// Get a handle to the relationship Item by index.
5 @# Z. a" i( C5 V4 j1 y5 Z  Item bom = bomItems.getItemByIndex(i);
. o4 d$ w3 R+ W7 N1 C// Get a handle to the related Item for this relationship Item. ; |. R2 o$ o3 U6 @, O1 m4 o
  Item bomPart = bom.getRelatedItem(); 2 f$ l- ?: Q3 x6 K: n4 o9 s

% Z6 c! q4 J1 h% N4 c  content += "" + 5 z2 V: G8 U3 M! Y6 @4 \3 R' A' x
    "<tr>" +
! w; D: N* b6 W, g2 e      "<td>" + bomPart.getProperty("item_number") + "</td>" +
& r3 Q6 Y/ L9 }! l; ]: ]      "<td>" + bomPart.getProperty("description") + "</td>" +
4 g: r0 r' m! m      "<td>" + bomPart.getProperty("cost") + "</td>" +
$ a; z# z, ]3 f: k      "<td>" + bom.getProperty("quantity") + "</td>" +
" A+ @; ~# |/ _) ?/ \9 f7 s( f4 y    "</tr>";
# ?6 S3 q- m6 A; g5 m' Q& p3 K8 w}
* j5 D/ p% }0 C. T( pcontent += "</table>";
0 r& w( i) j: J  `1 \! y3 Q8 Y
$ _# X  E8 ]5 n' L# yreturn innovator.newResult(content);   C. W6 \9 x5 M, \

  F6 S8 t6 a6 E4 Z1 d& h% n1 x" C; r: A

( `* K9 C$ H& [0 n) @  R
8 U$ I5 w1 P9 Z, m$ [
8 c' w" l( x. [5 F# V# m

9 }! l4 {# K  y7 V
5 O9 R! j& `* D

0 h+ q$ T$ i( ~# q* }* J0 ^    Page 46
3 m9 W8 w8 j$ N8 w
- k  t8 K7 a+ s7 h0 @Copyright   2007 4 K6 h  E$ E" Y) N6 z8 r
Aras Corporation.  
3 z) k( [9 a& U4 m" ^All Rights Reserved.
% A5 j6 T  r" s. y: f6 j, \5 F- EVB.Net  $ L7 X3 s1 D% K: k$ X3 J
Dim innovator As Innovator = Me.newInnovator()   q  X& N+ c2 |" F8 b

. q0 m1 d6 y+ o2 T9 s' Set up the query Item. 2 y* c- d$ C6 n$ }) o9 h! \
Dim qryItem As Item = Me.newItem("Part","get")
4 p0 z) x& c2 j0 H; v# L2 G+ z6 }qryItem.setAttribute("select","item_number,description,cost") ( V% x. s8 s" }7 r# \
qryItem.setID(myId) / a( w# K+ U0 k& a8 ]

0 ^( r8 y$ u3 g7 h1 j+ i! ]' Add the BOM structure. " ~+ D2 g) b( L9 }0 f; P/ t
Dim bomItem As Item = Me.newItem("Part BOM","get")
0 F: k2 u( c% x& ?$ b0 \bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 1 E) K8 c* K: E4 W5 k
qryItem.addRelationship(bomItem) 8 N& O; }: H0 e, g; x
6 ^* ~; i9 x/ o
' Perform the query.
. j" X/ i2 b2 n1 v* [+ D# ~0 V* oDim results As Item = qryItem.apply()
6 k: B5 K3 k- t& y0 d8 z # ?! ?1 d/ A, }% t2 _) ?" S
' Test for an error.
; i6 W6 |4 F6 c( A' bIf results.isError() Then
" T1 C, X1 _/ r$ J1 M  Return innovator.newError(results.getErrorDetail()) & ]9 v* x2 m& J" ]% p$ z
End If
) {( r+ j/ I( V, U: i
2 w3 t: `( ~0 ]$ k4 {. H2 s' Get a handle to the BOM Items. & d7 m: a3 ~' E) O0 n% _; g& J
Dim bomItems As Item = results.getRelationships()
+ K5 m7 j' t/ {) yDim count As Integer = bomItems.getItemCount()
+ h! h9 g0 \4 Z( O* I! R- \Dim i As Integer
& p7 T( b& S5 }: ?* I
4 y+ _( n) @7 b$ A% L' Create the results content. ) x; U  k0 M0 e
Dim content As String = "<table border='1'>" + _
( k# W. }9 c' `  "<tr>" + _
+ Y3 M9 T/ H. o6 G. u    "<td>Part Number</td>" + _ ' t2 D. }. k# ?, k4 v
    "<td>Description</td>" + _ / b; j/ p1 E6 W$ h
    "<td>Cost</td>" + _
, d& M! d% a& l% q0 d, ]# x    "<td>Quantity</td>" + _ + Y$ b2 C0 K$ I5 \& `( }
  "</tr>" ! L+ u% X% E" D+ E' \9 A

* J* y( c* ?) ^9 }) `5 w5 b' Iterate over the BOM Items
8 N' O& y# @+ K, ?0 L/ FFor i = 0 To count - 1
6 V$ `  j2 I. Y6 h; O1 H4 m' Get a handle to the relationship Item by index.
$ S9 c$ G; t5 {) n% |; _  Dim bom As Item = bomItems.getItemByIndex(i)
: E! [- k( i7 N" Y
! @" `: j! D$ ^9 \9 p! D- U' Get a handle to the related Item for this relationship Item.
8 ?1 s5 I; R# }* D4 h/ ?& r' B" a1 w  Dim bomPart As Item = bom.getRelatedItem() 8 A9 v1 i: P8 l9 D' k% D
6 V; K, n! d; A5 S$ _
  content += _
1 ?7 j& K( M+ Z& O" t( B% Z    "<tr>" + _ 7 E" W" q8 [* X$ k8 \6 l8 p+ q3 n
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
, F: z. ^: R/ e" Q1 p      "<td>" + bomPart.getProperty("description") + "</td>" + _ 3 ?# X+ W. c+ H2 d$ M
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ ' X: v$ z7 |, [+ H  J
      "<td>" + bom.getProperty("quantity") + "</td>" + _ 4 c. w- n0 v  v: J( J. v
    "</tr>" 8 R. J2 f/ ?) i; V8 t
Next
$ [4 P* l& b  K5 Q4 G# H2 F+ Y1 |content += "</table>" 0 a! J, i" Z/ X
7 b7 @/ ^7 Q: f1 i; h
Return innovator.newResult(content)
+ f6 X. ~& e5 \( m. k+ ]
" f( ~: Q0 e: b, A
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了