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

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

[复制链接]

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

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

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

x
Technique  & ^0 K) y# _1 a% U9 P
To query for an Item and retrieve its structure you build the query as the structure & Z+ W( k4 m" E1 X% S4 R  q
you want returned.  Use the IOM methods to add the relationships you want and 9 M! `* \* ^  K4 Y  D' `% i$ g
build the structure in the Item.  The server will return the structure that follows the
5 n% [+ @7 D8 I0 {! }3 Urequest structure. " a/ o' }* ]- L( g4 K( ]
This recipe illustrates several related concepts together, which are how to get a set
3 H: Q& m7 R$ [7 }$ E: a$ ^. _of Items from an Item and how to iterate over the set, plus how to get the related
1 a4 q9 Y2 e3 xItem from the relationship Item.
. I5 C! b4 }9 K# b* d0 ?! M$ N: DJavaScript  6 O- T! q( I) U
var innovator = this.newInnovator();
# x3 V2 V/ q4 h  _4 M( @0 G7 M
2 ~% Y# B) J. q1 B' G  l5 u// Set up the query Item.
" a9 ]$ X7 `  L- g% U/ ivar qryItem = this.newItem("Part","get"); 7 r& a8 E+ X' [* n, K- r; l6 ?
qryItem.setAttribute("select","item_number,description,cost");
! @) }  g0 ^# v# U" \$ kqryItem.setID(myId);
5 U$ r# h: {' `( ~3 `$ q% q& P ; R. q( D1 v# W
// Add the BOM structure. 8 }$ }/ |  f, u9 J. w! [
var bomItem = this.newItem("Part BOM","get"); ( W. S; h" f- m# C3 g" X* ~3 x
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); : A" O" Z3 X9 H
qryItem.addRelationship(bomItem);
  a5 B2 s2 Z' u% ~
8 K8 N3 R. v( F: O2 `$ b// Perform the query.
# y7 W! f9 {# M* X" K+ j: l- zvar results = qryItem.apply(); 6 [3 a1 m3 M8 S' y" Z8 E

. X9 Q/ X% b: B8 ]) g1 \// Test for an error.
, B. k% S7 Y" Yif (results.isError()) { 3 ?* H2 u9 o  [* M9 G$ ^- ~
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
) L3 z. N" e0 x5 M  return;
' y, J, r3 \9 }}
. q. q( h$ u$ w5 H7 |8 ^ ) h1 M' n4 z( H+ x. T! b
// Get a handle to the BOM Items.
! ]  F1 J* J, tvar bomItems = results.getRelationships();
! E$ }2 L& @5 R) ^" A( W& R' pvar count = bomItems.getItemCount();
! H+ @! b* i; L) i. G3 y $ `6 N6 \) n! G" _' E8 f
// Create the results content.
7 q3 q7 B& P* g+ _8 `& G( Svar content = "<table border='1'>" +
: L2 _/ H7 N  N  "<tr>" +
( V; p3 M4 |6 D6 M6 x# x1 M4 t$ \) ?    "<td>Part Number</td>" +
9 R# H& B, `" f% I0 L2 h    "<td>Description</td>" +
5 f5 b6 y3 {/ I    "<td>Cost</td>" +
; S& m; B5 V* l5 E& b0 o1 l    "<td>Quantity</td>" + + p8 N7 R# I" c' k4 t
  "</tr>"; , b8 W7 v0 t- U7 |6 k. M

0 C" J- e4 }, l. G( I! d* U// Iterate over the BOM Items.
& N$ A! ]0 S! o% E0 `for (var i=0; i<count; ++i) 3 {7 N/ N5 p  C" V
{
! D+ w8 T- A  ]( H! \( a// Get a handle to the relationship Item by index. 0 w( W: j; e1 A, b0 W% w
  var bom = bomItems.getItemByIndex(i); , `, c) B9 i/ O- G# G- J: O. M  _
