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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82170
QQ
发表于 2018-8-1 13:41:14 | 显示全部楼层 |阅读模式

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

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

x
Technique  $ D3 l( K3 a: ^, U  F5 J
To query for an Item and retrieve its structure you build the query as the structure " A& s6 e1 b/ J0 J/ j$ R
you want returned.  Use the IOM methods to add the relationships you want and ( ]" E% X) s# ?  C) i
build the structure in the Item.  The server will return the structure that follows the
) g/ @; ~! [7 X9 xrequest structure. 3 B3 t+ [/ C% b  M) B
This recipe illustrates several related concepts together, which are how to get a set
+ `! ~$ L+ ~# z1 Xof Items from an Item and how to iterate over the set, plus how to get the related 3 r; Y  e1 j  e+ `" D6 C4 S7 A' S
Item from the relationship Item. 8 x' Y" j& {& {' U1 V+ I
JavaScript  
/ y. l7 \+ J/ k0 ovar innovator = this.newInnovator();
5 a* `5 `6 `( ?, W% B3 k
4 ?3 q( F1 I1 ?" w* }# ?1 K// Set up the query Item. 4 ~2 O. j8 c7 t6 I5 n$ T1 q, t
var qryItem = this.newItem("Part","get");
7 R2 L! `" a6 U" ^qryItem.setAttribute("select","item_number,description,cost");
% R- H. b: r: |' Q' `; y, v  iqryItem.setID(myId); , S! @& m1 M* K# [. }
9 W9 ]6 r7 j7 ?
// Add the BOM structure.
+ _# U$ h3 I- f4 Hvar bomItem = this.newItem("Part BOM","get");
  Q. P$ ?! I$ A" L; u5 C9 l1 J2 b7 BbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
; L- }) n5 R+ O( ^; A  r" MqryItem.addRelationship(bomItem);
- U, R& A: s- W9 R3 c9 q: I* w
9 B, h/ Y! E  J, Y// Perform the query.
( E+ `% r* O- c7 F* fvar results = qryItem.apply();
1 p3 s$ l1 p: E5 e8 W5 B0 {: G 0 Y4 u3 p( v0 p( c/ L$ d0 B
// Test for an error.
" T2 t0 t7 p& V% e' }if (results.isError()) {
, ~8 r) _$ u- `  g, e  top.aras.AlertError("Item not found: " + results.getErrorDetail()); + R5 r( D/ `. N+ Q) N7 C: R6 r
  return;
. y' S: x5 a& J% f}
! H8 E; A! L% W$ B
1 e2 h" |" @5 r/ H/ B0 Y& |3 O: @) d// Get a handle to the BOM Items.
# j$ b* D1 m. p0 {; B  S0 Hvar bomItems = results.getRelationships(); + X, G9 \5 {" T( G1 b9 k. @# S
var count = bomItems.getItemCount();
7 ^7 D% V/ b  p  C
; ~# ^, v6 p! U: q3 V" [// Create the results content.
& N- D3 J% e5 W; ]' Gvar content = "<table border='1'>" + , v( |: H% W1 ^$ o
  "<tr>" +
