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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x
Technique  
+ C$ \. D9 l7 B! M7 nTo query for an Item and retrieve its structure you build the query as the structure
9 ]) S6 a" w' Z1 v8 y' ryou want returned.  Use the IOM methods to add the relationships you want and
" Z* x- m# M& C3 I) W2 D0 {build the structure in the Item.  The server will return the structure that follows the 6 g2 ^( K2 l# X+ v  ?
request structure.
, L5 i! i: x4 D7 ]  C/ S: mThis recipe illustrates several related concepts together, which are how to get a set - p3 [# p9 S3 M. U+ P
of Items from an Item and how to iterate over the set, plus how to get the related 4 I% x# s3 r, t% X
Item from the relationship Item.
1 Z6 E6 D- K( |/ {/ ?/ Q" |7 z# nJavaScript  
6 c; g* B1 @# d( Z2 ]* W& pvar innovator = this.newInnovator(); ( C0 j& j! z; }& C
2 Z% e) q( A# F+ i2 Y
// Set up the query Item. , ^% C) _# A; l# `8 D) L/ \: E
var qryItem = this.newItem("Part","get"); ) b7 ^% h; I! e" i2 s+ X
qryItem.setAttribute("select","item_number,description,cost");
5 N% ~  X/ c) uqryItem.setID(myId); 6 O7 |5 Q9 C6 u1 p: w1 S0 V9 n

- z$ C5 K% p3 A) n0 ?( `// Add the BOM structure. " ]6 q$ s2 V/ y9 F3 x* j1 [
var bomItem = this.newItem("Part BOM","get"); & x" Q( f0 b2 o* B
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
: V& ]4 f3 h. V/ L! K- bqryItem.addRelationship(bomItem);   g" m( u% X2 z- O6 V$ {! y. i" p
# a9 P) y1 a- |. `
// Perform the query.
$ g+ H3 g7 u2 \8 Mvar results = qryItem.apply(); ; W- L2 ~% S% S
8 U3 Q& z" p5 ^. M; f
// Test for an error. 1 |8 z9 g5 x! @
if (results.isError()) {
: K# R7 c9 I# ?" y* d  V6 S) j  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 9 F2 r$ S2 X, E. e
  return;
' M8 V3 j6 S0 X4 f3 r} ) [. L2 z, T3 q. l1 X( F

: S0 ?% X: t6 X6 |% ]// Get a handle to the BOM Items. 4 U% n. I* x1 x  }2 B0 l. l& h
var bomItems = results.getRelationships(); * D8 R* V* d3 c. u/ }
var count = bomItems.getItemCount(); 1 Z! F; i; s5 A

; ~7 C. I, j, N" K) w5 b* R// Create the results content.
( R9 j3 s8 N; g# U' Rvar content = "<table border='1'>" +
1 w6 ^. P4 F$ U, e2 `; G: j  "<tr>" + 6 Y" {) |" r* R0 D: `: I) G
    "<td>Part Number</td>" +
7 M+ E5 V, }9 J5 G' r- L2 R# p    "<td>Description</td>" +
, b) X# ^* f' o0 u/ ]% v; Y    "<td>Cost</td>" +
' n# M* k2 z3 n    "<td>Quantity</td>" + 7 m8 M9 t; f  ~$ X& }3 n
  "</tr>";
