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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  / t, ?! _, s$ o/ v2 E, L
To query for an Item and retrieve its structure you build the query as the structure ) `  I! q& b( V1 r/ ^. Q% M
you want returned.  Use the IOM methods to add the relationships you want and
" b; m7 Z( m+ g" Y. ^& X0 sbuild the structure in the Item.  The server will return the structure that follows the
; {# L; i$ o" i2 N& Z; \request structure.
+ H0 e& i# n! fThis recipe illustrates several related concepts together, which are how to get a set
* T# p9 H! M5 O3 l, Cof Items from an Item and how to iterate over the set, plus how to get the related % Y3 R5 _' f2 P2 x
Item from the relationship Item.
' ^7 p; v0 F1 s: U" ~- jJavaScript  
" F& ^+ n5 k' k( fvar innovator = this.newInnovator(); 2 O5 P: n) B1 Q- }9 w5 X0 s% E

4 p, [: o6 S6 K" Y  u/ v# `// Set up the query Item.
/ S2 v) T. r4 o( v) G: Vvar qryItem = this.newItem("Part","get"); % U& F9 k# J, k( J
qryItem.setAttribute("select","item_number,description,cost"); * p3 M: ^7 F% @6 v7 D
qryItem.setID(myId); 4 S7 ?. q( _$ D0 v7 O6 d

# y6 A. i/ }  v  S// Add the BOM structure.
1 Q" }+ |; N" Avar bomItem = this.newItem("Part BOM","get"); , e5 z) C- C  l; B
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ! O& ]9 k1 E6 Q7 g
qryItem.addRelationship(bomItem); 6 W- n3 O9 B# K: }7 }2 V

