PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
$ ?& t  K6 a8 ^& J$ r* OTo query for an Item and retrieve its structure you build the query as the structure
# R' ]7 g) {6 N! cyou want returned.  Use the IOM methods to add the relationships you want and 9 p- f' S" M+ l9 A
build the structure in the Item.  The server will return the structure that follows the
( E  _+ g& S0 |2 X. T4 mrequest structure.
$ A) X8 J. }% f  S4 NThis recipe illustrates several related concepts together, which are how to get a set 9 ^, ]) _4 c% V% q, b* P! ]
of Items from an Item and how to iterate over the set, plus how to get the related
, ]5 v: W( p' Q) |Item from the relationship Item. 0 v7 o' U5 x+ O. Z
JavaScript  . {% {0 _' g3 a" l1 O- _
var innovator = this.newInnovator();
, ~& R1 z. n! Q/ Q# s
* J) r/ E  {- e* |/ Z$ J: Y// Set up the query Item.
- |+ d9 c0 B! e) Tvar qryItem = this.newItem("Part","get");
6 {; |) y$ G. ^; Y# ]+ OqryItem.setAttribute("select","item_number,description,cost"); 6 U$ v4 z2 V5 u+ h7 Y3 b$ }8 ]- \
qryItem.setID(myId);
; L7 L" G( `1 Z% {2 z6 F! M - V( {. u* \0 g- c: m
// Add the BOM structure. 0 R: q$ ~) W5 Y
var bomItem = this.newItem("Part BOM","get");
; H) u8 a7 m5 D8 l6 _. T, |/ mbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); , \' b/ a1 v1 g1 w' C
qryItem.addRelationship(bomItem);   C6 f& O! b# G  d- R) Z
) s( `: Y1 ~' t, S* J9 N
// Perform the query. 8 ^+ u! \0 T" _' ~* @1 W! I  d/ H8 F
var results = qryItem.apply(); ) p0 A6 o  ?  p

4 z, z+ ^/ H7 r: p1 O9 w// Test for an error.
+ b! v. H; Z8 Mif (results.isError()) {
3 U; M7 j2 i6 z$ o. ]  top.aras.AlertError("Item not found: " + results.getErrorDetail());
4 F+ @6 p* _  O$ M  return; & c& j- u  @3 `/ F9 @+ m4 `
} , v- r( r1 g5 g1 U

/ x. K# Z0 H: S% g# @// Get a handle to the BOM Items. 4 m0 c: |7 S2 x5 c! p/ x
var bomItems = results.getRelationships();
; ]7 ]9 j$ A$ q; Q4 f3 Avar count = bomItems.getItemCount(); ! D/ S. k$ f: v, m4 o

4 l7 x6 V7 e: C7 T, o: Y2 m. Q/ P+ Z// Create the results content. , k: W/ H9 b# H! _& j  q9 A$ i) y$ [
var content = "<table border='1'>" + ! H8 s7 s4 z0 b8 Q: n
  "<tr>" + & s( \' p/ x6 E$ [7 y3 J. \
    "<td>Part Number</td>" + & a8 a. z9 B8 |4 }! V
    "<td>Description</td>" + . U- N' }0 o6 N1 a2 x5 N+ Q
    "<td>Cost</td>" + 3 L# r# r% x! C  V6 ?
    "<td>Quantity</td>" +
- x: Z  K$ c6 Q/ S* e  "</tr>";
# p! o: Z$ o3 C7 U. b9 ~% E + ]" t# s- P- P9 D  s- R3 o
// Iterate over the BOM Items.
1 u9 p/ E8 u$ ^- J! D9 C8 qfor (var i=0; i<count; ++i)
; O* f' x! T7 q{ * H3 y4 R) b- d' @& r, S' q" S
// Get a handle to the relationship Item by index. 4 P6 @8 a9 F  s( x7 t) G
  var bom = bomItems.getItemByIndex(i); 1 m0 I! y/ P+ v& m1 e) h% G3 d
// Get a handle to the related Item for this relationship Item.
( W3 P! J3 h$ n  c. w+ \/ j  var bomPart = bom.getRelatedItem();
" Z! G2 D' q5 p+ _9 |- L) [8 d
3 n, z/ H% [5 d( b: x+ L2 H  content += "<tr>" + " C+ Q4 m+ O! O7 P$ v
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
1 H# r& ]& z5 \+ h6 c, n7 Z      "<td>" + bomPart.getProperty("description") + "</td>" + " O) F- D& m* u+ G7 H4 O& Q* _
      "<td>" + bomPart.getProperty("cost") + "</td>" +
$ a4 a+ |& W9 b$ R9 e  v# v      "<td>" + bom.getProperty("quantity") + "</td>" +
* ?# ^5 x0 G5 W0 ^0 n    "</tr>"; 0 Y9 w. U6 E6 v- g
}
5 ?0 [  u' D" R' m$ Q% j5 _9 ^- ereturn content + "</table>";5 y( }, r2 Z% R% F) w+ i; g, X
( m& l+ L0 ~. U+ T. ]

" x, ]$ x! w, _8 A# i$ N+ @/ p9 U. x; T% }

( y1 j4 d1 i9 L3 m  oC#  
( a5 @7 S0 _; }, r/ ^# cInnovator innovator = this.newInnovator();
' M& t; y7 E* x5 Q
8 h! E* Y4 O& J) \4 v5 Z; L& @. F// Set up the query Item.
) A) c( i0 \1 t6 m$ e. `5 L( C/ a% CItem qryItem = this.newItem("Part","get");
$ F1 L( x$ B7 u  ]( aqryItem.setAttribute("select","item_number,description,cost");
1 ^; A# M/ ^- z+ ]/ XqryItem.setID(myId); 5 o% a" A+ U, l- t

' A* p5 s& e! ^. g! c/ T  H3 I8 I// Add the BOM structure.
2 d. V5 g. f2 t1 b+ BItem bomItem = this.newItem("Part BOM","get");
  y# e- T( r" _( d  w; M8 TbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
0 n1 K" X, Q4 l5 I$ O# s5 n5 sqryItem.addRelationship(bomItem);
" f& R! J3 c4 m$ a
5 Q* |; n' y' y0 j5 f// Perform the query.
$ j1 t: O8 R; M' u" gItem results = qryItem.apply(); : v! _3 y# l- k- T6 C
7 j5 l) W0 J1 H, j: h1 c; \
// Test for an error. 7 \/ F8 x5 U1 P1 N
if (results.isError()) { 0 F3 e4 c$ h: ^" T4 k+ ]
  return innovator.newError("Item not found: " + results.getErrorDetail()); # g4 s( \& R( i& r5 a& H
}
" Q6 Z2 C' A! R0 G+ Z" [$ ?% O( g; \, ?
+ l4 c+ \5 ]" R6 U5 G* R// Get a handle to the BOM Items. + h- ]' R$ R( x. M
Item bomItems = results.getRelationships();
0 X* D2 E3 Y$ x) Z+ A( [int count = bomItems.getItemCount();   `# i; _! _* ?5 t( n$ I% E7 S
int i;
9 W+ A: d3 U. L% U
' A  L: V* I' Y3 f$ H// Create the results content. $ Y+ c; p. M. }* I0 H1 J2 p+ O' l
string content = "<table border='1'>" +
2 P8 _, ~; `/ ^  "<tr>" +
" ]6 C6 s! D- I6 ?9 A1 y1 L* r, {    "<td>Part Number</td>" +
5 D$ m, u& a1 k. l2 S    "<td>Description</td>" +
( G/ P7 \" h1 ~2 \  r6 r    "<td>Cost</td>" +
* k7 T5 @) g# Q& V: w    "<td>Quantity</td>" +   S) i8 ^% x7 y4 r" J
  "</tr>";
% g2 C  \9 T8 a- `2 ?8 u4 B1 |2 I 9 z  T# b( ~& c- U- H  q! c
// Iterate over the BOM Items. 5 y. p" u5 m/ ~, M
for (i=0; i<count; ++i) 9 D! f6 l. j& h, D# P' @3 r
{ 6 d7 A+ v: }/ C6 H. ?2 P
// Get a handle to the relationship Item by index. - Y+ w2 B6 ?" h- g
  Item bom = bomItems.getItemByIndex(i); . n3 T  V9 s! g. n  X
// Get a handle to the related Item for this relationship Item. + Z1 @; v6 H0 e+ n- n+ x
  Item bomPart = bom.getRelatedItem();
" h- u6 N8 S. n1 G+ J
0 E$ @2 d# }5 o5 T# G0 Q/ L6 w" [  content += "" +
+ a& P, m" q- n( C& d) ~    "<tr>" + 7 B( Y3 O! I8 b+ D1 F# [
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ! E) {4 A. H% g: C* P8 m7 C
      "<td>" + bomPart.getProperty("description") + "</td>" +
/ Z$ q# h8 p. g5 Z1 Q4 |      "<td>" + bomPart.getProperty("cost") + "</td>" +
* C6 o% y- P: `% I      "<td>" + bom.getProperty("quantity") + "</td>" +
' I! H# M- J, y8 F5 ~9 B    "</tr>";
/ {6 ^1 E. K8 ?$ \5 P  \} , M' O, |- d1 @* L) U# |: j
content += "</table>"; , Y: y* y& C) r6 y8 c7 h# V3 F
: S' G7 f; g, ]6 k
return innovator.newResult(content); # S% e9 m6 j0 t) v1 S5 _" X
5 f$ N* T# }8 j9 i9 o1 X
; O; b- V- E0 a& y3 I/ X6 z
' |" h, Z  `3 X1 A+ A

$ T, w7 O6 z, r; {, i
4 p7 W% P* s7 ]1 p- m7 g

1 Q& u' G% L# k" z9 ^# p; T# j& S 2 T% t0 F0 d& o6 P; y- r- Y2 Q
    Page 46
3 p1 O5 l* Y* F* c6 D/ f% S0 h/ U 7 K5 o/ p- ^: Z" A$ g0 d7 k
Copyright   2007
/ N7 C4 B2 g* t8 Q' {Aras Corporation.  * A5 C9 g  i4 z& G  V
All Rights Reserved. 4 Y0 s+ r) r4 A
VB.Net  ! B& K' ~" Q( ^2 A' E
Dim innovator As Innovator = Me.newInnovator()
% x4 n0 w! s& h" }5 e0 k2 ~5 m   q  |2 V; e; S9 ?
' Set up the query Item.
1 l: c1 G3 F% F" D3 tDim qryItem As Item = Me.newItem("Part","get") ' D6 ^, o8 N3 Q9 _
qryItem.setAttribute("select","item_number,description,cost")
3 K5 x0 Y( ^) D$ X# R0 s1 l$ JqryItem.setID(myId) 4 [. b. ?  `# S, |; Y7 P
/ ~" b; n7 K8 n
' Add the BOM structure. 7 f+ o1 U+ S  e" ]1 A
Dim bomItem As Item = Me.newItem("Part BOM","get")   ^! T9 J* P; A+ y, K2 O
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") : A8 Q4 I6 i' L. K
qryItem.addRelationship(bomItem)
* x4 H& l" |" Q, E2 i( ^: I' j, M) Y
( a: R! g8 }, b: s$ A/ O2 Q' Perform the query.
: X' X- S6 i  n, I# nDim results As Item = qryItem.apply() " }- {" J" i8 A" ^/ Z7 m8 n# m, T* ~, B

$ g$ O2 s# P: ^$ h1 J0 |. ]! `) \' Test for an error.
& }3 f2 \1 l- S; z3 R8 J! MIf results.isError() Then   u2 w' r6 |6 t8 C/ c7 A$ K
  Return innovator.newError(results.getErrorDetail())
; l6 |7 H8 N. V( R) ~End If ( \1 {& E; @1 f& N- I( x" X* B+ Z
. p0 i) ?& T/ w
' Get a handle to the BOM Items. ! c' k# V) e0 y8 _* g0 I- j& t
Dim bomItems As Item = results.getRelationships() 6 A( _8 I8 r* w2 R* `5 f+ _
Dim count As Integer = bomItems.getItemCount()
: W$ b! }" w: ]9 e( dDim i As Integer   G* s. B' ~% }/ a4 `! E

  s  a- G, l, @6 V" Q' Create the results content. ) J9 Y/ _: y2 x5 a/ E. O, A
Dim content As String = "<table border='1'>" + _ / z  t# e' s7 N; Y; m
  "<tr>" + _
( a. N0 I: ]! G5 z' O. P/ f    "<td>Part Number</td>" + _ % q" y1 s4 e8 s. J4 ^; z
    "<td>Description</td>" + _ . ^' h9 Q$ @( k4 b# `
    "<td>Cost</td>" + _ 6 w/ T6 @2 X6 q- M; w8 v
    "<td>Quantity</td>" + _
& N  t$ L: ^) w, F2 m" r- B  "</tr>"
1 B1 d- e7 \3 b" k- \* l
: g& D+ J6 F3 ]9 o1 `' Iterate over the BOM Items 4 D6 ^4 {9 O+ h( D4 {7 V9 G: L- {
For i = 0 To count - 1
, e# P9 {; n  n- A2 Q9 Q' Get a handle to the relationship Item by index.
1 \4 v5 k7 Z1 h% M6 D0 o  Dim bom As Item = bomItems.getItemByIndex(i)
6 i5 O1 r" i1 g1 j
8 f) t3 N/ i- x  a( o' Get a handle to the related Item for this relationship Item.
& i9 [8 c0 {; H5 S  Dim bomPart As Item = bom.getRelatedItem()
& D" g; t0 Z3 d7 h( c 1 V) [% I2 h4 A: E+ j+ S  v8 M
  content += _
9 b9 ]; r6 ]/ C" i9 L+ X    "<tr>" + _ / J# i. M8 U$ _, y
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
, X  y  u5 x4 c& V. |      "<td>" + bomPart.getProperty("description") + "</td>" + _
& i4 G% t( E: c& ?" A      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 4 X5 M9 x3 S* F' k# b7 p1 U
      "<td>" + bom.getProperty("quantity") + "</td>" + _ 9 k) ]2 b" `- W" b6 ~, c
    "</tr>"
& l) F' Q3 p* h& ]# J% NNext
. \+ z* Y  ]1 v% T+ Mcontent += "</table>"
1 j. h7 e6 i3 C6 |* q 0 \  s5 A, x/ O% [2 g  D
Return innovator.newResult(content) 1 p2 t; @" `& ]% G+ ]! C4 a1 F

* j& p* A9 u4 h( g5 {; x) L
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了