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

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

[复制链接]

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

admin 发表于 2018-8-1 13:41:14 |阅读模式

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
6 g8 t! }) Q& y. eTo query for an Item and retrieve its structure you build the query as the structure : r4 z; {  m+ g8 ]! k. K2 b
you want returned.  Use the IOM methods to add the relationships you want and 9 m7 L( p; \7 {7 |; m) i6 Y' V4 t
build the structure in the Item.  The server will return the structure that follows the
+ T+ t; a. A9 m7 {. `3 \request structure.
8 B% h* v& i6 S2 nThis recipe illustrates several related concepts together, which are how to get a set
0 k* `" Q6 N- l8 K$ eof Items from an Item and how to iterate over the set, plus how to get the related
4 ]# ]3 }; w; o8 u: F3 fItem from the relationship Item. ) P, j  ?' B, w
JavaScript  2 G  Y; l7 T* z4 h
var innovator = this.newInnovator(); 2 _& B# ?+ l' A* Q. v5 C% j

; X5 q+ W: `& d+ L// Set up the query Item. + w/ [: W8 @( R4 k, h
var qryItem = this.newItem("Part","get"); / ?4 y2 @( x2 E  g( y% k1 ^
qryItem.setAttribute("select","item_number,description,cost"); 8 J4 L0 i$ U' [* R  y" q& Q
qryItem.setID(myId); ( V4 E1 p: j! f: }3 M

- R7 |- ^, A# g. A; x5 V& @) \// Add the BOM structure.
" q. D/ y% P2 x* N6 bvar bomItem = this.newItem("Part BOM","get");
! f6 Y  O) z# ~bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
1 x( f; e0 L/ H* kqryItem.addRelationship(bomItem); / B. }+ b( m( a# P4 {* Y4 v

2 h& c8 o6 U6 Z2 w4 O+ }: k// Perform the query.
$ ~/ C  Q* s6 O% t( {var results = qryItem.apply(); 6 ~1 j4 W! l+ I3 T* L

9 t; i$ i6 L) N// Test for an error.
# r) l6 D8 x* _$ Cif (results.isError()) { 9 f! J. q- Z+ b( F
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
; _# M& r! P6 h% g0 s% x; e  return; : n8 {& C. b# D
}
6 `# Z, J5 d  @' P; `7 R
2 a) y2 s4 O1 N( M/ g% ?- l) j( r// Get a handle to the BOM Items.
# I& p; N6 Z  G, Z; m+ m1 \4 M' pvar bomItems = results.getRelationships();
8 }. A! e5 q' W, {: I8 `2 |var count = bomItems.getItemCount(); ) R! o, e0 l- M. u0 ~
0 h& ]( r. e% R7 G: ]* v
// Create the results content. & r7 ~* w( M: g' U/ S5 d
var content = "<table border='1'>" +
8 ~5 c% k+ I; n) A% ], q  "<tr>" +
* o" A9 J( M9 R$ U! B    "<td>Part Number</td>" +
9 ?! G' G3 ]: A( H( `8 U: `- T5 S1 r    "<td>Description</td>" + 3 P8 c2 S4 U3 u) u! F5 x' M1 R
    "<td>Cost</td>" +
5 V; q/ |! Q; ?4 Y- U    "<td>Quantity</td>" +
4 n' _/ ]7 X1 X+ o/ N( u$ N" j$ ~  "</tr>"; ' G7 y7 g5 p3 V7 z

