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

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

[复制链接]

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

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

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

x
Technique  % {  _) n* X' {) X" r# Z
To query for an Item and retrieve its structure you build the query as the structure 8 W1 t4 h! \4 U2 I$ B2 W2 t& k
you want returned.  Use the IOM methods to add the relationships you want and
# H5 @3 |/ r) r, R5 p3 gbuild the structure in the Item.  The server will return the structure that follows the
( B0 q  B* ~* i' M. v) xrequest structure.   U$ V) T) q* W/ A' J" F
This recipe illustrates several related concepts together, which are how to get a set
; Q1 h/ E0 v; [* }of Items from an Item and how to iterate over the set, plus how to get the related
! K! @( `" C, X& S2 WItem from the relationship Item.
/ {9 _' F1 F+ @1 |( zJavaScript  
- Q# a" `8 h3 P" f/ o8 P5 _+ n+ t8 Avar innovator = this.newInnovator();
/ e, Q8 t+ D; m! U
  |7 c& ?" ]/ H// Set up the query Item.
" X6 k! s- Y2 F( hvar qryItem = this.newItem("Part","get"); ' {  g2 i, |7 M2 A$ C3 L
qryItem.setAttribute("select","item_number,description,cost");
) t2 Z9 \6 {/ L7 W# i7 GqryItem.setID(myId); + a& ]  {( S( y
9 ~& {3 _/ V& U
// Add the BOM structure.
- c5 q# {: T; T6 ovar bomItem = this.newItem("Part BOM","get");
+ z: N) P5 _8 K& H4 ]bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 3 _8 S  ]; k8 h% N. u/ A7 e
qryItem.addRelationship(bomItem);
. u1 j2 s( I/ n& \, r- S# l3 _# Q
: K. p- y+ s+ y1 |- a* i// Perform the query. ! I) y# h' G( ~  I; }! ~, L
var results = qryItem.apply();
. J- k4 [" [( V# t
) ?9 R& \, W9 Z$ {6 j7 }// Test for an error.
" ~+ ^% F/ S5 ]) l4 vif (results.isError()) { 9 P9 e: C7 I) Z4 u
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); , T  h. M/ i- R; I# G
  return;
