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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
  `. A" t0 Z! TTo query for an Item and retrieve its structure you build the query as the structure " j- k$ R& b) ^/ m; G3 w) m) t5 U
you want returned.  Use the IOM methods to add the relationships you want and
7 k8 C0 h' f+ o5 U/ F9 U4 \build the structure in the Item.  The server will return the structure that follows the & {$ V1 c' g$ ]& t$ k# d7 o) u
request structure. 0 l/ V! ~* ]$ M
This recipe illustrates several related concepts together, which are how to get a set ( L: X8 `# z& \- E' r
of Items from an Item and how to iterate over the set, plus how to get the related
$ H$ c/ ~. y8 `% q1 b- P% S  nItem from the relationship Item.
, A0 q  t, G8 D9 P% |4 C" J8 pJavaScript  0 Y. Q7 k) j; _( ^1 b
var innovator = this.newInnovator(); * N0 C  E; A: U+ Z3 o; w! G
/ X* q' r) A' j) I6 I- K3 x
// Set up the query Item. 4 l& ?5 e! e4 ]. |/ W
var qryItem = this.newItem("Part","get"); ) x" y4 h. E8 w3 f" L! U, M# j
qryItem.setAttribute("select","item_number,description,cost"); - ?& Z% P# b8 Y" l# r9 t# e( X2 ?9 _
qryItem.setID(myId); 1 M  z- r6 e- _' j1 v
/ U4 ^" B0 ]5 ?2 e8 G8 c
// Add the BOM structure.
; b8 Y# Y% P! L( B1 C& ?5 avar bomItem = this.newItem("Part BOM","get"); 6 {6 f8 J4 W$ V
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
& C- c1 W0 \7 {' `- r  s5 D, A! F" yqryItem.addRelationship(bomItem); ! ^. ~) J4 Z1 B  H# a# c+ \