1 b. A* P) Q5 H- M+ x// Iterate over the BOM Items. ; A- n( ~. b" Q7 w' }, T9 L# I0 z
for (var i=0; i<count; ++i)
, Q' P8 l, ]) s& \. q{
1 U; @( P! e! w! y// Get a handle to the relationship Item by index. & f5 T6 t2 H: a* M+ a
  var bom = bomItems.getItemByIndex(i);   X; ~$ l% {+ f+ ]; q( `1 _" l& q
// Get a handle to the related Item for this relationship Item.
8 w- L" P/ i; h  var bomPart = bom.getRelatedItem();
- E0 P9 Q( j" j; U & ~& {$ G3 ]" `% V9 K
  content += "<tr>" + + b5 P2 v8 f4 y, i  f% {. l
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ' k# |( Q- M4 c5 w
      "<td>" + bomPart.getProperty("description") + "</td>" +
+ \! v$ `' `2 I# l! u1 _! |" y      "<td>" + bomPart.getProperty("cost") + "</td>" + 6 y+ a: m. y$ `; G& y
      "<td>" + bom.getProperty("quantity") + "</td>" +   Z7 c, j" ]! X) |. ]/ n
    "</tr>";
) E- O3 N  J% S6 y# M# E4 {1 Y} ; x9 K& l" N2 E7 I
return content + "</table>";) t! C, J: L2 ?; k  u' r
, y9 L! d; m* {9 z
0 W  M2 Z, J/ h1 k; u- n; g9 _

- u- T( @) l  K. [, M

4 D- _0 W9 w0 g0 @3 t* CC#  5 u3 H* g! G& c5 v7 s& A* G! _8 Z
Innovator innovator = this.newInnovator();
2 f/ ~2 O" I1 |: ^, U9 m% N, c0 q
. y$ t) u: B  g+ [1 _6 P2 m% m: I// Set up the query Item. 3 @$ d, K- c- P4 v, p
Item qryItem = this.newItem("Part","get");
9 a5 M  u, E: B  l) _qryItem.setAttribute("select","item_number,description,cost"); 0 l% H# h$ @2 f5 V9 E3 \
qryItem.setID(myId); 1 {; j' [+ z7 B6 @  i7 c8 p

& d: }9 s& g' d  \) \// Add the BOM structure.
  }4 Q7 T" N7 u8 LItem bomItem = this.newItem("Part BOM","get");
7 G) W  M- S% O, ]( B1 TbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
. u4 p* \& C- S- o3 n" KqryItem.addRelationship(bomItem);   i# s# C: I& x1 p2 x! d& F

1 ^- G/ _+ h' I9 f  k// Perform the query. 2 P/ O2 f+ E$ W0 N$ C
Item results = qryItem.apply(); / R; q8 k' ~- Y0 m" y1 j
. j3 B: ~/ e7 {5 W1 b% O3 a
// Test for an error.
8 S( I5 K/ \! x! g3 @+ D$ tif (results.isError()) {
( K% W# z+ v  j5 G  return innovator.newError("Item not found: " + results.getErrorDetail());
, M) q  T1 k. ^9 G4 f3 J. g' }} & `: C! B1 M/ D* O
# B% j; G8 `% l7 G( v- i
// Get a handle to the BOM Items. % D& y* z: g+ a) }9 P
Item bomItems = results.getRelationships();
" D  a8 B5 k+ p$ S: Qint count = bomItems.getItemCount();
3 g6 r5 u9 e0 E& |' q8 S5 s3 B1 _6 dint i; 2 H3 y: B9 \  ~' P8 T% ?+ a
" n( g, W  E/ Z- m4 l3 v
// Create the results content. 9 t$ o- n7 ?: g; P4 h9 I
string content = "<table border='1'>" + ) ?* ~- _7 Z: \( }. m1 S
  "<tr>" +
, z. Q6 n' l" F( w    "<td>Part Number</td>" +
4 u7 L6 f4 n( t9 |0 Y7 a    "<td>Description</td>" +
" E. f& N" Z  z+ ?1 K8 i    "<td>Cost</td>" + ! q/ ?1 |8 z5 v% H3 G& m
    "<td>Quantity</td>" + & s, J% {) Y* l
  "</tr>";
# J4 i6 ?8 w8 J, v! K. _% d; E
0 H" I! Z) k. D7 b// Iterate over the BOM Items. 8 x+ e- h, n( W8 o& w. F! n9 P
for (i=0; i<count; ++i) 3 ]6 R" O' m6 g* U
{ ) B( Z* P( B* A. S! G4 y
// Get a handle to the relationship Item by index. 7 l) D9 s5 z4 X  I* j+ }- z
  Item bom = bomItems.getItemByIndex(i); - ~$ _7 A0 e2 h0 g8 }
// Get a handle to the related Item for this relationship Item.
/ ]2 N, h1 G" O9 i# V- B* c( [5 B  Item bomPart = bom.getRelatedItem(); & `8 O& L1 b" E" u1 u

* ?" E2 t7 ^* r6 c  content += "" + & G; a0 H" @7 R, [& }2 U+ C# R- @
    "<tr>" + 6 \5 R# {+ y+ \9 Q: v2 i2 `
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
# U$ b" i* W$ U9 W/ ]. w, d' h2 F/ Y      "<td>" + bomPart.getProperty("description") + "</td>" + 9 L, T6 Z' n9 b
      "<td>" + bomPart.getProperty("cost") + "</td>" +   N1 s! W+ t( y# C; l
      "<td>" + bom.getProperty("quantity") + "</td>" +
; G) j1 Z0 v, K3 X% _    "</tr>"; / {  `; L  @- z5 `  N9 w) Y# p+ I
} 9 x6 z4 i$ F4 G1 \) r" N3 L, D* J
content += "</table>"; 4 T2 J' F9 ^: `5 R: B8 k

# A/ t, S3 i' R" n4 Mreturn innovator.newResult(content); + Y, x+ b  U; g( y0 e( i1 ]8 y

% Y, l( P0 H4 y( ]7 q
2 O8 M. j) q% G  R* {
! U+ V3 ?# W% d1 v1 g
$ a; u- ?! K- n
2 Y9 A; t- u! o: g

/ [- N7 Y0 ^) [5 Z. f. t
' h4 A# ?' k4 \    Page 46
9 d4 Y- r- F! e& Y/ Y) f0 c ' r+ r. H$ `0 B" _
Copyright   2007
/ S0 h$ ^9 f) D: g( t: A8 z" ^Aras Corporation.  " }5 U9 k( L% t. V
All Rights Reserved.
1 |* \+ }6 G4 q  D9 a" r! ^VB.Net  ; X  a4 U0 X0 g! U% v
Dim innovator As Innovator = Me.newInnovator() 9 {: z* D9 l' N

7 E. W# u  R" t7 y% r1 \' Set up the query Item.
+ \2 K" |3 N2 x3 g7 sDim qryItem As Item = Me.newItem("Part","get") , ^* s+ t" Z* K( N
qryItem.setAttribute("select","item_number,description,cost") 7 o, h. M$ w" N
qryItem.setID(myId) 5 `( m( G4 J7 E6 y" t2 b

4 v; ^( b0 ^2 \2 S1 j! |6 _' Add the BOM structure. 2 V0 X: E7 a# l+ z( H, K, A, F
Dim bomItem As Item = Me.newItem("Part BOM","get") ' \, p! T0 L  O0 D
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
0 T8 O- |& L* DqryItem.addRelationship(bomItem)
  t$ @4 k' z3 r$ ?8 m, w 1 Q: M0 Z: h1 S+ g* h* P8 n* m/ Y
' Perform the query. % M  H/ ]: h) v
Dim results As Item = qryItem.apply() ! e3 {' q( v4 s7 z" d

6 A; S2 ~9 f3 K3 W" y* I' Test for an error. : m' C5 a$ i0 q* O
If results.isError() Then ' V# k, O  ^3 Y- n, i
  Return innovator.newError(results.getErrorDetail())
  D8 A3 Z" ?5 C" V# IEnd If
5 E. e% O% ]7 ~; Y& _ ! O9 p5 o% }$ J' j4 u
' Get a handle to the BOM Items.
1 Y/ |- N+ H, `5 u; w' QDim bomItems As Item = results.getRelationships() ' J, h0 F. u3 r. P9 j1 t
Dim count As Integer = bomItems.getItemCount() & u8 k! ]" n' `5 ]9 b) {9 M- c
Dim i As Integer
0 p; v! d) d; u, R2 o8 f
0 ~' o* u! |/ Z# r' Create the results content.
9 U! K8 T% F: @Dim content As String = "<table border='1'>" + _
4 y5 \% A; ^% d6 {; N  "<tr>" + _
5 h& D3 I2 d( S4 O0 L2 D    "<td>Part Number</td>" + _ 8 Z2 e$ @8 H9 k9 F* X+ ?
    "<td>Description</td>" + _ " p' L/ {. u1 G9 w8 L2 c: ~
    "<td>Cost</td>" + _ 7 q# U4 U8 \. O6 l& r; f- w, i* G
    "<td>Quantity</td>" + _
8 Y, [9 L9 C% b  "</tr>"
$ l$ u! N- M. A: w
% @) m+ t1 D0 t% _+ ^' Iterate over the BOM Items 3 d* [  ^0 A+ t
For i = 0 To count - 1 8 Q" |# ?3 q, x5 z  V* n; H7 H
' Get a handle to the relationship Item by index. & C& o7 X& t* z
  Dim bom As Item = bomItems.getItemByIndex(i) 1 H! @' c4 G6 J0 B$ W% t
4 j) J, [; H  W) P/ P3 e7 s- V
' Get a handle to the related Item for this relationship Item. 7 \, d- M0 Z' \. H, h9 e2 }
  Dim bomPart As Item = bom.getRelatedItem() 6 c% J* K! u- d: @- `" M3 S
1 w) x0 q  K3 Y4 X" A$ Z
  content += _ ' Q8 ~% z1 G* x1 q+ D
    "<tr>" + _ % v: ^8 @  [# N9 n+ @6 p
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
. F/ H' a7 y8 E; R8 ^$ W+ E- m- m      "<td>" + bomPart.getProperty("description") + "</td>" + _
# V2 @, R& n8 e/ ?; \      "<td>" + bomPart.getProperty("cost") + "</td>" + _ ( K* h* F9 E  v' n
      "<td>" + bom.getProperty("quantity") + "</td>" + _
/ ]# ^/ d# @7 U7 I3 z0 H- ^    "</tr>"
, w, Q$ Q( S( Y! JNext + `5 T9 X* I. j/ k! y
content += "</table>"
5 W4 D# `* H: R5 l & {' s9 A* w! J+ K: R5 ?
Return innovator.newResult(content) - y9 T6 t! R& e$ Q2 D' k; V1 j4 q

  d# G" B& K3 g, a% w8 I7 `
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了