$ p( n' R  ]: k: x    "<td>Part Number</td>" + 0 ?; W) L/ H: \1 A0 ^' U0 f
    "<td>Description</td>" +
# {. V0 u" K% D! F  o    "<td>Cost</td>" + 7 {2 h+ F9 ?$ K) e) W$ L) g
    "<td>Quantity</td>" +
, Z2 H+ k# \# T5 K5 R# z  "</tr>"; ; D0 w8 Q7 C# g+ N" S
- A3 D3 v/ q" z
// Iterate over the BOM Items. # F% `0 A; y7 q( y7 T" d+ h
for (var i=0; i<count; ++i) 8 r6 }1 r2 E3 A; }
{ . z& [* v& C! T: O: B; l3 g; a% Z% w* [
// Get a handle to the relationship Item by index. : u; C# ~( k* n
  var bom = bomItems.getItemByIndex(i);
6 T2 y0 n+ Y( E1 B, v8 k// Get a handle to the related Item for this relationship Item.
, V- b7 O( Q; ^1 |" r) E. N  var bomPart = bom.getRelatedItem(); . _3 G& K  g" s/ s2 O4 S9 g& y

* k! H! J; Z. e* z4 \9 R  content += "<tr>" +
/ Z* _( ^3 ]5 r8 f; D5 G0 c! ]      "<td>" + bomPart.getProperty("item_number") + "</td>" + / j$ }( S7 m# Q* _( M% H( d! e* d
      "<td>" + bomPart.getProperty("description") + "</td>" + + d6 r" p- z! ~3 Z
      "<td>" + bomPart.getProperty("cost") + "</td>" +
$ R- @- f1 |; b$ g. `      "<td>" + bom.getProperty("quantity") + "</td>" + 5 U3 W5 X' S$ k; I+ Q# d3 _
    "</tr>"; * _) w8 h% C+ |, x/ e
}
1 D6 T. h9 m( E6 b' ?, Sreturn content + "</table>";
8 @+ f4 \3 T  j% a/ l$ e3 p5 k" Z# j# _, `+ {: G
6 I4 |) S5 n: j8 C4 m) X7 `

1 A5 C8 P4 B" Q0 P0 ^

5 e% J- Z  q( J- D4 m: SC#  + U$ [  Z8 P- w1 c
Innovator innovator = this.newInnovator();
7 @3 f! M, j2 {% f / t1 \2 d4 O+ K* E+ ~
// Set up the query Item.
- D0 W6 O& P5 N$ a( WItem qryItem = this.newItem("Part","get"); 7 \0 h4 n" Y# z. d' G
qryItem.setAttribute("select","item_number,description,cost"); 1 J* R3 T' A) T' L% C- U  ^# b: M
qryItem.setID(myId); 5 d: E7 C+ @1 g5 ]8 x' \

2 j; @2 F9 W  p9 |6 _2 P5 p8 M// Add the BOM structure.
: ]4 M7 I3 Y/ qItem bomItem = this.newItem("Part BOM","get");
  I3 g$ F8 S0 o/ K; W  c9 ibomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ' p' {- ?9 l9 Y/ }6 W
qryItem.addRelationship(bomItem); ) C3 o' `, p% \7 ^. `4 }! O

$ a4 B4 Z  l: f4 f; u// Perform the query. ) B. e9 [- l+ \& u  V3 }6 c
Item results = qryItem.apply();
1 j4 ~4 H7 L2 C7 N) P2 }
( l4 p+ r# D& U5 l0 O6 X// Test for an error.
6 ^- Z5 ?; V1 |1 _6 J$ y; Fif (results.isError()) {
8 h, f) ^" R6 V0 t2 F( M  return innovator.newError("Item not found: " + results.getErrorDetail()); 0 Z' }& w' k, q- p3 `- O
}
' D2 D0 a& u5 f$ \$ | " U. I, B1 U1 u1 T4 D' ~
// Get a handle to the BOM Items. 8 d6 ?% C. ~) a7 w! D; u. q) M
Item bomItems = results.getRelationships();
1 g5 R& W  l& z, Yint count = bomItems.getItemCount(); $ M" A5 n/ |7 t$ B7 [4 i9 s. r9 G
int i;
+ ?! A, W" [4 z1 M * G( l4 O; c& J. X  j7 R7 @+ F' A
// Create the results content. + v$ L9 y) u; G  w1 ?; _
string content = "<table border='1'>" + ( E- D+ \/ }1 H1 q% U# m9 L9 W
  "<tr>" + 0 q" N8 o. t0 N
    "<td>Part Number</td>" + ! M7 ^5 ?- Z5 w" d5 b, v
    "<td>Description</td>" + & K3 }7 P5 n8 D5 |1 }
    "<td>Cost</td>" + / s4 R( i; q) k" i
    "<td>Quantity</td>" + + w' d+ A( B+ g4 ^' [% A
  "</tr>"; ; D9 B+ f, y& g' M7 @( ^
/ O& I: }; [# T2 |5 p- @# K; D
// Iterate over the BOM Items. 0 g' {  v' n( u* Y1 J
for (i=0; i<count; ++i) $ h% G/ A% Y0 \, l0 ^) R
{
6 @+ E8 M. M2 L7 k& {// Get a handle to the relationship Item by index.
4 R2 C6 `6 h) I( q- J. ?5 K6 \  Item bom = bomItems.getItemByIndex(i);
3 o1 ^% B* K0 ~, h4 ?// Get a handle to the related Item for this relationship Item.
0 C* D1 l6 ?( y  Item bomPart = bom.getRelatedItem(); ; _9 t& ]7 g  O, q2 Z

. r5 {6 l5 L9 |4 P% R& w  content += "" + ( ]7 j9 @' {; H! M5 _3 Z# A
    "<tr>" + ( b4 W. ~5 c/ C1 F5 l
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
! |- M6 h2 I4 D      "<td>" + bomPart.getProperty("description") + "</td>" +
4 c! l4 P$ w' P! a& G      "<td>" + bomPart.getProperty("cost") + "</td>" + 4 _/ S6 @" [+ B
      "<td>" + bom.getProperty("quantity") + "</td>" +
+ L6 p9 a- ?& C* k4 @% a% ~% D    "</tr>"; 2 I# E. T! t- o1 g
} " s; }/ o/ |+ @  b# W: q. T
content += "</table>"; . x" a  L$ p9 V4 c
# [) v3 @* f) ?9 G
return innovator.newResult(content);
* w3 P; ~0 F$ l6 L; e# A
# u  [- Z9 d: |$ n
: ?% Y" n+ p3 E6 o

) [" s+ L# E7 R6 W% r+ a4 U% Y

( a% N/ B7 o8 c, Z
# K8 q, Y  I: W2 X
  d3 P3 ^7 c4 r3 o& S; W, k4 c9 J

( {7 q4 c: j& n7 [8 Y    Page 46
/ C/ ]$ N1 Z4 J0 K" `) A
7 r  E2 U! L* p& T$ s0 \- K; pCopyright   2007 / \$ ~& P/ A5 |/ [
Aras Corporation.  % j) {* F! z9 v( V9 _2 F& F) W
All Rights Reserved.
, E6 L+ a8 W3 a6 }VB.Net  / b. k. b! O" j
Dim innovator As Innovator = Me.newInnovator()
" b# M1 r; Z* N. U; L$ t- D6 G 7 r. l/ M% y2 y
' Set up the query Item.
7 d4 K8 ^8 W; z( }/ lDim qryItem As Item = Me.newItem("Part","get") 8 D( y/ P( s. J$ r( E5 o
qryItem.setAttribute("select","item_number,description,cost") 4 Z& B2 E) K3 [! C; }0 s+ E
qryItem.setID(myId)
' M( V. }& d) }( V
  M) k8 y: t8 N: j+ h- v% {, L7 s' Add the BOM structure. 5 k! G2 g: f) I' ]$ l0 k
Dim bomItem As Item = Me.newItem("Part BOM","get")
1 D; Y- t2 {  [* b5 W2 M) O5 YbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 9 O1 h0 z) M) O/ B- F9 L
qryItem.addRelationship(bomItem) : G- z* A/ H, A: x% K5 b
2 s  u4 L9 C; A' y: H
' Perform the query. ) x+ H4 t* y( B" T3 q
Dim results As Item = qryItem.apply()
1 r" [+ {; j# I6 a6 R
$ u! B; @' l3 f5 q! `' Test for an error. 1 ?$ _4 [& h, }, G3 Z1 S3 w" d# b- i
If results.isError() Then 9 L% A8 f# g3 t/ i- q
  Return innovator.newError(results.getErrorDetail()) - t( Q/ c- b# M7 E, ~6 ?
End If + a0 c5 T0 i% t9 u3 t- f) x( {

1 l9 v8 ?/ o; l+ S/ n2 U' Get a handle to the BOM Items. - N, s& i  A% N/ {* p5 m2 g  a
Dim bomItems As Item = results.getRelationships() 3 Q7 x4 g$ F& t
Dim count As Integer = bomItems.getItemCount() ; L8 M1 L' U0 g7 k& p/ z; T4 W. O
Dim i As Integer - g/ g& ]! q8 I

; ^+ }% Q! `/ N2 O/ j' s' Create the results content.
( y! ~  E: Z( i$ @) \+ zDim content As String = "<table border='1'>" + _ 4 X$ Q' v; k$ a. i
  "<tr>" + _ 9 x" k; s$ Z# z7 c5 m
    "<td>Part Number</td>" + _ + p+ q% D8 v7 _( j( V
    "<td>Description</td>" + _ 5 x( c9 i5 [# v9 a! B1 |
    "<td>Cost</td>" + _ 8 U; N0 _% g2 y8 d; e4 l
    "<td>Quantity</td>" + _
* D/ _' A6 d& d5 B  "</tr>" ' d" \! V* }7 C; I4 {

* D9 x3 U1 X: V& T2 ]) M- \) z7 D' Iterate over the BOM Items
, h# I- i- q) H0 U) EFor i = 0 To count - 1 / i* I! l  Y; H) x
' Get a handle to the relationship Item by index. ; n2 H4 r! m+ F4 W9 C4 `2 ]" M
  Dim bom As Item = bomItems.getItemByIndex(i)