// Get a handle to the related Item for this relationship Item.
9 q1 Z3 B2 j- E8 d  var bomPart = bom.getRelatedItem(); ( |5 k0 J' |) f: i* ]  i0 Z+ l
" c9 m' |* D1 C, U8 P; U* r  Y
  content += "<tr>" + - y% W  H( R( N4 ~
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
6 C+ Z1 k' ~6 _: X) B      "<td>" + bomPart.getProperty("description") + "</td>" +   S9 d4 h% V9 l# h1 x
      "<td>" + bomPart.getProperty("cost") + "</td>" + & ?; g2 R0 k9 {1 x  J8 N/ G
      "<td>" + bom.getProperty("quantity") + "</td>" +
' P! K! c* Z! u; h( r0 S! y    "</tr>"; " U( F# p1 q0 p& F  R- {
} % j+ t+ H" p0 j: N7 E. \9 e
return content + "</table>";
& {& E* q7 V( B. @, ]1 J7 b( t5 `/ l/ @

% Q/ _* P7 c6 |' w6 |' w' D; q7 N& T8 t7 \/ O& `+ w

9 d' j/ q6 T. i5 xC#  * H3 k" U: Q* z
Innovator innovator = this.newInnovator();
* a# o6 A' i' r
6 `0 R0 P4 q4 R3 `/ N; s1 i/ Y// Set up the query Item.
  _$ H3 n2 T% L; E% n9 e5 p* KItem qryItem = this.newItem("Part","get");
; v4 N+ [* A$ G5 v" Z" f/ W: M& fqryItem.setAttribute("select","item_number,description,cost"); / D* x" u2 k$ n: O; }
qryItem.setID(myId); 8 v+ d$ T* {# D9 [9 G) ~; R3 k$ _8 n

2 `# Z& Z/ r3 r6 z8 F( k// Add the BOM structure. * S6 C& R1 v" C0 ?3 U
Item bomItem = this.newItem("Part BOM","get"); 3 p4 @% `% D# c( p6 U7 _% G/ T2 e
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); " J/ S* V* }/ y- P, S& l- K6 W
qryItem.addRelationship(bomItem);
: ^5 ]1 z! d) e1 J" |. y' o
% Q! Z8 V/ _3 L8 Q// Perform the query. / K' P6 b5 D. f& Y" i( P
Item results = qryItem.apply(); 5 w0 F$ o+ @" f7 K5 ~
5 U3 a/ s3 H4 f6 K
// Test for an error.
+ n. d( @2 m$ _$ lif (results.isError()) { - S" k8 |9 Y. t, }0 o+ @
  return innovator.newError("Item not found: " + results.getErrorDetail());
9 j  G! G9 E3 K' h}
* q0 C8 c5 Y& g' I$ k) U ( i) Q3 h3 u$ G  E
// Get a handle to the BOM Items.
! z0 s6 e$ a5 ^( }5 ~3 c9 Z- sItem bomItems = results.getRelationships(); & f" l- W/ n% t/ x$ P
int count = bomItems.getItemCount(); 6 {- s* r' I6 N; `
int i;
+ T- {3 }7 e, Z, A8 H& L : ^; ]* |& x- o/ _% B
// Create the results content. " S% {9 ~" c" }* F3 @% n0 U
string content = "<table border='1'>" + / ?! U% X. B6 V
  "<tr>" + . z4 v; v( `+ F
    "<td>Part Number</td>" +
4 N( F' d8 @! x1 I3 a! y    "<td>Description</td>" + + q. Q6 ?5 R4 L
    "<td>Cost</td>" + ) P! l  _( l; z! g
    "<td>Quantity</td>" +
& ~* H6 S7 {  m6 M3 i: [  "</tr>"; $ C9 g. f1 }) f8 }* j0 x  \" u

) s6 I$ W( v+ g8 a// Iterate over the BOM Items. ( @- H9 w. |; N! E
for (i=0; i<count; ++i)
$ r# P% K) I/ p7 |{
0 y$ V0 }  e6 z- ^1 V: c# B// Get a handle to the relationship Item by index. 9 `& _2 F& b6 t% q3 Q) y2 h  u
  Item bom = bomItems.getItemByIndex(i);
  {3 u7 M- O' A6 c- z' ]// Get a handle to the related Item for this relationship Item.
3 a8 u1 V+ D- f  Item bomPart = bom.getRelatedItem(); + Y% R! F. c( Z! e- R. T0 y
+ n3 f/ r4 N( b
  content += "" + 1 h# G8 A1 l7 K% b
    "<tr>" +
3 g1 G9 W5 a/ Q! U  `4 ]9 L* o2 w; p      "<td>" + bomPart.getProperty("item_number") + "</td>" + + ~! ]3 e# u* |$ `7 F
      "<td>" + bomPart.getProperty("description") + "</td>" +
5 ?/ c) Y; h. r7 f2 D' t' s      "<td>" + bomPart.getProperty("cost") + "</td>" +
. `/ j7 d0 D3 B: G0 Q      "<td>" + bom.getProperty("quantity") + "</td>" +
8 u3 }- O' t! A    "</tr>"; $ u7 {* O) K( A3 I8 }: P- s
}
1 k3 _  ?! h7 e% hcontent += "</table>";
7 ~3 _* x2 K& R8 r& j1 @
5 R3 U/ F, R9 a& \return innovator.newResult(content); , B1 \2 K% O# c: C
& a" \( u3 X; t7 O7 R

' G0 E% g6 E2 g) o. v  o- L2 g1 V+ Z3 p1 }9 Y

( f& r* z/ d5 t9 c; u6 V0 A5 z' K; ]5 v* M7 n1 Q

) ~& \2 p9 s8 y3 _6 I - V# H) N5 ^  Z# k# |
    Page 46 3 e, C$ s! X  d+ K! s
+ |* E( Z, u; Q6 o+ q0 t6 ^
Copyright   2007
. H% s7 w& x' k4 A7 w$ _Aras Corporation.  
1 O2 V* T* B7 B7 {7 D+ fAll Rights Reserved.
' a( {, t% m' h# |* hVB.Net  " ?0 \3 K, A8 f3 c+ _1 b1 A
Dim innovator As Innovator = Me.newInnovator()
$ u" y5 w) `! a ! |* b. n4 @5 [. Z5 g
' Set up the query Item.
/ Y2 ^) Z  H! V1 `Dim qryItem As Item = Me.newItem("Part","get")
0 B! E5 o  {# A/ {qryItem.setAttribute("select","item_number,description,cost")
8 X2 f7 r. l3 I' LqryItem.setID(myId)
& i# y/ d8 [# @, X: | 7 W# A$ I7 A+ [1 Q) ]" m7 e% }  ^7 d: |& _
' Add the BOM structure.
, Z  \2 x6 h( UDim bomItem As Item = Me.newItem("Part BOM","get")
* m7 L2 H0 f5 U3 |bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
' p2 G; }+ p( U. n  |qryItem.addRelationship(bomItem) * k: b# H- {: w# C( b2 H
7 D3 C0 Y) Z4 h9 V, ^
' Perform the query.
; S/ T# E1 y4 n  TDim results As Item = qryItem.apply()
4 m# V  o# r0 F( ] 2 e* R7 L; p  y
' Test for an error. 6 E$ N1 x8 _) g" p3 s
If results.isError() Then * C. u" ^! s5 t/ Y5 @
  Return innovator.newError(results.getErrorDetail()) ! n& O) k3 T' h' w# r- X
End If
7 W/ p. [  ~8 a( ~' p2 J ) _7 e: [- ^/ Q3 c* L" `. K
' Get a handle to the BOM Items. 9 q0 Q( {# @* t2 C$ w. q2 @
Dim bomItems As Item = results.getRelationships() 8 T- s& {/ o5 w/ g
Dim count As Integer = bomItems.getItemCount() - ~' R' k' s5 v# E- o& o
Dim i As Integer
4 _4 k- q& W, M9 H3 ?; K: e 9 A; A' z( Y8 S
' Create the results content. + i, ]# ^" H4 p- m7 E! b: e9 G" X
Dim content As String = "<table border='1'>" + _
1 n, j( g" |3 @9 ]) ~7 ?  "<tr>" + _
, \& w9 X3 p  ?, S    "<td>Part Number</td>" + _
9 {! G% d5 _: Z0 O1 i- {    "<td>Description</td>" + _
9 X# L1 J8 w% g    "<td>Cost</td>" + _
7 ?( l& O  D+ Z9 j9 C. i5 z7 b    "<td>Quantity</td>" + _ : S/ m3 Y! G' k) k7 u( i2 S
  "</tr>" 3 y0 i1 r3 t4 I0 E/ c4 c: V

; g2 c1 _& Q. j' Iterate over the BOM Items
% o. J- X4 N8 s8 G' S7 H8 T: ~' lFor i = 0 To count - 1 5 d) Z* o- }0 N& C9 K& L
' Get a handle to the relationship Item by index. ' }( {( ?2 H+ z
  Dim bom As Item = bomItems.getItemByIndex(i) % `) B  x% Z& g  h
1 [! V  V" q+ b5 ?
' Get a handle to the related Item for this relationship Item.
3 F4 y' K8 H* h- F) ]* l! j* h  Dim bomPart As Item = bom.getRelatedItem()
& G/ P2 G! z& N; S  s' Z" K / Y& o- |$ E. F
  content += _
; W- }: ^  a# k) G+ \$ g+ ]; j/ Z( ^    "<tr>" + _ , s* I, B& X6 z! b) ]3 O/ h2 i4 J
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ : G2 a  |7 S+ U, A- M  X
      "<td>" + bomPart.getProperty("description") + "</td>" + _ , O" t) q2 w! `  \5 [& b& l
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ % S! w: D# _! E8 l7 [3 G6 n! G& C, V
      "<td>" + bom.getProperty("quantity") + "</td>" + _
4 u$ `9 Y9 f& N2 k$ ?1 F    "</tr>"
' a# F& \& ?$ Q! rNext * T( N, t0 T/ C, F/ V
content += "</table>"
8 B2 a0 d1 _! p- r ( a( e- l% s" f7 l+ C& ]% ]1 E
Return innovator.newResult(content) + Y0 t3 z% Q  w& I% c( E

# ~/ m9 v( R4 g% f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了