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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x
Technique  & N  b' p0 t( i: Y5 D
To query for an Item and retrieve its structure you build the query as the structure
6 a) O$ `( [1 |8 uyou want returned.  Use the IOM methods to add the relationships you want and
& Q8 u4 y) k; I+ {& {build the structure in the Item.  The server will return the structure that follows the . |- z4 C- Q$ M5 c
request structure. . G0 I* r9 H6 h5 U
This recipe illustrates several related concepts together, which are how to get a set
  p, |" m# s8 N  Kof Items from an Item and how to iterate over the set, plus how to get the related $ n8 c: ?7 J2 V3 O% b4 ^8 r
Item from the relationship Item.
, T+ `# [5 p( a9 L1 sJavaScript  
$ k. Y9 Z7 z( ^/ xvar innovator = this.newInnovator();
8 m4 S+ y9 N1 M8 H& C! M- Y- s & U2 X- D; J/ Y, ?$ s
// Set up the query Item. / C# g$ z# q  B. B% {
var qryItem = this.newItem("Part","get");
9 W9 ?9 H! ~6 h" hqryItem.setAttribute("select","item_number,description,cost"); + c0 t2 @) c) t0 p. p# `
qryItem.setID(myId);
* B+ j9 m* B4 d* s8 X $ p0 v% E9 I: G  }9 X4 J
// Add the BOM structure.
- z' Q6 b5 U4 ?7 V* L; Ovar bomItem = this.newItem("Part BOM","get"); % P, v+ J0 R" P' ]
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
5 V; Q; b1 P1 r$ W7 zqryItem.addRelationship(bomItem); * ?* M- N9 ]/ D/ X# ?

- f, V  ~* o  |- c( f; c// Perform the query.
; J, O7 |9 E& j9 J1 e1 ^var results = qryItem.apply();   F) e) o$ I) `. e7 b6 ~8 C

) P$ t3 g7 ^4 A& T7 m3 Q// Test for an error.
+ R! K1 W, A- l$ xif (results.isError()) {   e2 q; ]# O* t& L
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); # `" e5 e2 P  m4 b, g' `) u
  return;
1 K! |7 I: u# X: o}
3 D' _! b7 N( q9 @
# f, }3 {9 j9 h6 W$ T9 Z0 _// Get a handle to the BOM Items.
, g( x6 G& V$ R; c: x) e* Wvar bomItems = results.getRelationships(); ) u% n& t0 b; X% C. D
var count = bomItems.getItemCount(); 9 A# p9 Q7 k3 Z' G6 z* Z/ i
9 s' X, [1 B2 L* b) ^. `4 `
// Create the results content. 8 H! z  \% P2 p1 u) i# K0 n) N; m8 X$ u
var content = "<table border='1'>" +
, r7 L. J4 K% a; [5 c* i; r4 J- h  "<tr>" + : `  k. |  `; @4 J9 ]
    "<td>Part Number</td>" +
% L# q  k. y2 p4 m% k2 W    "<td>Description</td>" +
( |8 @/ R9 c3 `8 j/ G7 X- o# C    "<td>Cost</td>" +
/ q' Q+ p. v- V) U' `/ I    "<td>Quantity</td>" + 7 F' ~' Z  x  H/ v( r
  "</tr>"; ) g9 |/ T7 r5 A9 W+ x2 V- L
+ D4 y- a8 Y$ _& u3 _0 ]
// Iterate over the BOM Items. 2 e/ b. V" Z; a
for (var i=0; i<count; ++i)
9 m$ }) r0 u/ m0 v6 Z# R{
4 L; j6 t- Q  Y// Get a handle to the relationship Item by index.
% \1 V. R: E! i% ?  var bom = bomItems.getItemByIndex(i); / P/ d" d* q# |+ z2 Y) F# ?2 [* w
// Get a handle to the related Item for this relationship Item. ( C0 Z" B- m+ R$ i
  var bomPart = bom.getRelatedItem(); ! G2 l' E/ K# F( h1 r/ J- q1 u$ Y1 j

