PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  0 F2 m/ Z0 B. s
To query for an Item and retrieve its structure you build the query as the structure
  H4 l3 a( H1 P" w: }you want returned.  Use the IOM methods to add the relationships you want and 3 `3 S9 l! u3 N. ]" ]1 X+ a" e; V
build the structure in the Item.  The server will return the structure that follows the * Y6 h, |: v9 C5 d8 A2 g
request structure. % \: n$ K( d& C) ~% D6 B) Z
This recipe illustrates several related concepts together, which are how to get a set 3 O) {& e1 T* G* Y1 Z3 t' F
of Items from an Item and how to iterate over the set, plus how to get the related / W- w; ]* ^! T* o
Item from the relationship Item. ) W# q& h" ~7 T7 @3 b8 m
JavaScript  
/ H+ A  R; @7 ]  t6 ivar innovator = this.newInnovator(); - T# e" {2 j3 {8 X/ q3 S# x# R4 M
0 y, ~% q% u2 W
// Set up the query Item.   v' a8 n7 K& E- a
var qryItem = this.newItem("Part","get");
2 r8 K% v5 d# p/ xqryItem.setAttribute("select","item_number,description,cost"); 4 ]7 Z4 C( W3 j0 ^
qryItem.setID(myId); * Y/ [- h" |5 @' M
1 ~5 ?0 i) x, e' N1 e( s( Q5 Z
// Add the BOM structure. 8 i, a4 H5 c" f% ~
var bomItem = this.newItem("Part BOM","get"); ) `1 f0 ?' g% v' k* e
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); * b# U/ ]6 c' T
qryItem.addRelationship(bomItem); / U* B" K% X" F  h& L4 L# K$ c/ D

7 t% U& n4 F' w1 o2 P// Perform the query.
3 `0 Q! E/ e5 B9 @var results = qryItem.apply();
6 P1 I* T1 [6 t- _, |
- G3 o# F/ V; \# R$ L" x// Test for an error. 2 f3 y, E; w% U) H9 f. u% e
if (results.isError()) {
; V! s! y: _% t! [( p  top.aras.AlertError("Item not found: " + results.getErrorDetail()); " a3 u. V( l9 N3 j0 V
  return; ; y4 K7 e( z- J, c0 z8 E; O
} 6 i4 Z) [# h4 E8 w4 [0 T7 ?

3 ]$ D) r; ?, A( N* O9 c: S// Get a handle to the BOM Items. ' h9 v+ l' @* N2 T4 _& M  l9 E
var bomItems = results.getRelationships(); 8 K+ N4 d9 m, v+ i" G0 t7 @
var count = bomItems.getItemCount();   P' J6 O8 q, q; N
8 h: S$ g+ M4 ^# w
// Create the results content.
; w/ W1 n5 S; H! svar content = "<table border='1'>" + * N" _# P, S5 ^
  "<tr>" + 2 @" o  ]+ Y5 N+ @* t2 W7 |
    "<td>Part Number</td>" + / G* b) B0 B2 _
    "<td>Description</td>" +
( R3 w% d' Z8 o; }    "<td>Cost</td>" +
) r1 H% `3 Z8 T! Z. G    "<td>Quantity</td>" +
( Z  l0 |: s" O" Q0 P9 u  "</tr>"; # l8 a4 m" n# ?7 m# }
6 j# S; o+ `, G# D, n# F6 W3 z
// Iterate over the BOM Items.
5 g3 k$ R# B9 rfor (var i=0; i<count; ++i) + R3 C$ ~6 E0 t
{
- R  `& G# P0 h; e8 e- W// Get a handle to the relationship Item by index. % y. x7 n  Q7 x4 p& Y
  var bom = bomItems.getItemByIndex(i);
" P/ R' x3 [9 t4 j' M+ X( R// Get a handle to the related Item for this relationship Item. & S, w0 `* B6 i4 ^8 Q. I( ?2 A/ u
  var bomPart = bom.getRelatedItem();
% A9 ~& [( @+ F: C( U6 F , x# y2 m' d3 Q# h# [
  content += "<tr>" +
. s0 C! f% R6 ~# X4 Y. T! x      "<td>" + bomPart.getProperty("item_number") + "</td>" +
0 h$ H9 T9 X1 `4 A2 A( |$ z5 d9 j, k      "<td>" + bomPart.getProperty("description") + "</td>" + 9 `8 ~3 T9 s$ c9 p+ o- L" n
      "<td>" + bomPart.getProperty("cost") + "</td>" +
5 m7 q  O. M1 j* j- E5 P6 E- y      "<td>" + bom.getProperty("quantity") + "</td>" + ) S- S9 R$ H# B/ \+ j2 q' E& r
    "</tr>"; # u) M1 E! S4 O& c; o
}
# Q% y  f% y( k. m) _# rreturn content + "</table>";3 {2 m$ c, a  G- b, C  Q: P! k4 u! F
% l* A. k) w9 V7 ?- s% D4 O
, O  x* g& ?9 ^! X. X
( P4 W9 @7 Z& m: T) g( s- `3 a
0 G# K! e/ \( }6 `- j8 M2 V
C#  - e, W3 Q( {2 l+ p5 w' |) a
Innovator innovator = this.newInnovator(); , e4 ]9 r( X6 w
2 J, x0 t0 i8 z/ T7 u
// Set up the query Item. ( [9 H) w! A3 R. z* e
Item qryItem = this.newItem("Part","get");
7 f6 ~! A" w. `* t3 p; P& WqryItem.setAttribute("select","item_number,description,cost");
% ]  d) C3 L) x9 \3 o( X7 XqryItem.setID(myId); ! _- V9 w  h  J0 s
" i3 P- C4 k. w3 }" N- G- m
// Add the BOM structure.
" d% ?& D8 w. v# O" O$ ?Item bomItem = this.newItem("Part BOM","get"); + I9 ]9 s8 o" \# V) T& [# b9 ~1 R
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");   a# l; ~7 `: F) I) ]
qryItem.addRelationship(bomItem);
* [# A* [! e& O5 [( {% f& W8 v & S4 _2 G2 x/ {; W1 D5 `
// Perform the query.
$ r' h9 ?; R2 @Item results = qryItem.apply();
% m) |9 f0 d0 ^/ B' l! m' b ; Q# Q% l$ w! Q7 m2 j
// Test for an error.
0 E7 j, Z0 p1 y1 n; `if (results.isError()) {
4 f& T2 n1 ]/ H8 R1 R8 B" z4 k  return innovator.newError("Item not found: " + results.getErrorDetail());
9 ~) K  O; i4 Y' x- p}
( @! @- A7 `" a' q! y 7 w# i) i1 B7 Q1 C$ H. C
// Get a handle to the BOM Items.   t9 H% b: i3 }$ K/ r, t/ K
Item bomItems = results.getRelationships(); 3 U: h! r. I/ o
int count = bomItems.getItemCount(); 2 W. }. n. a0 {) u2 t* y
int i; , \: z- O) f( F' Y9 X" S
8 w6 w0 c  {5 h0 u: r
// Create the results content.
& f* \) e+ Z4 n, J. Wstring content = "<table border='1'>" + & Y: ~( J3 P$ ]& I
  "<tr>" +
2 i0 w0 K3 z( C3 Z5 j    "<td>Part Number</td>" +
  @) _! i: ?& Z8 e4 o    "<td>Description</td>" + " f; N. O, _9 G- V! q
    "<td>Cost</td>" +
3 k! I6 `9 U/ C( {; h8 e; E1 Y    "<td>Quantity</td>" +
; `2 u" Y' G/ i& g  "</tr>";
5 `, e- X/ s" Z6 @ ( A; J% b1 U$ D
// Iterate over the BOM Items.   ^. G) C$ e$ K& ?
for (i=0; i<count; ++i) 0 _6 ?  [0 ]& p. F2 f
{
9 C8 G/ H% P$ t: h! ~// Get a handle to the relationship Item by index.
' H, F4 e: J" a  Item bom = bomItems.getItemByIndex(i); : n) ~. s% F# L9 C
// Get a handle to the related Item for this relationship Item.
: M5 H  I5 q/ K. K0 q4 G  Item bomPart = bom.getRelatedItem(); 8 ]. e" p1 C3 _! n

' w7 R2 m3 A; ~) t5 S  content += "" +
1 M5 u% S' {5 y9 S0 n    "<tr>" + ( p, g6 @8 k6 G6 l& U. T+ @& ]
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
5 h( z: \2 Z+ A9 ?" C# a* v/ b+ ]      "<td>" + bomPart.getProperty("description") + "</td>" +
2 N5 v) d8 n, z# m" E3 B. G      "<td>" + bomPart.getProperty("cost") + "</td>" + , N* S/ p. w; q% X3 v# b1 o0 Z
      "<td>" + bom.getProperty("quantity") + "</td>" +
" E3 B( D9 T% F6 X  Y1 n    "</tr>";
6 l; Z, c% ^0 H$ \3 f. D- q}
6 j/ R" {  N2 z* y8 I* |content += "</table>";
) E7 y, V1 o9 t3 Y% j 6 I) f& _( p) X  z+ ?
return innovator.newResult(content);
5 [4 x4 a  H) B( C9 \- z/ s  |
: d* u- C3 p3 S3 O4 `- i4 O

7 Z5 T- i4 O$ t6 r3 i- M' W- z. Q
. T/ D) G2 D2 ^
# K" I5 i3 `  i# W( S; i: z9 P5 n
7 S: D/ e: d- R6 p/ Y/ c. w! `7 v
1 L7 c5 N3 X7 W0 d" |
; {$ @: `; B6 ?/ w* e- q
    Page 46 - _0 q# Y* D4 ]6 Q5 g

