查看: 2069|回复: 0

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

[复制链接]

6

主题

4

回帖

60

积分

管理员

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

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

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

×
Technique  
! y' o& @8 ~+ S7 {+ H  L5 H4 c- `To query for an Item and retrieve its structure you build the query as the structure * ]% x2 b: c' |' K
you want returned.  Use the IOM methods to add the relationships you want and . ]  r' V: S$ m, U' Y
build the structure in the Item.  The server will return the structure that follows the : e9 q+ c1 R8 u5 `  L
request structure. # W% b% b. }1 |  `9 e" e
This recipe illustrates several related concepts together, which are how to get a set
$ h0 i6 l3 x" P; }" F6 Z* F+ F2 w* tof Items from an Item and how to iterate over the set, plus how to get the related & d# T8 {0 e) x3 R, e1 M/ V/ P
Item from the relationship Item.
" h2 D3 }# C( ~JavaScript  
" {3 p' Y& I/ }5 c. C1 Gvar innovator = this.newInnovator();
! z5 P4 B! B  `
$ @" [  b% q/ Q, L/ [, w! P8 L6 r// Set up the query Item. 9 r& _: \! c# `& i
var qryItem = this.newItem("Part","get");
0 O$ a) O$ Y) Y4 GqryItem.setAttribute("select","item_number,description,cost");
, D7 }; ?! ^' @6 UqryItem.setID(myId);
# J; L, K; s- y0 d1 z: z( c $ u. k" |  c* ?
// Add the BOM structure.
  S6 T/ r7 s+ ~' e5 m, v3 V% tvar bomItem = this.newItem("Part BOM","get"); 2 I6 G. w$ C& v5 o$ B2 E! Q
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
. }4 w; W$ m; K/ B0 L0 tqryItem.addRelationship(bomItem); ! p, f- g: s7 K: A! Y

