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

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

[复制链接]

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

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

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

x
Technique  ! F* t$ z* G  U* [
To query for an Item and retrieve its structure you build the query as the structure : B5 |& x5 q" ?, I
you want returned.  Use the IOM methods to add the relationships you want and   Q. d7 L, m& g3 {! }* ?
build the structure in the Item.  The server will return the structure that follows the 8 f" N* j4 h/ X& i# u! M4 O
request structure.
6 }- }( b% r  `This recipe illustrates several related concepts together, which are how to get a set
- ]4 m5 L+ R. v* X- ~of Items from an Item and how to iterate over the set, plus how to get the related # |  K7 Z* i) g. X( K; ^$ @+ }
Item from the relationship Item. ; B( K% R( G% S! o2 d
JavaScript  
) R/ r( ]0 O! _var innovator = this.newInnovator();
) n3 g( z; o8 t" | & Q0 C6 ]" F$ I5 m
// Set up the query Item. 7 F& c" ?7 t$ c- q& \
var qryItem = this.newItem("Part","get");
0 j" J0 _5 I! J5 |! ~8 Z$ OqryItem.setAttribute("select","item_number,description,cost");
0 {  f; {* \6 U  t/ OqryItem.setID(myId);
4 }4 O, J. D9 V" D2 |
& X! V3 }$ A" U- E# H// Add the BOM structure.
$ F, S1 q  w7 bvar bomItem = this.newItem("Part BOM","get"); % z! G) |8 C  q8 C9 E0 ^
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); * y2 M$ e( u" d, Y
qryItem.addRelationship(bomItem); + v; i  ]+ f! s' I+ i0 N" s) A( s

" b! D2 T( Y- I+ `; Z% t// Perform the query. 9 T% L9 ?1 ?( r! ?
var results = qryItem.apply(); 2 |/ |, {4 s( M2 T. j$ T; j
) b( V3 q0 ]: B# k
// Test for an error. % g3 ^6 B* d0 m6 T
if (results.isError()) {
4 ?$ f' O  F* j; Y3 x  top.aras.AlertError("Item not found: " + results.getErrorDetail()); # T$ f9 p, b2 @( Q
  return;
! P# \% j2 e1 e2 T1 V, J}
, T7 s# C& N" M" o 5 [2 d2 Y7 z; g8 {* c+ X* |
// Get a handle to the BOM Items. 8 c$ l2 o$ q' B. y. e
var bomItems = results.getRelationships(); # z, H5 A4 Z# ^
var count = bomItems.getItemCount(); 2 j; B; M& M! a' J4 L% l
" n1 k# g4 g2 q& c3 x. n$ m/ Q/ H
// Create the results content.
4 }9 c! O* G; y- |' N/ \0 }var content = "<table border='1'>" +
) [, H9 X8 d3 m- L% z, ^  "<tr>" + 5 Q+ \* k7 O# ^8 }% p/ z
    "<td>Part Number</td>" +
$ V# E$ g4 w4 ]; l: X. w    "<td>Description</td>" +
8 v9 `7 P5 C9 L) F! ]2 E    "<td>Cost</td>" +
4 O; I; p/ S# R# p8 H' p    "<td>Quantity</td>" + # N& [. O0 D, ~/ P; f
  "</tr>";
- }1 h3 T) n  z0 n5 U4 G
5 V5 U  R$ L6 I1 u) M// Iterate over the BOM Items. 6 }0 N* X" z& u, {/ W( C  F
for (var i=0; i<count; ++i) + W/ A& B- A6 s9 {
{ ) s( a! P" S6 K; B4 O! I9 s
// Get a handle to the relationship Item by index.
- a# X4 _5 o- o& N  r0 ]7 \+ r  var bom = bomItems.getItemByIndex(i); 5 J. _( `- j; l9 Q3 ?7 x& E7 a
// Get a handle to the related Item for this relationship Item.
2 C: A5 m- F! g( V  var bomPart = bom.getRelatedItem(); 7 W8 R% Q9 m+ _

  S$ M) r* U. u, K  content += "<tr>" +
- g# g4 L: m6 E* B# U+ ^5 f      "<td>" + bomPart.getProperty("item_number") + "</td>" + ; j$ ^9 o% O+ r8 E( u+ r& u" o
      "<td>" + bomPart.getProperty("description") + "</td>" + 7 V) Y8 f4 A9 o) }
      "<td>" + bomPart.getProperty("cost") + "</td>" + / G3 B5 ^1 R# G9 }& F9 Z# J
      "<td>" + bom.getProperty("quantity") + "</td>" +
/ L5 t1 ?" I  [" Z& g    "</tr>"; 7 S- c: G* h$ _, K5 K: H) w$ ]* E
} ; T) y! o4 i5 y* s$ j- v, ]* t0 k
return content + "</table>";9 D& p8 W- x1 h5 l
* V$ a: j- ^" X0 b) ?2 i/ i& I, p