4 F2 k$ c' q3 p$ W 8 A) V( E/ ?- h3 P$ Z
// Iterate over the BOM Items. ! m' J. r) V; ]/ `$ v+ J+ t
for (var i=0; i<count; ++i) : ^% J. a. i' z2 o, ^( D' O
{ # P, q# e8 u( i) `8 I
// Get a handle to the relationship Item by index.
* ]$ t0 l( l$ L$ P6 Z( Y: h  var bom = bomItems.getItemByIndex(i); : B; S/ M" j/ i* ^+ u4 x
// Get a handle to the related Item for this relationship Item. $ }' Z& T. g. F
  var bomPart = bom.getRelatedItem();
; Q6 `- R! b' y* O! N' ~ % L9 o  t4 v7 R: @  s  ]' p- P
  content += "<tr>" + ! y& Y4 x- F4 n& p
      "<td>" + bomPart.getProperty("item_number") + "</td>" + . ?" a- }9 o7 |5 ?* {5 \+ `
      "<td>" + bomPart.getProperty("description") + "</td>" + $ e  I/ n# X* B9 R6 o0 y
      "<td>" + bomPart.getProperty("cost") + "</td>" +
4 I/ k  O; h6 ~" ~8 ~      "<td>" + bom.getProperty("quantity") + "</td>" + 8 v, \  |7 n! H7 g" L
    "</tr>";
2 f% o6 J6 x1 L: b; t" J1 ?) v}
, ?; J/ t% T6 [, S, b2 Dreturn content + "</table>";+ K9 U( Z' g' C

3 Z% [' s! k* u! P$ d4 X) A9 M/ @( ]# L; h
+ Z- ^; z6 C5 Q

/ a6 W: k1 e, j+ _5 I

2 X3 r* l: n% B2 z  MC#  
+ n/ k/ o- J8 iInnovator innovator = this.newInnovator(); / p& m5 c3 R2 m9 k+ U4 K

5 o0 I$ g0 W) C  [. Q% I$ q// Set up the query Item.
5 }; U; ?, G6 C/ |) I* S" WItem qryItem = this.newItem("Part","get");
. ~3 J* t. ]: e  Q/ z* EqryItem.setAttribute("select","item_number,description,cost");
+ L3 e  m3 P# p; X9 M8 p: L0 qqryItem.setID(myId);
# X/ G" ~6 Y7 g/ }! C& X4 `( V$ p $ q& M" d, h* d6 g) Q: K1 G
// Add the BOM structure.
- A' w0 }+ L2 ~6 sItem bomItem = this.newItem("Part BOM","get"); ; F9 E- R2 S% M+ z1 q. z9 I, i
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
6 E/ \# W9 N( K. Y# K" o% q9 U7 C9 X; @qryItem.addRelationship(bomItem);
+ \  D) u/ l) B  |
3 g9 M2 z$ l' ^' R3 d6 [7 G// Perform the query.
, j; f- r9 J7 T" T  f7 ~Item results = qryItem.apply();
" l5 n0 O# ^; q' |0 Q . p" o8 t6 t& W
// Test for an error. / b6 ]+ P' ]( e0 |$ s& d4 i5 v
if (results.isError()) {
( w9 m+ z1 b% W2 U: ~% r! j  return innovator.newError("Item not found: " + results.getErrorDetail());
1 d  X- G5 A8 @3 G) d% P5 J}
; N# `7 h4 _$ S1 ^( y8 _
) L) R# w. V7 P3 m// Get a handle to the BOM Items.
3 y$ d) {- R2 y6 E. j4 p9 c$ YItem bomItems = results.getRelationships();
) {! ]2 q) }/ |+ S& wint count = bomItems.getItemCount();
; H& l% j) \: [, r& z4 f4 x( Aint i;
( O) \3 T4 D& F+ C# v
! G! Q$ V; z5 U0 }$ }// Create the results content.
1 @/ L1 j! s1 `. b0 ]6 k* N4 ostring content = "<table border='1'>" + ) L5 y) }8 b0 }
  "<tr>" +
6 ^- Q6 |/ _6 c% P    "<td>Part Number</td>" + 1 g) K6 u1 D# u! |& R5 X; p
    "<td>Description</td>" +
8 A% ?$ Q* E+ G) b) n1 X1 ?5 t- ~    "<td>Cost</td>" + * \9 V. V: _# {& a/ m
    "<td>Quantity</td>" + - d6 j" p- `; \' y6 o9 D
  "</tr>"; ( m- Q" U- S' i6 c1 f* x# T# |: A
7 S+ }0 q% h7 H4 Q0 y7 E
// Iterate over the BOM Items. 7 j& ]$ S7 V! v: f2 p, r
for (i=0; i<count; ++i) + P6 D; i7 R% F) Q
{
) g& M. n. a$ s- G; d6 S5 C6 \// Get a handle to the relationship Item by index. / q1 z' P1 x) ~9 g, B' D
  Item bom = bomItems.getItemByIndex(i);