; w1 r3 z0 Z7 ^) M6 A* k
7 J/ y5 l, l6 x6 w/ R( _' Get a handle to the related Item for this relationship Item.
# p& j: C) E* B( k+ t+ _8 L& S& `  Dim bomPart As Item = bom.getRelatedItem()
- U( e' R* \9 H3 e+ N , {+ x' D0 b( B  T% N
  content += _ % W/ @6 j# {, B6 q% H2 ~
    "<tr>" + _
) Q: I2 ]1 C, z' |3 O      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 2 B" Q' ^' q' E! Q5 o5 w
      "<td>" + bomPart.getProperty("description") + "</td>" + _ . l# b% X3 W* L. f& E4 X
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 5 D! Q1 w  l1 Y6 d" g
      "<td>" + bom.getProperty("quantity") + "</td>" + _
. n  g/ G9 ^& C8 S0 \, }    "</tr>"
$ q4 J2 j3 C: W8 m- b1 `6 aNext 0 I* B) ~( Z0 G# Y/ D- ]
content += "</table>" + e2 N8 A+ `' ?$ ~6 v* r. x
0 `. K( k$ v) k9 d+ a8 Z. z1 w
Return innovator.newResult(content)
% T5 m4 G- `: U8 N9 }+ T# }+ A6 @% }; d
3 }7 \* \3 e: _5 q( g' {$ q3 @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了