- Q6 k0 N* W  j% `2 W& K- L- d3 Y) u/ t" Q

  Z1 A% p8 k: E8 n/ ?+ {0 GC#  
$ }0 \5 B9 H4 L  k" q: {6 sInnovator innovator = this.newInnovator(); * w; w5 J* H! O4 \  \

7 |/ J2 D. _* I// Set up the query Item.
+ |. h6 u( {" x& Y6 ^% z4 D& Q+ EItem qryItem = this.newItem("Part","get");
! @) Y. u' O% @/ X5 h3 M6 fqryItem.setAttribute("select","item_number,description,cost"); 7 A: E, @+ K6 d  G! X9 @3 v
qryItem.setID(myId); # K5 a$ U# {2 b  K7 q
# e- n$ W! E3 G. E
// Add the BOM structure. 4 U/ N. |! n: \
Item bomItem = this.newItem("Part BOM","get"); ; {9 n6 }9 \$ ~) X6 u. T# n- l
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); $ d% P7 c, Y  i) v6 u) \
qryItem.addRelationship(bomItem); " |; _, U3 V, Z
; n  h7 b" B0 D: L7 J9 f+ O' {
// Perform the query. * q9 z2 s3 [$ m3 ?* {9 \) R
Item results = qryItem.apply(); . Z' @. ^2 J" p" }* p: j: |$ e

9 @$ u; ^8 }7 w- u/ Z4 b// Test for an error.
; {+ P: G+ w8 j- ]' a' S* \if (results.isError()) {
1 j8 q7 y3 I- `4 V" ~( @6 f  return innovator.newError("Item not found: " + results.getErrorDetail()); % A' W( K4 X- c" U( ^, @
}
& i* T, Y+ L7 o, Q, h* W
6 m& C; ~  S5 U7 h. P$ @, J% o// Get a handle to the BOM Items.
! p3 X! C8 a( Z9 i# AItem bomItems = results.getRelationships(); 8 I: w8 o: m6 p' c
int count = bomItems.getItemCount(); + x$ ~4 a9 {* p; a& e7 @
int i;
/ f: ]' ^+ q& o. b* G1 J
6 |  q: U1 Q6 j) }2 A% w- c. a+ J// Create the results content. / E7 H: F( p$ n$ Q& e, e  y) l( L
string content = "<table border='1'>" + # x/ d$ l5 L3 O
  "<tr>" + ( L6 X  k9 J9 X2 E
    "<td>Part Number</td>" +
* R/ P7 j" ^5 O. }. z% a- O" j    "<td>Description</td>" + & w$ k2 G9 A) C( N& U* p
    "<td>Cost</td>" +
+ ?% e5 F! d! ?9 I1 m- {- S3 |    "<td>Quantity</td>" +
2 J$ G' K: Y+ v9 s7 b  "</tr>";
* E  p1 C3 L" ?4 q4 V: V# A
4 z0 g0 G6 v- V$ `, S// Iterate over the BOM Items.
$ t) N, ^: x8 \$ d) W4 r1 P6 sfor (i=0; i<count; ++i)
. {5 J/ S1 s7 A{
9 y1 X/ x* J/ T- `1 k/ V, C0 e// Get a handle to the relationship Item by index.
+ J5 S% l/ {8 v* u8 @" F  @  Item bom = bomItems.getItemByIndex(i);
+ O/ Z. ]  t& I& K6 l( D# p// Get a handle to the related Item for this relationship Item.
9 D# t4 d- X  D. H6 r# U2 l; T  Item bomPart = bom.getRelatedItem(); # t& n$ v7 v6 Z& Q

4 u% o1 d. n! R/ j5 X  content += "" + + ^1 _* \' h: f) x0 \
    "<tr>" +
/ p3 x, d2 t/ V% J7 k      "<td>" + bomPart.getProperty("item_number") + "</td>" +
3 V8 x9 I5 q* i7 f      "<td>" + bomPart.getProperty("description") + "</td>" +
2 N! z8 u% t* D2 a" J+ q5 P/ @+ Z      "<td>" + bomPart.getProperty("cost") + "</td>" + % _: N- W, {& f* @  w3 h
      "<td>" + bom.getProperty("quantity") + "</td>" + 9 q+ l$ e! I- H  }" @* v
    "</tr>";
' T; P+ N# D$ T; F: o" Z}
; \! h9 B& O+ D# {3 o8 Scontent += "</table>"; 6 n4 P, ?. r+ m+ E% S2 ~
+ F; O% ?. M' B6 R2 V5 a7 o
return innovator.newResult(content);
# R5 L8 K) r  O+ F
3 R5 Z4 @( g! N, k) G
6 Y, \: c6 p2 [! o8 x7 {- j

* w6 E& E" ?1 I( d2 L
- d, }: d5 Q3 g. v" T. t$ j
' \$ M1 v% W0 Q, x
3 q, K% [7 l- r  b9 o2 K8 T

! m: }6 W4 G; g! a+ [, p  g    Page 46 $ N( R3 y5 }. w( Y9 @

4 j; D6 j- P. v& ?- \Copyright   2007 7 a" d& D; [* }0 w6 M, U
Aras Corporation.  / e- y7 p; m1 M' V, H- ^) P
All Rights Reserved. ) @$ `6 R& F3 E: U! b4 a; e2 ]
VB.Net  ! r6 G  g, G" _! d) f
Dim innovator As Innovator = Me.newInnovator() 6 {. x* Z/ a, q5 J/ R5 k5 ~7 A+ P
6 D3 `/ Z, Q- C' ~* T$ E
' Set up the query Item.
4 g% o1 w  P9 w, v; {8 Y+ J: aDim qryItem As Item = Me.newItem("Part","get") - e. }% e8 |- t( L$ G# w* Z
qryItem.setAttribute("select","item_number,description,cost") 1 a/ ~& }+ ?9 b2 R7 N+ O9 Y
qryItem.setID(myId) 7 a3 z) x* B5 e3 u, V. i
8 t9 R1 `+ w% w# _  _3 r1 V& Y
' Add the BOM structure. ' s* }; a2 E+ N3 `
Dim bomItem As Item = Me.newItem("Part BOM","get") " z4 b+ O  e8 L, c" l7 a
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
0 M! c1 k' e6 RqryItem.addRelationship(bomItem) & `8 W* ?- f; u* }; o4 ]6 z0 N
+ p9 d- R; Q' r7 s
' Perform the query.   J' {7 j( s& C
Dim results As Item = qryItem.apply() % H3 I) [0 v$ `
2 S0 r9 D$ L: E$ ?- u. n+ _( N; u: p
' Test for an error.
9 _# L: \" h! Q6 D! R6 Q( Y9 dIf results.isError() Then
$ N' f9 D. A8 h* a  Return innovator.newError(results.getErrorDetail()) ( C$ m! T8 i: _* t' F1 z
End If
3 f) Q6 a0 {9 v ) {+ P! t7 g9 U+ C: ~
' Get a handle to the BOM Items.
2 X8 E( O  F" YDim bomItems As Item = results.getRelationships() : w: j1 @; ^+ ^7 w: [
Dim count As Integer = bomItems.getItemCount() ; k0 V  B4 {- o/ `# W
Dim i As Integer
$ g, e1 w, `" g3 r* F
+ ^* S2 C4 |2 X; ~! O: J' Create the results content. 5 F% k# x% F" X, f; i! L
Dim content As String = "<table border='1'>" + _ / u( W* ?4 ^- M* Y) g
  "<tr>" + _ $ W/ d" y5 g& x- [$ D, b
    "<td>Part Number</td>" + _ 7 I& K) f$ B* q8 \: P$ U2 ?
    "<td>Description</td>" + _
4 [. {0 S0 g3 Z9 r4 E, h+ k    "<td>Cost</td>" + _
* q4 y+ I4 Q3 L    "<td>Quantity</td>" + _
# @7 M- f8 s% K* m- t  "</tr>" ! ~! ^3 W0 W  w, i: a! Q8 |0 W

0 Z6 l; w9 F" I( B, z' Iterate over the BOM Items
& o7 @: h; B/ qFor i = 0 To count - 1
6 b! Q+ Q, z. u# d) v' Get a handle to the relationship Item by index.
8 j* k3 ]) L4 p9 [% |! v, e  Dim bom As Item = bomItems.getItemByIndex(i)
% ?" D9 p- y. P# o% G4 [) C
! s& ^7 C% {0 Q, w: v' Get a handle to the related Item for this relationship Item. ( `) B0 S; g$ h0 h; e. {$ N
  Dim bomPart As Item = bom.getRelatedItem() 2 N. v. i9 G4 r3 r: S/ o3 C

' S' e$ \* s  h2 ^! t  B  content += _
3 J2 ^/ W5 i& x, Q# u8 N+ O' b    "<tr>" + _
8 A4 _& X' D. y# k      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 6 j: i7 Z. t% X2 ~( i" G; O
      "<td>" + bomPart.getProperty("description") + "</td>" + _ , R$ a) ?& R# \; ?
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ % m4 C2 ~% R9 b0 h" {
      "<td>" + bom.getProperty("quantity") + "</td>" + _
2 ]# g/ W5 }( A/ u' R    "</tr>" 9 X" ?4 H- u8 }4 v; Q
Next
3 k; R' o+ }: Z" q. z+ |3 Wcontent += "</table>"
8 {3 z) {5 y$ R% U- O! p
3 B  Z' `( g) D  hReturn innovator.newResult(content) : t( ^) [  K1 S0 e& f; |( c
. v" B0 v& i, b/ \# e% `+ m8 I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了