3 `3 n, K3 W$ W// Perform the query.
0 o2 O" b% S$ Z1 f+ ?; |var results = qryItem.apply(); - }; e5 w2 t& H8 S" w, j: G

# O# |! V1 g$ P  D% e: n- S( s// Test for an error.
3 b4 I- l8 B) j/ d1 c: fif (results.isError()) { 9 y$ v6 U0 h& b4 Z) d
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
, ^1 c6 |& o! n# T: p* \  return; ! d- s# G0 e4 e6 o5 e" U
}
( E( N" j' @2 ]( b, _. z8 I ' \4 q3 r$ s+ x
// Get a handle to the BOM Items. 5 M6 |  V7 H0 B3 o
var bomItems = results.getRelationships(); " m1 p# v* ?4 h7 w8 o/ K
var count = bomItems.getItemCount(); 6 ]8 K) `% E( x, C
) l, z; ?. g) M+ D- C( |
// Create the results content. ) Z' i0 I! q3 A5 [+ C
var content = "<table border='1'>" +
" G: Z$ c" q3 B) Q! J  "<tr>" +
1 y& f: c8 q& z1 Z. C% ^    "<td>Part Number</td>" +
, Y: i3 D; M7 [; R3 s  D    "<td>Description</td>" +
" p1 p: B% E$ n. I    "<td>Cost</td>" + 7 {- ^* f* t" B  S3 u2 S
    "<td>Quantity</td>" +
+ R% A* b( C$ Q2 ~  "</tr>"; 6 ^1 ~1 W' X& N6 q4 D9 B# f

( a9 E" K1 w& [; A/ p- h" G$ j// Iterate over the BOM Items. , L- V$ i0 K4 @: Z9 n: u/ V
for (var i=0; i<count; ++i)
5 y, O0 s" ]. l( J{
4 w' w# m; c2 T( g5 B+ T& T: T( z// Get a handle to the relationship Item by index.
6 W/ `1 N) t' S7 ~! i- }& w6 p  var bom = bomItems.getItemByIndex(i); 9 n6 y% p- }" X9 N' j3 H# k8 C: c
// Get a handle to the related Item for this relationship Item.
: c( r7 V% P* e5 q  var bomPart = bom.getRelatedItem();
" C, k4 ~( y: D3 i' ~
2 Y, k- O6 r3 D+ Q6 @6 L" n  content += "<tr>" + - A8 C, X: Z0 Y" `9 \* A) \! ~2 b
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
" \, @6 A# T0 o8 i% m, I  Y) x      "<td>" + bomPart.getProperty("description") + "</td>" + 7 ]8 Y% d7 x7 A' K# C$ M% ?, q
      "<td>" + bomPart.getProperty("cost") + "</td>" + 0 i- s, g- N/ ^) [4 _( o
      "<td>" + bom.getProperty("quantity") + "</td>" + * @, S3 Q$ {) B1 x; Y7 m9 H
    "</tr>"; ' j# G, t, b% }/ {* ^
} 4 i- u: z$ o5 n! z. ?
return content + "</table>";
6 V; T) L. ~! F- _
/ \: s7 e4 R4 ?  g
0 f4 ?. {+ w& `4 ]; D% g

0 ]9 @2 f: @6 o3 D( [

- M1 H  j0 e- L) [3 k4 {: ]' GC#  
( c& `1 a8 H( S2 |Innovator innovator = this.newInnovator(); 9 y6 a, K; s8 U( j. j3 d7 y# Y

( p. Y0 |  I' [# E7 D0 ?+ }4 I* T// Set up the query Item. 7 }  s9 G9 H; G+ H+ w! [, v* y
Item qryItem = this.newItem("Part","get"); - w# H, L' h, I$ z  e) i, F/ j
qryItem.setAttribute("select","item_number,description,cost"); 0 M1 D6 Y8 N2 U% r) O$ R
qryItem.setID(myId); 2 O# {% w( F8 E7 g+ j0 P6 V
. T; _1 I% b3 U" Q
// Add the BOM structure.
" h- }$ d/ A: g4 tItem bomItem = this.newItem("Part BOM","get"); - ~2 b3 M& W) K2 S
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
$ ~3 s4 u9 _( j0 N" b' wqryItem.addRelationship(bomItem); $ x1 Z. A" S. I! ?& H, y3 H

( ]; F8 R  e6 h0 R( F8 P! J  G+ _, S// Perform the query. 3 x) c, J" a8 M$ ^* u% A
Item results = qryItem.apply();
0 D- g2 @! @, V" v- y* E0 u4 Z) i ' G  d9 g. V" u( ~" h, X3 s+ q
// Test for an error.
1 K, K9 Q5 H1 M" Yif (results.isError()) {
- l: G( m1 @& z( v0 I7 F  return innovator.newError("Item not found: " + results.getErrorDetail()); $ h) B  I+ {0 v* }" Q/ j
} . ~5 p3 t+ T: ]5 n/ j: k9 {
4 s3 ^* H+ r+ p+ N7 U" V0 E
// Get a handle to the BOM Items. 1 |; D  @4 ?$ r. w7 @/ u+ e$ g) a
Item bomItems = results.getRelationships();
' c% p$ k3 L' {9 z5 R, \( t$ dint count = bomItems.getItemCount();
' E4 X- `5 n0 a; q8 Fint i;
5 q$ j( T% I3 X' G* X0 v' b+ z * s  J/ _$ X$ D; ]9 b' L
// Create the results content.
" I: @3 D' P2 S" `0 r( B: t& Tstring content = "<table border='1'>" +
5 @* _% F# n* n- J  "<tr>" +
. N; ~2 D3 f  c6 D4 D1 v$ M! i, }+ [9 N    "<td>Part Number</td>" + 4 E' w$ D, l# d" Q! g, c5 N. k2 d
    "<td>Description</td>" +
, U. _/ J: L5 b2 p3 P) F    "<td>Cost</td>" +
; h5 q2 z$ _$ U" N+ l    "<td>Quantity</td>" + + E9 x& F& S. R# n. \8 {
  "</tr>"; 4 A/ B: J- E0 ]) S

1 v$ |6 ?" a* t, S1 P; p: w! c// Iterate over the BOM Items. ) T+ \& A+ E) \
for (i=0; i<count; ++i)
) c6 e7 B. U4 X  L$ d/ J! w( t{
- m1 z! @. ?3 A3 G! A// Get a handle to the relationship Item by index. 1 E2 T( R" H' I" X! Q
  Item bom = bomItems.getItemByIndex(i);
' {6 C5 z0 b- }// Get a handle to the related Item for this relationship Item. & z/ r6 H' I" L6 V) y' Z" E
  Item bomPart = bom.getRelatedItem();
3 g8 g3 G/ y/ [# s ! p9 d( _0 O- ^, W: I& C
  content += "" +
- y% U8 U: w, Q/ q  O2 H' `    "<tr>" + * J' t0 k) @0 u/ y# E5 D& I
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ) |  a3 N, z( D+ T# s. g
      "<td>" + bomPart.getProperty("description") + "</td>" + * p+ y+ [% v/ @, r- f6 f8 H
      "<td>" + bomPart.getProperty("cost") + "</td>" +
4 m7 `& ?+ \; _1 e: t: {      "<td>" + bom.getProperty("quantity") + "</td>" + : t) \1 G! W3 W3 g
    "</tr>"; # V* O9 S  \1 K, _" S+ P
}
# f/ M" W7 O1 w6 \& T  }content += "</table>";
8 D" `7 k3 D$ i' P6 P 7 s& g/ f( e4 M  m
return innovator.newResult(content);
8 }$ ]# W) M' r! s9 m1 M. U2 ~" n; U
! I- _# s5 o- L$ x5 a$ r% p6 l

6 F" A& \( I* o' [# u

) i! p2 Q* I( {( c  f; S2 Z
* h. q% y* q; k7 l, b

3 K) K# R4 ]$ H
! Q5 z$ t; m' M    Page 46
; T; O+ E0 P' T# `/ C5 l1 y3 ~
9 w3 z- O: h: r# e7 o/ V- m/ D  o! CCopyright   2007 $ b0 M4 \5 d# p0 r9 O
Aras Corporation.  
1 w* F) h4 M$ X, h# c2 d' rAll Rights Reserved.
& ~5 `$ P& I. u2 j. d6 KVB.Net  
; v. F) W3 D3 R  v& NDim innovator As Innovator = Me.newInnovator()
+ Y7 q; T, E% P( |) U : e! e! g' n0 c% ?3 q; y1 [
' Set up the query Item.
) r3 G1 Z. M0 V  C5 UDim qryItem As Item = Me.newItem("Part","get")
+ Q* r) X0 Z% F9 c6 e9 {qryItem.setAttribute("select","item_number,description,cost")
% V6 j6 Z+ I6 @* U# y& ]/ LqryItem.setID(myId)
) M/ f$ N' W3 c  {9 S # n! H, s* T, H$ U% K& N
' Add the BOM structure.
2 R) j  p/ v! @( S! eDim bomItem As Item = Me.newItem("Part BOM","get") $ c' Z, Z: l/ X: E! T. [# W, {
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
+ J0 @) ^3 f7 BqryItem.addRelationship(bomItem)
- d. J! {6 v2 X: s- L/ _) b( f
% v* ]* `' |2 a/ N2 e" d  f. p' Perform the query. 6 B9 h, g1 h$ D1 M
Dim results As Item = qryItem.apply() ) j8 [' Q6 z. T$ @- X* A

) G! F  }9 l+ n4 D7 [) [1 T0 F' Test for an error. # X! r- y( C  q. t0 y
If results.isError() Then
8 b: @8 S5 x6 G, q1 v  Return innovator.newError(results.getErrorDetail())
1 D, I1 p% v- ZEnd If
! A3 o# S/ t3 x8 b& k/ ~! V
1 \7 a( S  t+ \$ p6 ~7 Z' Get a handle to the BOM Items.
, B9 m. m  _' ]% k9 Z9 \' Q% F4 M" {Dim bomItems As Item = results.getRelationships() ' t; u3 i  n' B2 G0 b3 ?
Dim count As Integer = bomItems.getItemCount() 7 q8 q5 C# o6 `4 Z! f0 U9 h
Dim i As Integer ! q1 k% k5 r' c2 t& y3 [# m
7 A" E9 B9 q- h. u1 u7 k7 W2 Q
' Create the results content. ; Y1 {8 b7 Z" [6 f# q
Dim content As String = "<table border='1'>" + _ % B- V% m- u5 T) F5 b0 }
  "<tr>" + _ * C7 ~6 @8 L: A" U- e
    "<td>Part Number</td>" + _
. G' Q, F0 ^4 R# B    "<td>Description</td>" + _ ' V/ b7 a7 s6 m& h4 u. y$ a
    "<td>Cost</td>" + _ 1 @) C, ^4 `" N
    "<td>Quantity</td>" + _
3 `, D0 P* S" t9 U+ p1 S  "</tr>"
- Q- N7 b$ J- V
/ O$ E" o6 X7 l, }4 w$ I' Iterate over the BOM Items
8 D& k  Q8 g, G* b$ ZFor i = 0 To count - 1
5 g' c  }. I  r) a! b' Get a handle to the relationship Item by index.
( s8 o& n0 R( }! h2 K0 l" z  Dim bom As Item = bomItems.getItemByIndex(i) ! a& G9 o, n. h( N7 N
" q! s+ C9 z8 I" c* v
' Get a handle to the related Item for this relationship Item. 0 {+ U2 i# R' }6 x
  Dim bomPart As Item = bom.getRelatedItem() 3 V4 H# @6 f3 p/ ]

1 c0 J8 L; |# W% o  content += _
3 c% T4 f+ R& K% C5 w7 m3 `- W    "<tr>" + _
- v0 W8 |( P& k: U3 I      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 0 Q6 H4 P4 ~: l7 W) ]% O
      "<td>" + bomPart.getProperty("description") + "</td>" + _ : a9 K4 e9 `, m" u1 d
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ ; t( c2 j- F9 L% @. X, t* M1 B
      "<td>" + bom.getProperty("quantity") + "</td>" + _
7 Z" _- k9 r, X9 x+ u: L    "</tr>" / P( n0 v/ R- [) ?& d
Next : s8 [$ F7 ^* R
content += "</table>"
* O' p$ a( y  q( \3 {$ R9 a' ^1 H7 Y% f' m 1 s9 y1 g& S3 m( H
Return innovator.newResult(content)
9 F- W9 n$ ~. h* U8 Y; @
4 p! M& B0 }2 f) F5 H  B9 [# R0 m! c
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了