查看: 1970|回复: 0

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

[复制链接]

4

主题

3

回帖

40

积分

管理员

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

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

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

×
Technique  
- L3 G% ]" [% j+ V- t$ WTo query for an Item and retrieve its structure you build the query as the structure
4 R5 P) ^$ J7 p# ], f+ u- wyou want returned.  Use the IOM methods to add the relationships you want and ; w0 B1 ?. t/ I9 z7 V; m# {; @
build the structure in the Item.  The server will return the structure that follows the
5 Z: m8 B6 R2 g6 \1 j9 jrequest structure.
6 n9 W# l* b8 D$ _% v, h! KThis recipe illustrates several related concepts together, which are how to get a set
% q% b  [' ]' V1 U  jof Items from an Item and how to iterate over the set, plus how to get the related 1 E5 f( C( V  G7 f) I2 H3 i
Item from the relationship Item.
- m8 \! f- R9 ?! XJavaScript  
% p: {( D( V# g# b" B, l- M1 Uvar innovator = this.newInnovator(); 2 e- o$ F& d6 X6 f) I
3 j# M  d  R2 p, k& {  I, S( R
// Set up the query Item. 1 B6 O* w7 b5 y& M# J6 v( `$ |5 I% L
var qryItem = this.newItem("Part","get"); 6 H1 K! T: g+ H4 Y  v$ L/ _
qryItem.setAttribute("select","item_number,description,cost");
+ t7 v; e1 b0 J6 a/ w. [qryItem.setID(myId); , ~3 V2 f; Y, v2 d, I- c' V' e

6 K+ g+ x' X. G  t7 G& x// Add the BOM structure.
# t/ |4 u/ }: a& Ivar bomItem = this.newItem("Part BOM","get"); ' d# |" `8 \6 q& ]; e# w* w/ {9 B' D
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
& E( C% {4 J! j3 jqryItem.addRelationship(bomItem);
" b( |" I( N6 f- {, j + |0 V  x. @# E' p
// Perform the query.
9 H8 I! \  P' O" W5 ^var results = qryItem.apply(); ! \' D. |% H" ^6 Q+ E; G5 a
7 d+ X- a9 ^( A2 I+ Y1 e/ d' W
// Test for an error.
+ W: X! U% w3 M  zif (results.isError()) {
- [+ x5 p: o# F; N2 x+ h4 s- t  top.aras.AlertError("Item not found: " + results.getErrorDetail());
8 }# a% ~# d: e2 l; m, N% s  return;
# @% K6 r. ]/ ?1 A, f& s} 8 u% i0 ^) J5 f5 j" z# [

) e+ b9 j2 Z+ V* T// Get a handle to the BOM Items.
7 \% J+ ]! q. @$ ?$ ]) h2 bvar bomItems = results.getRelationships(); , u& V1 @- d0 h) Q
var count = bomItems.getItemCount();
! a- i8 F0 o* v! O8 e: m 2 L5 I6 j, R- u! M1 x3 f. ]
// Create the results content. ; I, X+ k* U/ n2 h$ g
var content = "<table border='1'>" +
8 Z5 D+ |# E* W4 Q# i$ j7 B  "<tr>" +
6 y0 w4 Q7 \) V    "<td>Part Number</td>" + 8 D0 @. A8 O9 ]& m/ @# {1 Y
    "<td>Description</td>" +
' q7 ?( a+ R& V. ]    "<td>Cost</td>" +
& q* I0 }3 c: b( ^( k9 x/ R( C, e    "<td>Quantity</td>" +
9 [% s- e( z) B1 X8 V3 P' s  "</tr>";
* f& V% z( c' x: a: \  _$ K
3 U8 q' ~) U5 {// Iterate over the BOM Items.
6 Y# L" U- ]$ u' cfor (var i=0; i<count; ++i) * F7 E" `# A0 a/ }( ^  D
{
9 s! D/ r/ J* m* a( Q8 Z( C// Get a handle to the relationship Item by index.
: T! X8 j( P, q; G  i* }  var bom = bomItems.getItemByIndex(i);
4 M+ [1 e' O1 B. S6 Z0 n  C' `// Get a handle to the related Item for this relationship Item.
9 |: M# Z; W: [6 t: ]! n  var bomPart = bom.getRelatedItem();
* i9 _/ [, ~0 p6 R) {4 p
6 E) D# N7 I2 H  content += "<tr>" + ) t; d$ o% U4 Y! N: t, W% d6 Z. Y/ ]0 S
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ' V+ t' Z( v4 F; l, _7 t6 F, V. ?
      "<td>" + bomPart.getProperty("description") + "</td>" +   d; j5 ?( m+ r" t1 |
      "<td>" + bomPart.getProperty("cost") + "</td>" + # W, Q7 C" E' O
      "<td>" + bom.getProperty("quantity") + "</td>" + : P( I) h& F# W3 Y
    "</tr>";
1 G8 d8 B, @0 E2 U$ j9 {' m6 z}
/ G3 l3 y" F4 d% ~. wreturn content + "</table>";
8 }% A# @! i# U2 y6 U2 g4 L0 J( |; e7 [' H2 I! r

% e/ x$ X1 i' n7 K( P# f' x+ k8 m' t+ _7 [
5 d" b, m0 u- v2 K& }
C#  
1 P9 f" l8 \9 h5 S: U0 HInnovator innovator = this.newInnovator();
1 k5 V5 H. ^/ G+ s* { - E( T0 [+ Z8 }7 l1 l7 T
// Set up the query Item. 0 @4 D) M$ j$ d  n
Item qryItem = this.newItem("Part","get"); ! U, ~8 b* q; \, z
qryItem.setAttribute("select","item_number,description,cost");
) x* u! b, c, Y* |qryItem.setID(myId); : `+ P8 ]' f+ Q( M( b4 V& \& A# o, l8 W

4 R% @) L* S5 |+ p: }9 P5 N% f' N% g// Add the BOM structure. 9 l3 U7 ?4 C9 ~! U. \
Item bomItem = this.newItem("Part BOM","get");
  [1 ^9 {: D2 A2 }8 bbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
6 t0 t2 E! k/ L6 ~8 ]qryItem.addRelationship(bomItem); " q" y+ z) D3 e, S; x: I
7 i" i2 u6 u; P  P
// Perform the query. # ~- q$ ^) d% M
Item results = qryItem.apply();
8 _5 q5 d5 y; X" W8 a 5 T$ D/ G5 I7 Z/ |
// Test for an error. 8 V' t; T: S$ j+ ]$ f
if (results.isError()) {
! I( {4 ?! @7 B* h6 i  return innovator.newError("Item not found: " + results.getErrorDetail());
( p8 k7 o5 V8 f}
; y$ o! x$ ]! `- k* }! x& e$ m3 b $ t* u7 `9 B' g
// Get a handle to the BOM Items.
# Q! W4 }5 r$ [! R! l; C+ oItem bomItems = results.getRelationships(); % N- Z3 S( M8 M- b! T7 y- i. Y
int count = bomItems.getItemCount(); : k% G: _+ m& h) r7 H
int i;
2 C$ a* b+ K+ Y ' p  \* ~2 p$ ^- q4 H; o
// Create the results content. & n2 L3 W4 a2 L# U3 O
string content = "<table border='1'>" + 9 H" l  a0 s8 V' k
  "<tr>" +
5 R: ^& p/ |7 P/ `; U    "<td>Part Number</td>" + : }0 I3 o# ]2 }2 k
    "<td>Description</td>" +
, y; g  m3 S% w' z! l( U4 o1 A. a    "<td>Cost</td>" +
* ^! X4 V4 w. Y" K6 f; F2 i  ^! H    "<td>Quantity</td>" +
6 v; e( n$ N& _! r  "</tr>"; & W6 o% q9 A* k4 H" Q! c) @2 q

  J# Q: F. q+ U, G% m  v4 f4 S8 S# A& K// Iterate over the BOM Items.
9 g' M6 ^2 ]% I) x- {% o- `4 cfor (i=0; i<count; ++i)
9 ?; m* x5 O% [' S' B{
$ l# h* l$ m; `; W/ |& q8 u. P! V// Get a handle to the relationship Item by index.
$ _& C& o6 ^: C( Q7 w, a( z; u; D2 t2 [. S  Item bom = bomItems.getItemByIndex(i); 9 X7 z) ?7 q* b" q1 n( i9 t# u
// Get a handle to the related Item for this relationship Item.
# x" k8 L' W1 d  Item bomPart = bom.getRelatedItem();
0 K+ Z5 R0 z0 n& O+ l0 s
# h) ~# u6 t: N# W  content += "" + - N/ l' U3 B$ n8 Y7 {
    "<tr>" + 6 u+ A7 ~0 t/ ?5 s
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 v8 t% o" c8 A$ K8 R5 o! U+ |6 h      "<td>" + bomPart.getProperty("description") + "</td>" +
) c. @- ]  g/ o+ h) E      "<td>" + bomPart.getProperty("cost") + "</td>" + 1 k8 A- H. L0 M: u: t4 `
      "<td>" + bom.getProperty("quantity") + "</td>" +
7 X# d' s8 ^/ O; l    "</tr>";
. ^4 o+ C7 p% i- c3 s, I: P6 v! |% g9 f} . h$ x1 g  x- s$ j/ e
content += "</table>";
- d% t4 X: C8 {( `3 T4 n8 g
  g3 V& i6 ]( areturn innovator.newResult(content); . O! L1 L# }% ]

" c6 R2 u5 D# `: N

! z. q. s  ?# d4 Y2 c+ a# A0 C. q; }$ Q8 ^8 m% T
& a% |- e9 X2 Y% \6 u

4 m) F: O& b5 y- N" Q
5 O9 W4 A- c# q) ~, k$ Y

# o& v! y$ p' g) s; _8 j$ ?: h  I    Page 46 + x$ \0 O, a1 a( Y9 v6 i
! g% Z9 M, v- d
Copyright   2007
5 e4 x2 C- a" _: ~6 VAras Corporation.  ' o3 n6 v9 ~: r+ o4 `( w
All Rights Reserved. ! P1 k. l* m) r+ I0 Y7 h" z
VB.Net  
. O: F9 x2 r* i7 X0 J8 S, w+ }Dim innovator As Innovator = Me.newInnovator() . y  B3 P( O/ j1 M; M, W; f* x

, B8 ^) ]6 \1 p( T) k, Z, Y' Set up the query Item. * ^- _/ g4 M  H/ Y. ~/ m
Dim qryItem As Item = Me.newItem("Part","get") 1 r5 M1 c1 s$ L9 `+ q' R" j( `
qryItem.setAttribute("select","item_number,description,cost") 2 c3 W5 _3 r! P9 a# o& l" m
qryItem.setID(myId) 1 X$ O) p. S/ \" Y( q
( B8 G% g* F& K% ]( I9 b0 O3 R
' Add the BOM structure. 6 C! @5 N: m' R: t
Dim bomItem As Item = Me.newItem("Part BOM","get") * H# `/ M& u8 d5 X) h" K, X
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
/ q9 J: ^0 q! t5 q$ K* J2 C! G- lqryItem.addRelationship(bomItem) * S$ R, s: f8 P  k' W

3 w! ]: q, v9 F' Perform the query. & t6 ?* L/ Q8 q7 ^' W
Dim results As Item = qryItem.apply()
7 {  a' H6 y' N$ {4 n6 l; A- e
* h, P9 T. d& K& q' Test for an error.
# R9 p0 y1 H$ k: \5 \/ b* D: yIf results.isError() Then
, j9 U- n1 V& q2 O  Return innovator.newError(results.getErrorDetail())   \# p+ w: ~* z8 N5 S) H" A8 M
End If ' l+ v0 d% b6 ~
4 L8 o) Q  ?7 ~- @
' Get a handle to the BOM Items. 6 O' u. |8 t6 ]5 w% C
Dim bomItems As Item = results.getRelationships()
% K4 e: i8 p+ ~4 }8 {! H6 Q6 PDim count As Integer = bomItems.getItemCount() / N/ c& m& V4 T* B0 s' e; h' _2 b
Dim i As Integer * I+ v: h8 f# V1 N! w+ q  a

2 G1 m' E  H  ^0 ~' Create the results content. - o8 \4 Z+ j. Z9 m# @2 r2 _6 e
Dim content As String = "<table border='1'>" + _ 6 w: y- S8 g' j' [! l+ B) M5 e4 g
  "<tr>" + _
  w; k" p/ ~, S$ C. M7 ]    "<td>Part Number</td>" + _ 8 {3 x# L* S& A4 d. l
    "<td>Description</td>" + _
% c2 }, F# a) k5 C7 x0 ^    "<td>Cost</td>" + _
) A3 a+ [; e% T" v    "<td>Quantity</td>" + _ ; l" s" ]9 _. c* C% z0 b: h
  "</tr>" 2 W: h( i) E" i- U$ ]9 a3 b, r

4 i$ }& b6 w+ v& X0 a( Z; a% E' Iterate over the BOM Items
( S+ l2 r# N/ j- l9 bFor i = 0 To count - 1 5 N! }8 |4 m) @6 B5 \/ }, i3 _9 z
' Get a handle to the relationship Item by index.
! M6 }) k) e7 k  t1 O  Dim bom As Item = bomItems.getItemByIndex(i) , a# l2 S% V: S( }- U7 c9 R

2 k- Y, f4 S% H" C$ `1 g9 R' Get a handle to the related Item for this relationship Item. ; ~& V6 `3 ^3 f" Q
  Dim bomPart As Item = bom.getRelatedItem() # v4 T! Z* R& E. F

# w, E- s) k7 u7 n7 U" H  content += _
; U- _. t  [6 P" N    "<tr>" + _ # U* n' o9 V( j" u& T
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
. u$ I# l, r' o! P/ v5 J3 u# o      "<td>" + bomPart.getProperty("description") + "</td>" + _
( J% |% g& W% g7 D& h0 B      "<td>" + bomPart.getProperty("cost") + "</td>" + _
/ S* h# L0 i4 ?: B! P& L1 c1 Q      "<td>" + bom.getProperty("quantity") + "</td>" + _
% @) }0 R# s& k2 X    "</tr>" 4 M5 i; q- B# N/ T4 E1 h
Next
1 ~) k! W; S0 ~! Xcontent += "</table>" / a/ @6 \( U: y0 U! @$ ~( |

+ B' c1 g. W3 hReturn innovator.newResult(content) 1 ?' I6 n$ c9 w5 \
# c& ~+ u3 q# K" P, f
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部