7 d% \7 T  g/ D2 d  A1 O% u// Perform the query.
2 o& s9 o/ S& p* w* W2 j. l3 F3 Tvar results = qryItem.apply(); : c1 ?$ \/ @% Z, r
9 s" q1 s6 g) x" x" O) r# k  s
// Test for an error.
# P, T% ~! ~4 I( I) M) iif (results.isError()) {   h2 e$ D  @$ q8 f
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 6 `" \) k$ z  P% \8 [
  return; 9 P( j$ J& K1 W2 I6 P( R
}
6 H+ [7 g2 T1 Y( Q ; O% T$ p; C: K( w' {
// Get a handle to the BOM Items. 2 }8 Z& X0 A( [. A! l8 b( ~/ B
var bomItems = results.getRelationships(); / j2 b7 O& X9 g( ~( e9 u9 l
var count = bomItems.getItemCount(); % x, d  z) {4 g: y

1 v9 f$ I* V* {2 }6 g// Create the results content.
7 C2 |& f& ]! W  bvar content = "<table border='1'>" +
1 s7 I6 _% {0 E  ?4 H- t# K; P% B' @  "<tr>" +
8 P+ ?0 |3 l+ `    "<td>Part Number</td>" +
3 k/ E; \8 V; u3 T    "<td>Description</td>" +
7 V3 G% `+ e7 V, U5 w) X    "<td>Cost</td>" +
, \$ \# t- X  ^7 ~3 g4 a    "<td>Quantity</td>" +   M" B+ h' e" J
  "</tr>";
/ L" `* d$ I9 G4 y
1 M3 Z5 y- \4 N! E4 s& E% s- d// Iterate over the BOM Items.
6 N2 v0 M  L# |9 s6 mfor (var i=0; i<count; ++i) 4 _1 k, o" D; B& c# ~1 S4 K/ Z# _. ]
{   i! |7 I6 f  c4 u0 R# t" B
// Get a handle to the relationship Item by index.
" Y. a7 \2 P! P/ V; n8 \  var bom = bomItems.getItemByIndex(i); 5 _+ R4 M" K. H+ \: l
// Get a handle to the related Item for this relationship Item.
' \9 R5 {/ H. R% z3 O  z7 b# Z  var bomPart = bom.getRelatedItem();
7 [) a8 R5 d$ j1 k+ x: _) u  p
. Z5 v0 [" L! R  content += "<tr>" +
' h+ w0 q4 R9 R& k      "<td>" + bomPart.getProperty("item_number") + "</td>" +
1 g5 ^7 h' m/ C5 b      "<td>" + bomPart.getProperty("description") + "</td>" + - `" a& X2 O6 @0 C# E3 \) w
      "<td>" + bomPart.getProperty("cost") + "</td>" +
: u5 F8 O2 H  f) _; _" O      "<td>" + bom.getProperty("quantity") + "</td>" + * {1 u* |# p  n5 Z* ]
    "</tr>"; ( Z, Z# y$ E5 `
}
" z0 T% N. h/ H! n: n% Dreturn content + "</table>";: d+ l6 Z- }! _8 f4 f: _: I# l
9 f% G0 Z* q. E5 }
3 j* b( m( v5 A9 @4 }

5 U4 M$ T$ f8 A3 T' i' i0 {
/ j, Q, {4 \* q# F! X( \* {0 |
C#  
) W; F, q0 ]% G7 jInnovator innovator = this.newInnovator(); * W! I5 X& R5 F* B$ M

! s+ M) N  G: N// Set up the query Item.
. y5 J7 E& T* R7 ]Item qryItem = this.newItem("Part","get"); , Z2 o1 |( i" B# z
qryItem.setAttribute("select","item_number,description,cost"); % _0 F, H" q9 ~
qryItem.setID(myId);
7 H: D0 n/ j4 j" F
" I5 r0 b3 x; |. @: u6 r1 p% M- }// Add the BOM structure.
/ q+ l6 S  H# q* A5 E1 qItem bomItem = this.newItem("Part BOM","get");
; y+ t- g/ A) L2 P+ r# ~1 q4 XbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
. p4 Y0 K% a. kqryItem.addRelationship(bomItem); 4 W4 L# Z" V6 {( x, G; Q' L$ c
) q! {# j& i! b2 s$ M' H, [
// Perform the query.
1 @' u+ U* _; X3 m, jItem results = qryItem.apply(); # {# C# v; Y$ R5 f) [  P
- `; ~0 B4 x' _
// Test for an error.
  s% K$ {( Q) i2 D6 Wif (results.isError()) {   K; P& K! y8 G: n/ e
  return innovator.newError("Item not found: " + results.getErrorDetail()); 4 ^! @8 X% v  T8 R% Z
}
$ e0 B2 j! O) g: d% C) c
* I+ b) B; m" c0 j1 ?// Get a handle to the BOM Items. 9 W4 h$ O: U* e; p4 c, P/ X
Item bomItems = results.getRelationships();
$ ^  _5 _  {$ J+ E, O  S2 H8 dint count = bomItems.getItemCount();   v2 m# v) i+ e, G( Z
int i; * u, ^3 N7 q  m0 a- |2 z. R" F
1 O& o9 c: X5 a! Q( \4 V9 }
// Create the results content. 0 I' G4 ^+ ?% d/ v
string content = "<table border='1'>" +
4 Z! I# o/ n* ~0 I  "<tr>" +
8 g  l( W) f$ y5 a+ F2 ?    "<td>Part Number</td>" +
' m( E3 m9 u& D- G5 [3 x    "<td>Description</td>" +
8 r" B4 Z/ x1 a+ D* f) C    "<td>Cost</td>" +
: Q" W" A6 Y6 C    "<td>Quantity</td>" + / a4 F5 x/ w6 M
  "</tr>";
( w4 H% I. O- {, B' `0 X 6 Y; ^6 Z  s  f3 i
// Iterate over the BOM Items. 6 p7 m5 \& O7 `! j: r
for (i=0; i<count; ++i)
9 d+ H) L0 W  \# R+ u{ 9 U% @9 S7 e6 N1 P4 r. y
// Get a handle to the relationship Item by index. 8 H3 [/ E) m' j
  Item bom = bomItems.getItemByIndex(i); + ?/ B7 F. Z) d; J5 N- w4 Q8 J
// Get a handle to the related Item for this relationship Item. 2 I) c$ U. i* S& G. g: H
  Item bomPart = bom.getRelatedItem(); " ^. a: r% J5 a, V
" k: U( C* s* o  W# s7 `
  content += "" +
* l9 `4 @( Q3 I4 P: t# F4 d( N    "<tr>" +
3 H3 `$ a: O; {9 f6 e- h9 U      "<td>" + bomPart.getProperty("item_number") + "</td>" + + b  S, B5 A  l, q% d$ F
      "<td>" + bomPart.getProperty("description") + "</td>" +
+ w8 o) v! Y8 E# C0 i6 N2 c      "<td>" + bomPart.getProperty("cost") + "</td>" + ; |0 R9 w# [6 H3 ?" h: w
      "<td>" + bom.getProperty("quantity") + "</td>" + 4 z( @& E# a3 l6 H; |7 k1 ^6 H" R
    "</tr>";
  |- [$ F9 S& G8 D9 _8 f} : t5 s! l* ]# K6 t' J8 W5 N