, ?4 z/ f0 r! H6 }  ^// Get a handle to the related Item for this relationship Item. 5 @; }" t: f& g; [+ y. T" Y' S
  Item bomPart = bom.getRelatedItem();
) l9 q0 S' f4 ^5 I+ e. s' ^4 o
2 b3 N$ Z3 m5 j: N7 y7 l  content += "" +
' h: J4 n$ V' D* o5 |( L- ]* x: M' x    "<tr>" +   R. d4 ~, Z$ k1 O$ }0 j3 x
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 5 x( V$ E# _( l/ m  T
      "<td>" + bomPart.getProperty("description") + "</td>" + ' L4 c( a9 _+ f5 J! Q
      "<td>" + bomPart.getProperty("cost") + "</td>" + 9 M+ V+ I( b5 c. D
      "<td>" + bom.getProperty("quantity") + "</td>" + 5 N; S8 n' F" ^2 i, D
    "</tr>"; # F) ?+ {1 o( T. t5 y
}
8 G( M% `+ H2 C9 fcontent += "</table>";
; R% T% Z& B5 L# N* s' m! ] - b" h& `+ x9 l- e9 e
return innovator.newResult(content);
8 p3 X  e- b2 M$ [
# P0 ~# U) p# N4 Z1 f, [8 w: F
. E$ M" a  Q& @8 l9 x8 O

/ h4 T! j4 U4 p5 w2 F5 g
- w, ^0 k5 b2 z- I

# N& D; h0 g3 w; a! M/ Z" p# y
" {2 t7 \. N  D. p5 k! \

5 @* y, T0 Y  Q: }9 H$ S    Page 46 4 y" G8 l! z1 \. J$ W

6 r+ h. M% C5 h& ^1 W0 `& NCopyright   2007
. Z8 O( H: t$ B) hAras Corporation.  ! [8 P; L( `; t) D+ H
All Rights Reserved.
5 s: q( u+ T% U5 l, k2 f! F, r9 ^: W! OVB.Net  ( n8 R" X3 `/ v, L5 u
Dim innovator As Innovator = Me.newInnovator() # |  T: c. ^6 j% X! Q

* E2 ^6 o4 z/ t9 q' j& W8 e  Z' Set up the query Item. - o' j- Q- V( H6 }! C4 }) w
Dim qryItem As Item = Me.newItem("Part","get") % F9 {4 v) {( H( X
qryItem.setAttribute("select","item_number,description,cost") " D/ Y( _# \* m- w/ i
qryItem.setID(myId)
7 p+ y0 A$ G, B  t4 U, ]5 R: | % K. k0 a+ i# A0 g
' Add the BOM structure. 2 N! ?- `8 @4 |$ x' o0 Y/ P
Dim bomItem As Item = Me.newItem("Part BOM","get")
* `( t9 X+ W: ?1 RbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
9 X* u  a/ g! e; Z9 UqryItem.addRelationship(bomItem)
( }0 N) j/ J7 s
  U( q0 I" d2 q# F8 t3 M4 {5 Y( g' Perform the query. . s" p$ ?7 K* C, C$ H& `
Dim results As Item = qryItem.apply() / |( T+ `- z6 J0 @

9 K( ^7 [# V% V' Test for an error. * Q2 h* B2 ^3 W
If results.isError() Then
3 h' \8 r9 \/ x' E( D  Y; \  Return innovator.newError(results.getErrorDetail()) 4 P8 Q5 _, m- F% S6 G) c, e5 M2 }  R
End If ' C, S; x' ^' n: F3 r
1 i  c( J: l8 v
' Get a handle to the BOM Items. ) N5 ]7 b/ v/ o' H# B
Dim bomItems As Item = results.getRelationships()
) \1 T7 e  M& pDim count As Integer = bomItems.getItemCount() 2 p" F- l2 K$ R
Dim i As Integer
' U! n& n# ?& J' [, Q/ p
* H  i/ n2 Z/ g' T+ Y% ~  b: c' Create the results content.
4 b8 R9 u4 {7 @( S2 j5 s: DDim content As String = "<table border='1'>" + _
! V9 F) F, C0 E) l$ `  "<tr>" + _
* w  y7 ~3 i. ]8 X! @    "<td>Part Number</td>" + _ 3 @! g& L7 _- F
    "<td>Description</td>" + _ ! a; J; J) k5 Z
    "<td>Cost</td>" + _
' ?( b2 e% x* W. M+ e6 I6 u5 u    "<td>Quantity</td>" + _
4 }& c+ d! K) K  "</tr>" / _9 P& {: p1 Q& |- ^3 u$ H; e4 |

4 l8 K% H5 ~5 G# k4 W  \. L' Iterate over the BOM Items
  i7 w# P, |0 Q7 O: T3 ?  R& ^For i = 0 To count - 1 2 F, F% k; p0 `
' Get a handle to the relationship Item by index.
8 [1 R& r$ i6 G( C3 |4 V2 U5 x, [  Dim bom As Item = bomItems.getItemByIndex(i) * E! O& Q* M7 Q% }

/ J& w* ?% h, o1 z' Get a handle to the related Item for this relationship Item.
; G3 E# @/ V  c; W6 }5 N) F  Dim bomPart As Item = bom.getRelatedItem()
* j$ k) {8 k% t, N8 V4 {. P0 x . _, U/ {: J7 l2 Y8 b
  content += _
) n: O# p( ~+ V' N6 |    "<tr>" + _ ; D6 a4 @  ~/ l9 C- y4 h* E
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
3 d5 _- l+ z" P" x% D      "<td>" + bomPart.getProperty("description") + "</td>" + _ 0 W" g  k. ~1 I  W1 l- k5 Y+ f- h
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ - Z6 W/ Z! G9 c8 e$ G! ~' Q) P- S
      "<td>" + bom.getProperty("quantity") + "</td>" + _
1 i5 t# t4 Q: p7 |0 [2 t5 p! a) H    "</tr>" $ m1 t1 n" N/ X1 S7 \( j! `* o/ u
Next
1 r" d9 t, P  n0 v" Ocontent += "</table>"
' z1 S- I6 _3 U& u. J" W
6 F3 C/ y0 U/ ]4 s6 w, F" IReturn innovator.newResult(content) ; S; P1 s& d; |! Q& P

/ N, T; }4 h" U; E4 C
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了