" \$ m/ [; j/ B4 [) B+ DCopyright   2007 5 }; S# @+ z+ t2 c3 r
Aras Corporation.  0 Y. \4 j, ?; I3 z% _
All Rights Reserved.
& q# f' v8 Y! }0 `( U' M& J; \VB.Net  
& D: d- R6 O: f' G, NDim innovator As Innovator = Me.newInnovator() ) r7 h" D4 z8 H: m8 y$ j

( `- _1 ]  r* R' Set up the query Item. ' a$ v! V- [3 p( |5 L: @
Dim qryItem As Item = Me.newItem("Part","get")
, W) h) K" Z. c- N+ AqryItem.setAttribute("select","item_number,description,cost")
8 v8 c. {7 L% u0 m, AqryItem.setID(myId)
: J/ t1 ?8 Z4 |9 [6 v4 f: @* D
8 y% N" C2 l! i: D3 y' Add the BOM structure.
+ c8 @4 g  @/ S9 \( a* W& ~; ]Dim bomItem As Item = Me.newItem("Part BOM","get") - v% N1 o/ v* C; ?+ M
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ) `' U6 v- {; j7 F
qryItem.addRelationship(bomItem)
: ^3 i7 x! G6 h+ f ! v& S. g3 }8 W' Z8 l8 H% a
' Perform the query. , q4 S  [( w$ L# Z1 F4 M
Dim results As Item = qryItem.apply()
2 J3 c2 }+ n$ V9 W4 p0 v7 ]& d $ t  H8 j+ m' p
' Test for an error.
1 m* o0 ]& ^5 W2 B* lIf results.isError() Then . p! [; U3 l8 D& x; H* o/ [
  Return innovator.newError(results.getErrorDetail())
' M% T5 t. ^& k* i7 Z8 P/ ~End If 3 i/ Y0 j( [* }

  M# o$ {6 W5 l: a1 C) v" ^' Get a handle to the BOM Items. ' N$ _1 o2 q: r2 p* K
Dim bomItems As Item = results.getRelationships()
( E1 a& H- @7 J* EDim count As Integer = bomItems.getItemCount()
  W  {' t  s5 l- \Dim i As Integer
1 V% a2 }/ K! k0 h) h" W& {$ d 2 O; d6 {& `6 s
' Create the results content.
* n- y  w0 @8 EDim content As String = "<table border='1'>" + _
  y0 V2 t/ a) }* z5 ^3 A7 h9 `  "<tr>" + _ ; U" |7 r. w- O1 ~" v# N
    "<td>Part Number</td>" + _ : \- ]/ ]5 N$ [( O, O- ~( P
    "<td>Description</td>" + _
/ x, M: D0 c6 N' M    "<td>Cost</td>" + _
. {( [) }- U2 @% F    "<td>Quantity</td>" + _ 2 c) p& _8 J1 [% A( F: w% V+ P
  "</tr>" ; h. Y9 z- A8 d4 f0 l/ w( y

1 a+ z. }) U2 N7 A+ b+ l: t; C; ^) J' Iterate over the BOM Items . H7 Z/ H0 v7 ^2 `6 t/ D9 z
For i = 0 To count - 1
8 N: a; ~9 W! ~6 a. N' c4 q' Get a handle to the relationship Item by index.
: s3 t; I5 t, d  @$ Q" @+ S6 P  Dim bom As Item = bomItems.getItemByIndex(i)
% }2 C! \- ^# B8 u* ]' w
$ T! _: J! D- e( j5 c8 `% A' Get a handle to the related Item for this relationship Item.   k! h5 [  [1 r9 g' a& Z# M9 l+ p) D
  Dim bomPart As Item = bom.getRelatedItem() 4 P1 l) U7 F* B+ a0 M
; b' b# t6 t: x& m
  content += _
7 z5 v. r  m( @) [5 A) }! O) W' z    "<tr>" + _
0 c$ o$ r& s0 V& j! F      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ & u( E/ w% g" y# i* b( t* n+ ^
      "<td>" + bomPart.getProperty("description") + "</td>" + _ 3 s4 R/ A  ]1 A) D" H* \
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
$ n8 H# z5 F8 R8 y& d4 D      "<td>" + bom.getProperty("quantity") + "</td>" + _ # ~, J  T6 h7 b+ p; s; @1 t
    "</tr>" , c0 e1 |( \% q1 U; r3 J  C
Next
3 b. w( `% y7 G  T- \& hcontent += "</table>" 1 \2 V5 d( o6 K  T# W$ C- H6 \

9 \6 U0 I; F: J% tReturn innovator.newResult(content)
4 a5 \0 h) @. k& j/ I3 T- U+ r; ^- {" b7 ?9 E% Z- q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了