content += "</table>";
7 e$ p6 c% w! g8 }. P. O( [
$ J) V9 s" M! X: hreturn innovator.newResult(content);
" [% v1 b# T( o* d& k
+ ^5 I+ h* a/ N6 I

; H  {0 y3 l2 Z- i/ I& d5 _1 w. H2 j" U, [" ^+ F

) G; p# T; m7 @; \9 h' {) l) P. T( y# }% S" Y' `, }5 Q
/ e3 V3 @. F( Y0 D! Z6 @

+ y$ D2 n0 [0 P0 W) g    Page 46 # K5 y0 W+ z+ ]; w4 ~+ ?
! K1 e6 x% w) Z0 o
Copyright   2007
6 C- ^1 k- e3 \+ r" M7 M. K0 uAras Corporation.  
6 M% u6 q4 D3 t: g1 c1 xAll Rights Reserved.
! G+ E" t+ z% A- J: z% w6 |5 u6 }VB.Net  
' B3 l% Z$ z) I% a. c7 P- KDim innovator As Innovator = Me.newInnovator()
: d7 w! e3 V5 Z2 U0 T) w6 p$ x ) u6 q) e! I1 `
' Set up the query Item.
7 V" z9 z; m* B5 Y. D4 _$ xDim qryItem As Item = Me.newItem("Part","get") 5 V2 J" O: x  |
qryItem.setAttribute("select","item_number,description,cost")
" D+ m8 Y) b: U) u" sqryItem.setID(myId)
  `% m" h' z$ F6 ]  h$ M2 n/ E
1 C/ L) b7 c( z: R' Add the BOM structure.
4 J* E" Y9 w" x, HDim bomItem As Item = Me.newItem("Part BOM","get") 6 Y8 S" c# z* O4 |, z8 u/ l$ U
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") / c3 _5 G6 q2 h9 [, E& K
qryItem.addRelationship(bomItem)
: x, W! k% u) g $ G: S6 f0 J  A3 a, i: @/ v
' Perform the query. & R- C( {, E8 [" u
Dim results As Item = qryItem.apply() " L/ ?' q; V6 E8 }

$ ?& X" M( _) j5 n2 T0 Z* T' Test for an error.
+ L1 L. I4 p& i6 D7 LIf results.isError() Then 5 B: i6 |; R; q- s: G
  Return innovator.newError(results.getErrorDetail()) ' E; f  [9 t1 M- B. f+ M2 m' I
End If
* [. I( p# U6 [3 z4 }$ ~! k  [+ U& M
, y, S4 t! |8 Q) z/ G  L" i0 J0 A' Get a handle to the BOM Items.
; n* m. T" d/ n7 B  [Dim bomItems As Item = results.getRelationships() # H' x8 w/ p4 W; `
Dim count As Integer = bomItems.getItemCount() # \) I' \$ X& h. J
Dim i As Integer 5 {1 p- U* v/ L
- w* C; R) x1 l% V8 z
' Create the results content.
- J! Z$ s8 R$ ~% v( Y5 r, |+ y" tDim content As String = "<table border='1'>" + _ / B: l- W$ P. {
  "<tr>" + _ & r7 M1 M" d  }; Y$ B) V  l4 l
    "<td>Part Number</td>" + _ 1 E9 n# F$ h+ T8 q$ [: W+ D
    "<td>Description</td>" + _ ! L6 S/ I% j/ V' M! ?- F4 d$ C! L
    "<td>Cost</td>" + _
& }- y4 {, s& t    "<td>Quantity</td>" + _ % {4 M3 i2 |8 R9 H$ i; C" K- Y# K
  "</tr>"
  U) p8 {& [% `8 ^
2 W% H, _9 m+ z) ]5 ?  C' Iterate over the BOM Items
% I4 f% {5 g0 y6 B7 i1 ~For i = 0 To count - 1 4 d1 P# U+ \$ [/ I
' Get a handle to the relationship Item by index.
1 y$ x6 h; Z' W  Dim bom As Item = bomItems.getItemByIndex(i)
  A& f6 ^7 ~" K! [% u5 S 1 [$ \0 k( ^# ^! ~' Y
' Get a handle to the related Item for this relationship Item.
: o1 m. Z  B  }3 T  p& i  Dim bomPart As Item = bom.getRelatedItem() " u  l( b& |/ X6 Y: ~8 b+ _& [2 G

( D6 c/ v# t1 ?  content += _   U3 N2 m, [2 k2 O8 W: x
    "<tr>" + _ 6 E/ K& m! g: I1 Z$ C% H' @2 C
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
$ `0 i; c. e9 `      "<td>" + bomPart.getProperty("description") + "</td>" + _ 3 A0 ^; o$ r; a& f4 m% v! h
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
9 b; @; {3 I  E4 C  D3 I' A      "<td>" + bom.getProperty("quantity") + "</td>" + _ $ j/ l  o1 ]( d6 c) `. Q* u
    "</tr>"
0 v: |; I) H5 g* D* @7 q5 U3 ^Next
0 F. ]/ n: F: Z3 |) V  Ucontent += "</table>" ( X% }1 d- Z+ G  G! V2 \

  }+ i- b& F7 d7 I7 T+ @Return innovator.newResult(content)
+ m7 h1 I2 X9 o
$ O/ x. t0 P% A# A! e$ B
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了