9 }, l, T, o9 ]% T} 1 P9 B0 E4 E3 ?6 t3 U
# A& }, W/ I" k' P3 Q1 i
// Get a handle to the BOM Items.
' }- S8 d* `3 P& t  t1 C. hvar bomItems = results.getRelationships();
7 a0 G$ Q, U7 |+ z+ @( x  R$ tvar count = bomItems.getItemCount();
. K5 Y- U2 n3 L! z0 P( Q7 V& \ ( |5 ~: h4 k- v$ I1 C
// Create the results content.
4 h' G& ~9 l% d' q5 Y; rvar content = "<table border='1'>" + ' ^. w7 M; G# m; L  a
  "<tr>" +
+ M5 |; \$ F7 H# K) W    "<td>Part Number</td>" + . ?9 [3 s7 @; ?
    "<td>Description</td>" + ! h' B( ]5 H9 k7 B
    "<td>Cost</td>" +
+ Y' |# ?% ]) d  S    "<td>Quantity</td>" +
) n( E3 U- S( j* T; C/ X  "</tr>"; " |; s1 n, L! j' D

  f* T- H: F; R( z# @- ^// Iterate over the BOM Items. , Q# r) j( [+ h! Q# o" |$ l
for (var i=0; i<count; ++i)
* _7 Y2 V% X3 x$ b7 L{ . }5 v3 a; ~2 c: X2 S* d
// Get a handle to the relationship Item by index. 4 e4 _; B& [0 I. s  z
  var bom = bomItems.getItemByIndex(i);
" Y  `1 M- @3 M  m// Get a handle to the related Item for this relationship Item. : q5 V( j- ~/ P, E
  var bomPart = bom.getRelatedItem(); ; ^. v; i8 [1 m0 s) l
0 D9 _4 [1 U7 j
  content += "<tr>" + ' m" X5 D- A5 c3 |# X! J( `# t
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
/ b9 R4 E3 z3 G% H      "<td>" + bomPart.getProperty("description") + "</td>" + 7 C; M/ {* H! I7 D
      "<td>" + bomPart.getProperty("cost") + "</td>" +
: h' B7 t6 f0 m" N8 g0 x+ e      "<td>" + bom.getProperty("quantity") + "</td>" +
% X4 {) Q- }0 O" E+ Y; v+ j) L! V    "</tr>"; # r7 Z. V8 w9 [+ H/ G/ d0 W
}
1 m9 `: ?. ^  z' p$ sreturn content + "</table>";' Z+ r+ F& {% n+ C  H. v

) L5 X5 U+ ~2 u
* ~( I( C' D( `
3 D! `* H' m/ K0 L8 q7 E; a; Z
! n1 |/ C8 k" x: u" ], i* x
C#  
4 F' O' _4 y  H, g4 {4 JInnovator innovator = this.newInnovator();
& @. c5 o( b. T4 [# |8 W5 S / \) {8 c8 g! y0 c
// Set up the query Item. ; D$ z  D8 D( t
Item qryItem = this.newItem("Part","get");
9 Y( v& N, v5 W/ h8 @# N- UqryItem.setAttribute("select","item_number,description,cost");
/ A5 I# q9 _% ]  gqryItem.setID(myId); * A3 o. V: V4 e9 l% F  W
* d3 ^; W0 S6 N; u5 F0 `
// Add the BOM structure.
  Q! l0 d5 w& pItem bomItem = this.newItem("Part BOM","get"); , {- L& D) }: q: h
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ' r& s1 @; N/ g$ J9 Q/ n
qryItem.addRelationship(bomItem); ' d  {' {* q5 h$ q
7 }5 b7 K; @9 k+ d) h4 C
// Perform the query. . X. {- ?+ ?; \: f0 c
Item results = qryItem.apply(); 6 L9 b2 d. ]9 D1 h+ @$ J8 ]
; @2 Y+ B9 D' A- {  t" b$ a# Z
// Test for an error.
' w% U* y% K' x9 mif (results.isError()) { 6 k$ P$ o  r( m3 R  u8 y# {
  return innovator.newError("Item not found: " + results.getErrorDetail());
( ~1 |6 S4 D. V2 r3 H, l6 K} 3 X2 r" Y% @' q2 @5 K
* Y8 E: D2 y1 i' E: \' ?
// Get a handle to the BOM Items. , s3 q- y1 U# T7 Q4 k) V8 U0 [
Item bomItems = results.getRelationships();
" O7 L, Q5 ]. F& j' @int count = bomItems.getItemCount(); ! H* ~, j/ K+ E5 i" t
int i;
: C# O* Q, o8 f' n8 Q
+ U2 g  @* B0 R) ^7 Q// Create the results content. - N& _5 d, }. u
string content = "<table border='1'>" +
6 O5 @% ~1 b/ a7 v& ~& h! p! {  "<tr>" + . Z6 Z: }2 z. z( K& `8 @
    "<td>Part Number</td>" +
) b% a5 d1 v( B7 J    "<td>Description</td>" + ; g9 ^/ ~6 x. v/ r/ A+ J
    "<td>Cost</td>" + . ]6 n4 s. t( Z7 Q, u1 }2 J! \0 d; Z( A
    "<td>Quantity</td>" +
* ~7 b) A5 H7 o, ?' p' G- k  "</tr>";
1 @) t1 D, |. S! h
( G" u) J( l: Y. l, \// Iterate over the BOM Items.
5 {. x9 N) f5 A! Jfor (i=0; i<count; ++i)
3 r; p6 z* ?4 j8 A4 K{   w9 c/ t4 }; j& E) Q
// Get a handle to the relationship Item by index. $ u! r; o) f$ v1 O; n
  Item bom = bomItems.getItemByIndex(i); 5 H0 V: ]- i2 a
// Get a handle to the related Item for this relationship Item.
8 s- V1 A* l: V  w$ O& D; `  Item bomPart = bom.getRelatedItem(); / Y  P1 A7 n: U1 p( Z
. l3 b/ z3 J8 n/ @
  content += "" + . O$ w, h/ {/ k* e; p9 T5 ~
    "<tr>" +
% y# a1 H) l  E* K' ^/ @/ K- f2 G      "<td>" + bomPart.getProperty("item_number") + "</td>" +
* N) B2 \( I! y4 ?+ m0 z4 N( U. b      "<td>" + bomPart.getProperty("description") + "</td>" + / ~& {% @, S2 m+ L
      "<td>" + bomPart.getProperty("cost") + "</td>" + ' S/ f; v  A( |
      "<td>" + bom.getProperty("quantity") + "</td>" +
% j0 K, _; N0 T    "</tr>"; , g( N; @8 d, R
}
5 _8 m6 A2 _* ~) C  rcontent += "</table>"; 8 p; s& {1 R' I( s3 g
) `* ?' k* r7 G3 [( l
return innovator.newResult(content); , |9 B  n$ k, _0 ?- f
4 p5 R6 a* i& a; x5 b

3 O  |. s" B4 w) f5 t$ t( B* ^' N8 d5 G6 J

/ f* i; d- B; O( A0 `6 a) `
9 f# L% V2 y5 q1 W

, m7 S3 N8 ^0 \. G0 W7 H$ u5 o
3 _' Z$ Y& r" I. s: Z    Page 46
- X6 ?: ^( Y! p+ A1 l" b) v+ { * m, f! {/ @! E0 _7 K
Copyright   2007
3 ~" I) D) o/ _5 L, V- c" x6 S& A$ PAras Corporation.  
  T1 L# n1 M9 {$ p; w  K( a9 VAll Rights Reserved. , @4 a% R. [* H' a
VB.Net  
! J& h; @1 [8 N! i. BDim innovator As Innovator = Me.newInnovator()
1 N" k# B9 s. W  r! W: } 2 i9 {4 s( h* r1 z+ e$ Z4 s0 V
' Set up the query Item.
$ K0 T) Q, U$ t% w5 }Dim qryItem As Item = Me.newItem("Part","get")
: E7 t) w0 [. D8 F! WqryItem.setAttribute("select","item_number,description,cost")
! d+ r6 p% q1 _! O) ~qryItem.setID(myId) 6 {2 O; J: A$ I6 y! x% B$ O

2 ~; n' f: x/ ?0 C6 U* r! `! R6 `% I' Add the BOM structure.   F) v+ x9 y) M0 @
Dim bomItem As Item = Me.newItem("Part BOM","get")
: T: B% t9 P! ^5 ]) C$ W3 M8 obomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
) X1 Y1 e7 B' w$ P2 ?qryItem.addRelationship(bomItem)
6 h& F) ~+ ^2 ?5 }, Y: v% w6 e1 [ 0 f: A) o5 h. E$ H3 ]
' Perform the query. 7 x+ W; Z4 \5 T$ g5 G4 a7 z/ t2 p
Dim results As Item = qryItem.apply()
1 }) ^& [) c9 ]2 ]/ r! [
5 F1 V  T: t& s$ [' Test for an error.
4 D% x# H  o; w" ]! ]If results.isError() Then + t  w4 D5 W' T- G- ~0 [& {
  Return innovator.newError(results.getErrorDetail()) ' d9 v+ q8 k- t4 Y7 B
End If
# X' A  ?1 F5 R( E  Y2 E  \ 7 V. z, N4 t  R7 P! ?" L, k" V
' Get a handle to the BOM Items.
5 [2 K$ f" ]5 ~; MDim bomItems As Item = results.getRelationships()
3 _) N( B6 w! [; z  SDim count As Integer = bomItems.getItemCount()
8 m8 ?  F2 _5 u" R) u7 ?Dim i As Integer 6 @8 c6 D* F5 h& o( ?3 ~" R
( r0 w' v  w1 \7 n4 ~
' Create the results content.
! v; X4 A2 }/ h! H, j' IDim content As String = "<table border='1'>" + _
: n! `# [! ]* @/ ~; U  "<tr>" + _ . P7 F. ~. b1 Q4 f
    "<td>Part Number</td>" + _ % ^: q- V' v( h6 F' a% a/ q
    "<td>Description</td>" + _
) m8 e6 J. F/ n) b" ]0 X$ V7 e1 q    "<td>Cost</td>" + _ , S$ o2 I) e6 u2 O' o5 k' @
    "<td>Quantity</td>" + _ 2 J  i% r$ ^8 K, i1 e
  "</tr>"
) g0 @$ u8 f' w& q# B8 ]
) R: p+ T# z: \" e9 b, l  v0 p' Iterate over the BOM Items # o) {( `; q3 j2 B6 m6 Z
For i = 0 To count - 1
  H$ V9 R$ b% U. c' Get a handle to the relationship Item by index. ! g0 [9 `& X7 z9 B4 i/ Z* O
  Dim bom As Item = bomItems.getItemByIndex(i)
2 @$ M, j- o4 T, f* w8 | + ^/ [) y3 u7 R$ @4 h. {$ V
' Get a handle to the related Item for this relationship Item.
' v# t& K, Z2 [) g0 m, Z9 R  Dim bomPart As Item = bom.getRelatedItem()
; o) R) B, z# O4 t# F" p 2 T; `* ^  m7 [7 j& U. Q& k
  content += _ ) d/ X+ M7 p. R0 [
    "<tr>" + _ 6 U/ o3 T: w  u
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 k; j/ x7 c( A: _/ ^+ z
      "<td>" + bomPart.getProperty("description") + "</td>" + _
! q7 c7 R7 L. S4 ]- d4 ~      "<td>" + bomPart.getProperty("cost") + "</td>" + _ ) K4 I! H9 ~) K0 e; n: l
      "<td>" + bom.getProperty("quantity") + "</td>" + _ ) ], A) D5 l( [% p+ s
    "</tr>" 6 j: o2 t& J. W( |8 W' z
Next 5 j- }- R: B8 f  C7 n: [
content += "</table>" # J. ^$ m6 S1 x: |- {  o% v
5 D, E0 p1 G2 D) l1 ^( e  }& L
Return innovator.newResult(content)
& M" h, R) b- C5 H8 X  F! o0 X. w4 F6 }+ l0 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二次开发专题模块培训报名开始啦

    我知道了