2 C; N' y& g) X* k/ _& b  C8 b  content += "<tr>" +
2 E! ~- ~0 H( l5 ^3 i2 p      "<td>" + bomPart.getProperty("item_number") + "</td>" +
. T8 ~  q0 ]5 K      "<td>" + bomPart.getProperty("description") + "</td>" + # J* j. T) C  v2 L* G% n3 G5 H
      "<td>" + bomPart.getProperty("cost") + "</td>" + 0 |  q9 ~4 N( w% f" C, p
      "<td>" + bom.getProperty("quantity") + "</td>" +
1 @% w$ i. q7 Z5 o4 \: f$ R5 p    "</tr>";
. E$ ~* p: @2 V0 _; L} 2 L" w$ e1 H% J: `4 Y( O
return content + "</table>";
4 z  n* P6 \/ o# i; w  l, x4 O
. A- r) M3 q- `# U3 u0 Z
5 f. ?6 T4 z9 M3 }7 j. N
3 n9 B) q, K$ j! ~6 O+ |
C#  
/ y) K& s7 H7 H0 q' ?7 ^" oInnovator innovator = this.newInnovator();
& V9 d' B( c0 n/ _0 P$ V4 _6 ~ ( E- Y' Z! S6 ^6 T
// Set up the query Item. 4 Q% Q- ~8 @& ^0 E: f4 t* ]# f
Item qryItem = this.newItem("Part","get"); , Y1 v) Z& s# H* f+ R* G" o
qryItem.setAttribute("select","item_number,description,cost");
. i, S: _) C8 rqryItem.setID(myId);
, \; P" L7 n2 a8 k7 f, W! f . O# }5 p% N( S) G9 M2 q
// Add the BOM structure.
$ T+ A9 t5 M, U/ ~! fItem bomItem = this.newItem("Part BOM","get");
0 a2 v- P3 F  Y1 E& o/ wbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); $ m5 j+ d4 S5 _# W! a
qryItem.addRelationship(bomItem); 6 X& m6 S2 f, r: y% g

4 y" g1 y7 q( I1 Z* r2 [// Perform the query. * J8 Y  ~" n& G% S
Item results = qryItem.apply(); 8 h  |2 k2 e9 ~; l" x/ o& X
4 R+ d6 I+ ~% z9 a7 V$ p2 b1 ~0 `8 b( h) V
// Test for an error. 7 w4 C* O1 S1 D( n
if (results.isError()) { 4 M; b3 A1 S$ f" X: r
  return innovator.newError("Item not found: " + results.getErrorDetail()); ; W2 [) t3 `% q& }' |: C2 ?
}
5 X# q. k- \, m! |- z3 ?# L
* O0 \0 A; I* V) |& O4 e// Get a handle to the BOM Items.
1 Y3 \" A* U3 \# ]Item bomItems = results.getRelationships();
, `* T3 i. {% gint count = bomItems.getItemCount();
1 z3 Y- {1 Z" h5 w! Q+ t* iint i;
3 j. d2 Z  H' P% m" ]- U" S5 Q
6 p$ h1 n/ d4 Z# G// Create the results content. ' D( {( p: e$ M0 r/ y4 @
string content = "<table border='1'>" + 2 `; h, @9 _0 J' _' n& k- u& w" L) ^
  "<tr>" +
$ A, ~$ W1 c* q    "<td>Part Number</td>" + ; S# c' h- w+ T1 e. K. D
    "<td>Description</td>" + 6 N7 R  R' H9 i* u+ y. H; N5 N% N6 N
    "<td>Cost</td>" +
% o, C" K7 I, L# \- b- q    "<td>Quantity</td>" + # n: \4 O; b% D3 |+ @2 V- E7 Z
  "</tr>"; , ?4 B* E! ~3 D6 ?" F1 R+ I
, U2 }. U; h& _# N" p6 f
// Iterate over the BOM Items.
! ~' s2 u' x# t' B6 s& R, ]for (i=0; i<count; ++i)
- C9 @6 @; ?* s, K{
" \1 b7 w0 D1 Q1 M2 B// Get a handle to the relationship Item by index.
0 G5 f( |6 Z# q7 i1 N" c  Item bom = bomItems.getItemByIndex(i);
4 [0 ^: z& C5 q1 H: u1 U9 t8 K// Get a handle to the related Item for this relationship Item. 7 c. J2 V0 W! a' t
  Item bomPart = bom.getRelatedItem(); & b7 n; m2 E" i1 z3 S0 \0 O: ^% P
* T( Q1 o6 v+ ]+ G" g
  content += "" +
/ y# ?: ^2 b/ ^1 a, d9 k+ @, K9 r+ O    "<tr>" +
5 h; Y$ z# S* J& o& u      "<td>" + bomPart.getProperty("item_number") + "</td>" +
0 U4 a7 P! j$ X& |      "<td>" + bomPart.getProperty("description") + "</td>" +
' Z8 J9 Y2 [* ~: ^! }$ a, f. z      "<td>" + bomPart.getProperty("cost") + "</td>" +
7 t3 B) ^" S6 T! z9 F0 O      "<td>" + bom.getProperty("quantity") + "</td>" + 3 [9 ~) V7 |0 a" ^# v- _
    "</tr>"; / O  U7 z, J5 I( Y& V4 f; ?
}
: B2 E7 }0 x2 v0 u" ~" W  jcontent += "</table>";
4 h" r2 `) p+ e# `   j$ Q1 W4 v( b( s
return innovator.newResult(content); 2 m3 [4 u& d! r

9 Y. g9 Z" t  ^* n) e" ?
( M, Y" k3 h- ~3 w+ s+ M
* Z4 s, q( q# K

6 W( `# a$ [0 ~' ~! ^6 [% @" D
3 `* U6 _0 W/ N# L, N. _8 n4 r

4 ~# l, ?% ^1 J3 \) Z5 U" J " k, {' Y: w! `8 G
    Page 46
: T5 f& p/ I& p  j4 N9 H+ S 1 A# N$ G% k1 g* V2 D, u9 F
Copyright   2007 & s: ]  ]4 t4 x4 K; O
Aras Corporation.  
1 H0 O9 W% [- U  s; P+ j, x( QAll Rights Reserved. ( C9 _- e+ `; {) f( S
VB.Net  8 J0 G8 l7 a- ?' k1 n
Dim innovator As Innovator = Me.newInnovator()
; Z6 i; \# [5 N& s, D7 M- v3 m1 l . \+ [/ [( _9 o. U
' Set up the query Item.
, e: r$ T# J, d7 K1 NDim qryItem As Item = Me.newItem("Part","get")
6 L) W5 L" K* h$ c* p) Z+ n( y; UqryItem.setAttribute("select","item_number,description,cost") , _$ r  x4 I* L3 Y$ k, S
qryItem.setID(myId) ! v: l) U% A5 c9 {1 Z. r3 V/ R3 u

: s  B, u  a8 H1 Z% m3 n' Add the BOM structure. 9 S3 t, z, C7 _8 _$ V
Dim bomItem As Item = Me.newItem("Part BOM","get") " b5 v0 K$ R/ h
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
$ q& D( ^* I; R% }  s& I) {qryItem.addRelationship(bomItem) + G' a; {4 [! v: ~0 _
% E! D1 V$ u( Z; J& y& c; T* m
' Perform the query.
3 i0 F0 N1 Z& [; d8 x# CDim results As Item = qryItem.apply()
7 N! f  }3 K* B5 C1 U9 b8 g% h2 {0 h
+ T0 c  Z3 B: D0 f  W' G' Test for an error.
8 M* U) Q, C. ~; J. W2 Q+ w2 T, FIf results.isError() Then ) Z2 P* b. ^3 S4 y, y1 l7 I9 y" c& `# C
  Return innovator.newError(results.getErrorDetail())
* K$ T- p* _# z7 B# mEnd If
5 o/ [9 g9 o4 I + a3 q& _& U& L" J
' Get a handle to the BOM Items.
7 A; f/ J- ]  f8 HDim bomItems As Item = results.getRelationships() / U  G6 r) c; P, y* t4 B
Dim count As Integer = bomItems.getItemCount()
6 D; V( l5 \7 A  BDim i As Integer
* }( z7 @( j7 d. |" ~
2 F0 ]6 C0 Z9 R8 ]' Create the results content. " R+ |% o/ m" G& y
Dim content As String = "<table border='1'>" + _
0 V! \! k- ?( M- q) S  "<tr>" + _
  @; y- i, w5 O2 u3 f, S    "<td>Part Number</td>" + _
/ D( ]* A' G! v    "<td>Description</td>" + _ % C) d  O) N- m3 U6 D
    "<td>Cost</td>" + _ 9 E1 `8 Z  v$ V/ f+ N0 ?1 p  F
    "<td>Quantity</td>" + _
. J  _" I4 s& S6 S# c) U  "</tr>"
: e, I4 E; K4 g/ d; b- }3 t
4 Q9 _% q7 P9 ^" U/ s/ ]' Iterate over the BOM Items 2 m5 ?- ^3 Z5 d! ?: }% j+ p' y; ~- l3 A
For i = 0 To count - 1
; w8 v- H7 R0 E6 l6 }' Get a handle to the relationship Item by index. " ~3 L; {- t: L9 g& l
  Dim bom As Item = bomItems.getItemByIndex(i)
: e" `- ~% X8 Q0 x+ X. L! p ) i7 D# c4 }+ C, W4 L! x
' Get a handle to the related Item for this relationship Item. " _! P7 D1 h8 e7 `) M  Z
  Dim bomPart As Item = bom.getRelatedItem() ( J' d  V8 ~* i1 l
" a4 D: f9 B# `7 W" @
  content += _ ) o% s- L5 K' {
    "<tr>" + _ % z! R7 O: P7 m% \
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
  J! |6 T$ e1 f/ M      "<td>" + bomPart.getProperty("description") + "</td>" + _
  O. w; z: B, }* Q$ F* |      "<td>" + bomPart.getProperty("cost") + "</td>" + _
) \* z3 i3 v2 E% \      "<td>" + bom.getProperty("quantity") + "</td>" + _   l7 `- B7 N$ K  H) {5 }' S- l/ [
    "</tr>" + K) |3 C' U6 f- i  w
Next 9 Z3 }% X5 n1 X) |. F# S, j
content += "</table>"
5 ~+ |: E0 p2 ^2 j 7 E8 c- A- j/ f; |
Return innovator.newResult(content) & h5 D- O2 W6 X) F, e7 x
6 N( ]: ~7 Y+ w, R1 V& G5 S$ N
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了