: f8 e9 i  [2 P: m( \9 J// Perform the query. 3 s: f) e2 j! M0 [2 m. U- n
var results = qryItem.apply(); * R  [( I" \; [

* O! a7 b+ @1 v# M1 q8 U// Test for an error.
) U1 ^4 h0 y: M' Y" {if (results.isError()) {
! M8 n( O* {9 W8 H0 [  top.aras.AlertError("Item not found: " + results.getErrorDetail());
: {6 f( I( h1 R/ M. J! F+ Y& x  return;
5 x+ L) R6 f6 ^}
, |- y* O. q# e. _
7 L9 M' p# W$ b7 ~; F2 v) G// Get a handle to the BOM Items. * `) l' U: z3 _
var bomItems = results.getRelationships();
  G6 {% x- `/ ?! d$ w% H( Z$ jvar count = bomItems.getItemCount();
7 W8 m1 E) y6 k
. Y" G3 t9 b( p8 S- @/ h3 q! U// Create the results content.
% Y' \6 T- D7 Ovar content = "<table border='1'>" +
* m+ y6 u" P5 Z& K+ a- T  "<tr>" + 0 J  M; l0 ^: b( C! a# {( S
    "<td>Part Number</td>" + ! L" ?# ^  h7 w! W$ s
    "<td>Description</td>" +
5 B. a' _5 w& R4 c. m9 K    "<td>Cost</td>" + 4 e# H/ V  Z6 R8 ^) t
    "<td>Quantity</td>" +
9 _" N# Q" t9 I( V$ q  "</tr>"; : F! c# w5 l7 c( f9 B1 T! I

9 n7 P: X- I6 u; z8 Q0 w// Iterate over the BOM Items.
  k* f/ Z& s: s9 w$ s+ Gfor (var i=0; i<count; ++i) 5 G. o/ O6 i2 C
{
$ l/ ^0 z& y+ ]! n// Get a handle to the relationship Item by index.
) |% G/ Q; z8 @, d" V  var bom = bomItems.getItemByIndex(i); 7 L5 ~3 B4 V) ]1 n- G( y. G& b
// Get a handle to the related Item for this relationship Item.
& h/ v( F. C) g! O! u$ p: o  var bomPart = bom.getRelatedItem(); 8 q' \" L' d3 R5 b& W, v

- T2 O& V( U1 d2 E1 n2 k: |& L  content += "<tr>" + - x% j% q- ?7 W
      "<td>" + bomPart.getProperty("item_number") + "</td>" + & T/ g- j4 y; [: }
      "<td>" + bomPart.getProperty("description") + "</td>" + / L( x$ }0 l4 A8 a+ ~8 I8 F
      "<td>" + bomPart.getProperty("cost") + "</td>" +
- s# n+ s# X9 g7 B. ^$ V      "<td>" + bom.getProperty("quantity") + "</td>" + ' \* ]" f% v+ V9 g8 Y
    "</tr>"; 0 P5 p8 g0 @8 p7 F! w) A
} - j8 @5 U/ ]9 `, @, t% q
return content + "</table>";7 D- [) P/ I( x- `: d1 V
8 x0 E, w/ E% s- C0 s
5 p1 [% l! g* p+ ^  K( W

/ e( o7 O- E6 d7 ~7 V& Y! U
4 }, I( r  |6 y& E! `0 A
C#  * m9 t5 }7 x7 W; W- L  T
Innovator innovator = this.newInnovator(); & H: x  s0 E# d- g
6 I$ I) \) S0 m
// Set up the query Item. ( h5 }$ `) ^0 k# }
Item qryItem = this.newItem("Part","get");
% ^3 y4 t: S8 A( ]. QqryItem.setAttribute("select","item_number,description,cost");
' M# n5 ~0 ~1 j" UqryItem.setID(myId); 7 t. W' [9 A0 c& _
/ X8 B- a8 h$ c" A6 A& Q' {: w% J" x
// Add the BOM structure. & T9 U( e1 V6 Q" x+ g
Item bomItem = this.newItem("Part BOM","get");
, d9 o& _. b( Z, T  [0 u1 vbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
- z* Z4 ]1 M  o* E$ G3 b% cqryItem.addRelationship(bomItem); ( y' C& n" C: a: \/ `$ q! y4 h

$ L7 k4 {* l/ {0 q3 i; S5 l// Perform the query.
* ]; k  U# [" H8 f' t) rItem results = qryItem.apply();
' \0 V* J+ g, k' c. k
$ g6 r' g$ W/ v+ K  s// Test for an error. & X% M3 ~6 _5 t6 T* f) F
if (results.isError()) { 2 a. W0 l4 @" P+ h
  return innovator.newError("Item not found: " + results.getErrorDetail());
& l$ S- R" R& Z# k}
% A2 r0 V- `- [( C" x
- f2 a! f$ {' H1 w// Get a handle to the BOM Items.
$ C& s2 K, S9 Q0 C: JItem bomItems = results.getRelationships();
0 Z' R2 t6 N' n& M1 @. Wint count = bomItems.getItemCount();
0 U: {& M0 m2 _7 Y& }. Z9 T( _9 |int i;
2 t- V( h. A# B& P6 I
! y0 t3 Q; k, D( Z// Create the results content. 6 M  [! M6 p: }
string content = "<table border='1'>" + # b9 @" g" S& l
  "<tr>" +
( ~+ K( }4 E* W* k, Q) e    "<td>Part Number</td>" + / Q' S! s' l& ]' _: T) e
    "<td>Description</td>" +
& o1 C: n) T# _) v! i1 `% g    "<td>Cost</td>" +
  p$ b  K' g8 k, W, d5 d* g    "<td>Quantity</td>" + : [$ P* l% f* B; m* G; E0 [
  "</tr>";
( {" B3 M6 V5 U
7 r6 K" ~5 K  c/ S. Z// Iterate over the BOM Items.
. W& Y( b9 [8 [6 E# d& ~6 y% Yfor (i=0; i<count; ++i)
: _2 F/ O/ {8 u{ 6 Z$ A  M- @- z& B  d
// Get a handle to the relationship Item by index.
- o: s: Y: P' A4 i$ G# H6 ]  Item bom = bomItems.getItemByIndex(i); & K2 f3 c, g1 a0 G% P; v; Y
// Get a handle to the related Item for this relationship Item.
( @) m' l. N" V4 \8 g) p2 J2 h  Item bomPart = bom.getRelatedItem();
0 c, A& m- C4 X# K 5 u4 C+ r* ?, Y, A; r
  content += "" + , s$ o$ j/ A7 w
    "<tr>" +
4 j8 S' {- ?* d9 ^      "<td>" + bomPart.getProperty("item_number") + "</td>" +
8 ~# P1 ^. L( `      "<td>" + bomPart.getProperty("description") + "</td>" + 3 W# a$ d  R- ^/ i
      "<td>" + bomPart.getProperty("cost") + "</td>" +
  \. P' J% G5 u+ [  r      "<td>" + bom.getProperty("quantity") + "</td>" +
" i( W) E* l0 @" K- m5 d( o4 H    "</tr>";
; k7 J, Z& o7 P# {7 F5 k4 h}
' E; O4 d5 N3 J$ h: b( S# \" s- @content += "</table>"; / g* Z9 `9 @" J0 }% d* o; d
( O% r' P0 v$ f8 C1 j! G
return innovator.newResult(content);
1 r  }3 ], K+ Z( p$ ]. |
) A' h8 k" ^# Y7 k% N8 k

; @; l( R/ }5 i  D7 [. S- d0 ~1 Z( r6 p# w' h) F' ^
4 h7 Q, e2 F  @- }

+ E6 m3 k" }, K3 P# z' x

8 ]+ y1 r  O0 k* m: H; _ 0 L" A, A5 B! C: b
    Page 46 * V2 t' Z( X2 x2 A9 R8 Y

' \: }8 O7 P4 zCopyright   2007
  H# I- N" o( \" oAras Corporation.  
8 m. n0 L: ~9 n1 \All Rights Reserved. + t  x9 Z( h4 ~7 T5 h* K
VB.Net  
' T8 j- n% @8 u3 WDim innovator As Innovator = Me.newInnovator()
" T1 Y( n- m6 i3 f8 Z
+ v2 T% u+ j9 g2 b  Y/ i9 a# Y' Set up the query Item. 3 E0 `2 N  [5 N% t" N9 ?
Dim qryItem As Item = Me.newItem("Part","get")
+ m( P; I4 G% r) hqryItem.setAttribute("select","item_number,description,cost") , J7 }  a4 I' t0 K
qryItem.setID(myId)
# w% V- L3 C7 t& T - x5 A7 y/ _- K: i2 `9 x  k" j
' Add the BOM structure. % o2 J0 T0 A& w( A1 K- d! G; m: a3 c
Dim bomItem As Item = Me.newItem("Part BOM","get")
# b% R& D0 [, V! @) e7 Z& m0 l% qbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
* L$ ?" O* \1 H* Z' IqryItem.addRelationship(bomItem) , t: P: U9 O0 M1 h; H$ ?5 b
3 G7 |  }9 }3 `. V  E) f5 {9 ?, s
' Perform the query.
% ]0 Z2 l# s+ e) E( j5 QDim results As Item = qryItem.apply()
& e7 j3 U1 G8 z, p
" H3 f" G8 ]7 a0 u' Test for an error. 5 A1 E. w/ v# i8 _& L7 w  I/ U& ~& a* J
If results.isError() Then 1 ?/ t$ c0 A5 b( }
  Return innovator.newError(results.getErrorDetail()) # F: d$ P0 S. e
End If
) _1 b9 }& ?2 d* S5 J6 N3 d 8 b# X) [$ w. L! I/ P7 F2 u2 X
' Get a handle to the BOM Items.
  x( R& I# j* k; h3 d1 m* hDim bomItems As Item = results.getRelationships() 5 r/ o: Y# K: l2 j# {
Dim count As Integer = bomItems.getItemCount() ( u" S) y$ m( M$ r7 F
Dim i As Integer 3 [* l8 O/ }; i# g3 C& z
- P2 c  V0 g/ X. F# V
' Create the results content. ! ?6 N- ^- `1 O3 C1 z- y
Dim content As String = "<table border='1'>" + _ + h* Z( N! W5 a! b0 [( t
  "<tr>" + _ ; k* s, B7 C/ N& `- H/ }$ d
    "<td>Part Number</td>" + _
; s5 {- d5 v% x6 d7 I3 _    "<td>Description</td>" + _ & _) f7 s6 ]1 B" e- U8 S  x
    "<td>Cost</td>" + _ ) O9 P3 v& \7 n0 T7 J6 B9 p0 f$ Q* E
    "<td>Quantity</td>" + _ : r$ X; K. J0 A1 A
  "</tr>" + G1 I$ c. {6 P; n" f8 F/ I/ u' t. R+ R
) Q/ Q5 \" c, ~8 z
' Iterate over the BOM Items   N7 `$ ^0 g( U1 C" y( F5 K
For i = 0 To count - 1
3 H+ g: g8 z7 f: U) A0 ?2 P' i/ p' Get a handle to the relationship Item by index.
! B8 O5 l3 O7 p  Dim bom As Item = bomItems.getItemByIndex(i) 0 ~, a; z) ?4 T" w: ~+ a

$ y* m4 r4 f. }; t  H  S' Get a handle to the related Item for this relationship Item. 0 v4 i) N3 x: ~0 ~
  Dim bomPart As Item = bom.getRelatedItem() ' q2 \  @% W0 d/ Q

9 ?" n( F8 Z- L/ D  s. d+ v  content += _
9 E5 G4 Q- c( c# }$ S4 n    "<tr>" + _ 1 W$ A5 U. V. k4 |: f
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
: Y8 s- P9 D* ^4 v, N, r6 J( K      "<td>" + bomPart.getProperty("description") + "</td>" + _ ( u5 L" c8 D: u0 M+ _4 M! n) f
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ $ W+ b1 |6 j) U" s9 X9 }6 }1 F
      "<td>" + bom.getProperty("quantity") + "</td>" + _ ) C3 L7 I% s% T# E1 X( M3 i1 x5 T
    "</tr>" / G3 s3 [' s, o! O, S) G2 S" m( s; x
Next
. T" N, _/ o( M8 q, f5 v+ ncontent += "</table>"
/ F+ o, ^( D- c! s7 z( f1 f
8 q1 q6 u2 s: HReturn innovator.newResult(content) : f9 i$ H# K& {2 _; Z) a
. o1 v4 S2 G& j: r& F
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

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