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

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

[复制链接]

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

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

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

x
Technique  5 n( R0 b3 o( L, d" m- @
To query for an Item and retrieve its structure you build the query as the structure
, i1 T/ i; E) Q0 }you want returned.  Use the IOM methods to add the relationships you want and + |1 O3 i4 W$ A: u/ t) S1 s( I+ o/ U3 ~
build the structure in the Item.  The server will return the structure that follows the 5 i9 b7 C* t/ p6 W2 a
request structure.
9 ^; q6 ~& o- A. z+ p0 M. Z# ~This recipe illustrates several related concepts together, which are how to get a set
* v, j; }& U6 X! P, \! vof Items from an Item and how to iterate over the set, plus how to get the related 8 R0 f& f, Y8 ^. T* V  P
Item from the relationship Item. ) w6 O+ U  j( Q( [, f: I
JavaScript  
7 h+ v& B1 Q+ i- L4 k* Ivar innovator = this.newInnovator(); + @: t; Z, R9 ^2 e) Y; V

: ~2 s! |) L: p; k; u// Set up the query Item. $ ]3 o4 Q; ?( ~+ a3 B& S8 U
var qryItem = this.newItem("Part","get"); 2 c- j- S% p% k( p. I
qryItem.setAttribute("select","item_number,description,cost"); ! c/ R3 a; ~- ~3 x# p
qryItem.setID(myId); % x3 O2 |4 Z8 u( n% N9 }
( s/ f; y7 Q) G& S
// Add the BOM structure.
8 H, ~- h$ h$ G+ `) Y* l) @var bomItem = this.newItem("Part BOM","get");
" j# h7 _+ }- \; w) n& d/ q  KbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
5 f0 Y% \- n% q9 w+ L7 k. ^qryItem.addRelationship(bomItem); 2 t1 b* w6 n$ V
7 r" A- v8 B( O3 ~- _& i
// Perform the query.
0 s5 R' J& V6 @5 Xvar results = qryItem.apply();
: j& T3 E5 x! B8 c: ~6 B2 y$ W 4 y# C1 C) x- w$ L- M7 _
// Test for an error. + p, ^+ z0 ]( M
if (results.isError()) { 2 E( Z* s: |, V5 J$ L
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
$ M; E9 A+ E( a' Q* m2 h) g  return;
  \7 T# z- b6 j! R5 U}
: G0 {% O6 I; Q0 K# f : O2 I$ I& `1 m
// Get a handle to the BOM Items.
: c3 ?; }# g& _4 w5 Xvar bomItems = results.getRelationships(); ( f- r8 v- j: a4 s
var count = bomItems.getItemCount(); - G" v9 P8 Y1 M) v: K1 P6 g9 g. s

7 l3 h# H' ?# ~( n0 H9 @// Create the results content. 5 f3 ~) m7 e) V
var content = "<table border='1'>" + / A4 T4 V% V3 k! m
  "<tr>" + . u( \, u4 o% F6 }8 T
    "<td>Part Number</td>" + - T$ L8 i" T8 L. ]: Q6 J9 m
    "<td>Description</td>" + 4 Z6 `0 G6 t9 g! G  \3 s
    "<td>Cost</td>" + / C; W; _( y) S( ^
    "<td>Quantity</td>" + 8 [" h! t# V7 l) ?  t+ A
  "</tr>";
8 ?7 J) W3 s  b+ e& {. n  Z
: D: E9 y: p3 G( m7 m// Iterate over the BOM Items. & ~8 S! G  G. o  e! D
for (var i=0; i<count; ++i)
6 m3 K) C4 I- k+ k. @, Z" v: y{
! v: p5 S1 ~. U" E& j- }// Get a handle to the relationship Item by index.
4 V! r) X2 X0 z  var bom = bomItems.getItemByIndex(i);
6 z* r2 l: |# T4 P' c) X// Get a handle to the related Item for this relationship Item. # X, ]) K; e* m- [) i8 y+ q  J
  var bomPart = bom.getRelatedItem(); / w" J9 P( S6 p4 F" B9 ^: G

: x5 g9 o2 ^( Z  content += "<tr>" + 7 L. `& q" @0 v) e; N3 H
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 5 K6 Z5 T9 r2 ~# @
      "<td>" + bomPart.getProperty("description") + "</td>" +
" F& ^- m! g) e) A; ]      "<td>" + bomPart.getProperty("cost") + "</td>" +
6 L' h$ I" G" ~4 ^: o  p8 T      "<td>" + bom.getProperty("quantity") + "</td>" +
- T# L1 m% Z5 R- _' \  f9 k) f5 H    "</tr>";
; \3 C  t. b8 c- W+ D8 H} 5 u4 k2 f+ J6 [1 S+ [
return content + "</table>";& m2 E: J! ?7 ?2 a- K( g' `+ d# @
( d, S4 v6 K6 l% f- ^/ ]

+ _8 W1 C' N; M2 \
8 Y* E. H: Q3 y3 M# T- e& o" O

) i3 {+ c# ^; S6 P& GC#  
$ s' I+ a1 T, t# g/ T, I7 x# sInnovator innovator = this.newInnovator(); ; X2 ^4 L+ o# b5 ^
3 x1 k+ x3 W$ r# p3 g; R
// Set up the query Item.
( q8 C) n% q% E5 e+ d% sItem qryItem = this.newItem("Part","get");
) Q# c  H/ k( Q* P) JqryItem.setAttribute("select","item_number,description,cost"); $ C, {4 y& r6 r; C  g# t  R0 {. c
qryItem.setID(myId);
+ r/ b- p- r6 j; m 8 l1 A# G/ M9 ?4 b1 T# k$ D
// Add the BOM structure.
5 I1 ~( P2 Q5 Z5 V+ S. Z+ D$ F% Q* UItem bomItem = this.newItem("Part BOM","get"); 8 Y* y2 A( }8 B0 \, J$ ^0 A
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); / @2 _: ^; h' F. Q7 x6 M7 Y! B
qryItem.addRelationship(bomItem); * D% h1 s- k# ?4 K

9 s3 u/ d3 j( i) ]$ F// Perform the query. * ]8 C0 m1 s6 s. s4 N
Item results = qryItem.apply(); 9 M: R$ `, k( K5 g5 n

! d- o3 g8 z& U% I$ m2 F  v// Test for an error. 7 k. U8 U) a: }! G
if (results.isError()) {
+ |! m3 ]; o& F' z; m( o: k  return innovator.newError("Item not found: " + results.getErrorDetail());
. Q5 K  r5 t: [/ J( q  Z} . a0 I$ y- S% v$ w( d
" k6 [; f  ?& C7 `8 ^, I) z9 I
// Get a handle to the BOM Items.
, ?/ E# |2 I3 _) c; q6 AItem bomItems = results.getRelationships();
. e/ b3 [. o( x* }$ Sint count = bomItems.getItemCount();
" O$ l3 q8 `& h- A: Gint i;
) N# a; C8 x9 {; {' ~& W + O- M7 `4 I# \! g/ U
// Create the results content. # z7 F) Y% P( b; {
string content = "<table border='1'>" + 5 o9 Q( i1 i. f5 N& V! w! V7 `" V& U
  "<tr>" +
# ?2 ~* {$ P  }7 Y! j: h5 \0 `5 ~    "<td>Part Number</td>" +
4 K- |/ B+ p( ~! a, J' J* i    "<td>Description</td>" +
/ B/ L7 I; U: B3 _. B$ Z! i, g    "<td>Cost</td>" + ; e9 M7 Y& E/ y% W& p: z2 h' ?
    "<td>Quantity</td>" +   [! ?1 m8 y. Z  e  t
  "</tr>";
$ \: g5 \6 |' d
) O& ?4 H4 U5 O// Iterate over the BOM Items. * I% p8 @: f8 z7 C1 r1 _
for (i=0; i<count; ++i) 1 v5 @" B3 U/ [" Q$ v
{
: }6 l- D- I9 ^// Get a handle to the relationship Item by index. & v5 k) i9 I' i' ?: ?6 U
  Item bom = bomItems.getItemByIndex(i); % y5 U0 C+ M8 N, A6 m) \, t5 t: `
// Get a handle to the related Item for this relationship Item. ( x2 Z# C9 q5 q/ F. h2 }
  Item bomPart = bom.getRelatedItem(); & Z4 N  ?5 Q5 E, @# Z

& C+ z5 V1 H: L" a  content += "" + # m# i4 Z% C) ^
    "<tr>" + 6 j: R% @7 f& r# o; P( S
      "<td>" + bomPart.getProperty("item_number") + "</td>" + # a7 n$ ^" V- [& l! b2 C/ ~
      "<td>" + bomPart.getProperty("description") + "</td>" + - J  L4 y/ \$ M7 P2 s3 M3 ]3 ?' D$ @
      "<td>" + bomPart.getProperty("cost") + "</td>" + 0 k/ G) u; f9 N, E* `
      "<td>" + bom.getProperty("quantity") + "</td>" + + p; n9 K: J( H  v; q2 C* G
    "</tr>"; : U" |6 J, \8 l/ E! H
}
% T1 h6 ^1 u) V, R8 ~% [content += "</table>"; . f8 `  R, f7 a6 Z! G
0 s  W5 R8 z* x$ }2 S2 \
return innovator.newResult(content);
+ O3 ], e" t( ~) p$ U, |: @+ v* u0 M
( k& P* I& M' g/ N
# g- f5 t$ h6 I' F: R
8 e  D9 e3 m; y! r) p2 m' _

" o, b/ n1 k' ~1 ~
7 U* t5 g3 `: Y1 a0 j& R" {* [7 u8 A$ o
/ @  y9 _- e0 g0 V$ {
+ k& [4 z/ k+ |. c
    Page 46
! N. z6 L7 w& c0 k8 Z+ s$ X + [3 j$ x" k  \
Copyright   2007 ) }# |) c; i' l' `1 ?
Aras Corporation.  
" h# r. X3 i+ kAll Rights Reserved. ! c: ]- u: w$ Q$ \# F0 S
VB.Net  ; A5 F5 E" Y, |2 X
Dim innovator As Innovator = Me.newInnovator()
5 ~4 A" Z2 S3 Q. E9 {/ ]1 J3 ? 9 y  ~& I$ S) P9 J" e9 U
' Set up the query Item.
$ _& Y9 m. n7 cDim qryItem As Item = Me.newItem("Part","get") # z9 R* B+ c8 B- V. t  Y! Q
qryItem.setAttribute("select","item_number,description,cost")
4 U" h$ p/ z8 O8 C1 ]qryItem.setID(myId)
! ?  V8 _9 h: m# {: S9 r( V
$ Y; X6 W  m5 o6 j' Add the BOM structure.
8 w4 b- o2 g" |7 @4 _Dim bomItem As Item = Me.newItem("Part BOM","get") 2 p/ e0 h3 f9 P/ }5 C5 s. L" _
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! ~$ E8 U. P7 c/ F# X+ rqryItem.addRelationship(bomItem) ) `% O5 {0 D5 N( n! `6 h- p4 n

, @8 s  N: ?; n. ?& ^( k' Perform the query.
$ I' _& n" R& ?+ [5 d" P/ sDim results As Item = qryItem.apply()   _. ?7 C, }! d9 L! ^  B

  s8 L- K0 f9 x+ H2 T+ |8 O' Test for an error.
9 i. w$ U8 P" ?* Y: `! VIf results.isError() Then
/ G& Q6 ~0 Y! U( ?6 N/ F' K" |  Return innovator.newError(results.getErrorDetail())
& C( Z, T* S" CEnd If 5 s$ {) g6 k# l. Y) ?& z9 Y: Y
& l! M& K) }" |0 @0 o6 ~
' Get a handle to the BOM Items. ! B# V8 t6 c+ f' z6 z1 a& ^
Dim bomItems As Item = results.getRelationships() . R; g7 z* ]$ a4 ~; @, ~% T
Dim count As Integer = bomItems.getItemCount()
% @+ }! M+ ]. I. I& Q) p3 c9 E( k4 nDim i As Integer # y4 k/ F5 F+ @0 R
/ Y! z. x# G6 k+ O6 ~5 n/ T
' Create the results content.
- n1 F0 [( U/ QDim content As String = "<table border='1'>" + _ $ F  Y" M3 z3 |' J, D/ A
  "<tr>" + _
/ A7 G9 ]2 O+ k0 @# ]" |6 P    "<td>Part Number</td>" + _
- j! D9 n0 \; G# N: i    "<td>Description</td>" + _
- ~3 m8 Y; z* |- n9 e5 b    "<td>Cost</td>" + _ * O! R4 N: m; l
    "<td>Quantity</td>" + _ + t" q# w# M. L# n3 Y- j
  "</tr>" ! u1 l' B3 M( g4 _: C' r/ M

# o6 [( A+ `1 E; n) @6 `' Iterate over the BOM Items
" v5 F  c! e+ [% x3 ?! z- {2 J+ lFor i = 0 To count - 1 " M+ b4 N4 Y; [: J5 v! y8 |
' Get a handle to the relationship Item by index. ; O: w: }% ~/ b7 B8 ?
  Dim bom As Item = bomItems.getItemByIndex(i)
5 Q! ?1 ~* n& d; P0 \+ q
; i/ r+ _; E$ C7 `8 f! i% X' Get a handle to the related Item for this relationship Item.
, q$ r8 c, \9 K  Dim bomPart As Item = bom.getRelatedItem()
2 _! H3 s: |  p' d# d
8 z* c# n1 U) ]$ p7 U' F0 Y  content += _
5 o5 L* H! q% U+ Y4 {" p    "<tr>" + _ . Y% k. i- K' [7 C+ `
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
0 M7 `  n( O' I/ m, o      "<td>" + bomPart.getProperty("description") + "</td>" + _ 9 @- S' y5 d9 T5 l# u- M
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 9 c7 Z& W( ~7 Y, i
      "<td>" + bom.getProperty("quantity") + "</td>" + _
2 ~) d1 ?& H- g* M& g    "</tr>" 7 X1 ^/ H; r. n2 f3 w3 w2 i9 ?
Next
0 a2 P* c+ f- H% S% zcontent += "</table>"   x$ s6 R$ R( A6 V
, k9 [* j9 Y0 ^. ?- K
Return innovator.newResult(content) 5 R( h8 \- C0 ?9 y* D; t) k
  t: W# B- v- V1 v& w+ f, e4 `: i4 v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了