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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
5 `: {/ Q; [' x/ p& yTo query for an Item and retrieve its structure you build the query as the structure : ^, Q, d' n  U4 Z
you want returned.  Use the IOM methods to add the relationships you want and
  P0 v* J0 E0 Y' K% N, {) v* W% X- Fbuild the structure in the Item.  The server will return the structure that follows the ; L, B4 k8 W2 ?
request structure. # g; n9 X2 g5 K! |. e. F/ ^
This recipe illustrates several related concepts together, which are how to get a set
( J* Z7 k- B% ?. Xof Items from an Item and how to iterate over the set, plus how to get the related + ?' l2 b! R% w1 q( r" f
Item from the relationship Item.
/ W' |9 G) U3 kJavaScript  ) a2 r5 {* K" R1 i- N
var innovator = this.newInnovator(); 4 ~' u( @' r& s8 c3 E

) `; f; v- _. _! C9 M9 h# X// Set up the query Item. ) _) G6 L) V2 h
var qryItem = this.newItem("Part","get");
9 h# e: u0 y3 BqryItem.setAttribute("select","item_number,description,cost");
8 F) \; [7 v$ A7 b/ M7 YqryItem.setID(myId); " s5 n) ^1 A: R' {4 U
5 c( o- ?$ y! A" q2 P
// Add the BOM structure.
8 `& O# K+ ]2 N+ O3 O, e6 jvar bomItem = this.newItem("Part BOM","get"); ; [  c) W+ E% X. E8 [$ y- u% M
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
) U9 u: k: Z& [/ iqryItem.addRelationship(bomItem); 0 j: m5 F  u! |1 A/ U2 C; U& m" O" J

5 y# d& q6 q  F// Perform the query.
+ \. ^' w, v' D2 tvar results = qryItem.apply();
* `1 D" [3 _; Y# n 5 [9 `: C3 R2 ?$ ~5 ?( E
// Test for an error. 4 m  X1 L7 [; n4 V% U! [  ^
if (results.isError()) { ! @, x; w' S  W
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
3 U' ~) `# u8 E( J  return; 6 A$ V$ \: Q) L2 W* a/ Q! R
} 9 ?& _! }: k' D0 y& a  ?8 D

9 K6 }8 O' t. k- o// Get a handle to the BOM Items. * k$ Q% ]* Y6 r3 }7 p, C
var bomItems = results.getRelationships(); & G( x( E1 t. q" \
var count = bomItems.getItemCount(); + |6 R6 ?' m" _2 D$ v+ Y% h
0 R* v# B* x1 q- Q/ i
// Create the results content.
4 I" B$ {* t% W* m# C' {; o) s0 a% `var content = "<table border='1'>" + : b( u/ G: V4 t' l, b* A7 F& w0 T* k+ M
  "<tr>" +
; @2 X3 I4 J! f# V8 c    "<td>Part Number</td>" +
; W4 a2 h  Y% i2 _' v    "<td>Description</td>" +
. ~5 C/ q) {* Q. ~2 c; w9 n    "<td>Cost</td>" +
. f$ X+ r* m" H- S5 l    "<td>Quantity</td>" + + e$ |6 i' I- B, P. }# B& q0 e& i
  "</tr>"; - V8 s' t3 v7 R% |2 C3 Z

/ I4 {* c8 ?- s+ G' i// Iterate over the BOM Items. . U* q/ Z" ]& x% s  O# h1 t
for (var i=0; i<count; ++i)
4 l; t" l- T' H' p( W' L( W{ & y- \/ G* c+ n" k( S( m$ ~/ B
// Get a handle to the relationship Item by index. * u) Q, \  N4 K3 b/ l! }
  var bom = bomItems.getItemByIndex(i);
( @7 p7 Q+ R! B+ P" z% ?& d5 X+ S// Get a handle to the related Item for this relationship Item. " C+ i% t+ f; u1 M
  var bomPart = bom.getRelatedItem(); . E% f- W6 x. g' V" g; i$ P  j6 p( f
# Z( A8 d4 C5 M/ Z; e
  content += "<tr>" +
% |" D+ f; S. q& u$ j      "<td>" + bomPart.getProperty("item_number") + "</td>" + : x! C' d/ {+ K3 s
      "<td>" + bomPart.getProperty("description") + "</td>" +
/ X/ ^8 g/ f8 T/ M  G      "<td>" + bomPart.getProperty("cost") + "</td>" +
; b/ ]- a/ c4 N) }8 q$ Z" l$ y- d      "<td>" + bom.getProperty("quantity") + "</td>" + * ?( I/ Z1 H" @
    "</tr>"; 5 O7 {2 x& d% J/ c; `2 D
} ' {7 t; P- z/ F- s2 D2 F& `3 H1 v! ]
return content + "</table>";
7 f! y  l  {' y$ E5 i
7 Z9 }6 g$ z6 w* {1 B  E

/ [2 M2 x* W/ c# m; j. c) [- |3 G8 O7 j  `- ]9 Q' D

3 I; M' g/ D8 f# v# MC#  " K0 b% z: V% g( k; @
Innovator innovator = this.newInnovator();   O9 o7 z9 X9 p& a
8 M; d; q, l) U5 h! p8 Q8 t1 r" _
// Set up the query Item. . d/ V( u3 s2 l# g: E
Item qryItem = this.newItem("Part","get");
* P% u' j% v* }0 J1 O5 q4 W% ~qryItem.setAttribute("select","item_number,description,cost"); / e6 l9 N4 N, V, Y# \8 D! @
qryItem.setID(myId);
4 {( |# r9 f! w$ r; c2 V
4 @. T  t5 q0 g- w2 `3 g// Add the BOM structure.
2 T" i& {' D$ N$ C4 y" Z$ [) {# dItem bomItem = this.newItem("Part BOM","get"); & {0 u, l/ x' [, D
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); - N% S. o/ F& S! c8 S5 p
qryItem.addRelationship(bomItem); 4 P% [& N) Z4 j, P
2 H, u2 l% m  R1 A0 i6 s# N
// Perform the query. % E& u# M7 H: B8 J8 ]4 t
Item results = qryItem.apply();
0 ?% n. b1 ~# Q
) d7 I* Y( E4 {  \  h2 V/ ?// Test for an error. , N2 Y& S. x  S6 a
if (results.isError()) { 9 ]" u9 c( R- b9 D9 Y4 ?
  return innovator.newError("Item not found: " + results.getErrorDetail()); ' t, s  x6 \0 [) H2 Z
}
8 Q* k- \6 X9 w# v% M2 f" Y
: {5 ~* b1 a& }- l: W$ W, ~% u// Get a handle to the BOM Items. 6 A9 w& O# E* g
Item bomItems = results.getRelationships();
; K& B. z' A6 fint count = bomItems.getItemCount();
3 P7 ^3 C* Q1 Xint i;
# K. g, ]3 Z+ P$ K4 h# f
5 m1 ^( C9 i0 N" ?// Create the results content. ! z* T4 o% W5 H( O/ a% L
string content = "<table border='1'>" + 3 d5 y! C/ ]& Q
  "<tr>" +
+ w2 ]4 F/ }6 t0 |6 i  G6 @    "<td>Part Number</td>" +
2 ?+ ~( i5 S' h$ P2 ?: E+ K3 t    "<td>Description</td>" +
4 f8 X9 Y; A5 H+ |6 s, u  r$ v    "<td>Cost</td>" +   m0 i, a' d; b
    "<td>Quantity</td>" +
  q" }7 k& I- b. {  "</tr>";
/ s1 z  s- {0 l9 ]6 Y
) T* i- L! |- K+ y) _// Iterate over the BOM Items. ; c: q% d1 N* T' f2 K
for (i=0; i<count; ++i) 5 d; T" @5 [7 ?, Y- t" A7 X; j# s
{ ' B- H4 D$ k1 I5 I7 D
// Get a handle to the relationship Item by index. 2 O( A, F6 P- }* S
  Item bom = bomItems.getItemByIndex(i); 6 H/ n+ E% A& ?" C
// Get a handle to the related Item for this relationship Item.
; Q7 U( x) M( V$ u2 p8 E  Item bomPart = bom.getRelatedItem(); % q" ~  A8 b4 G3 z
! c, ^$ x5 m, y6 B
  content += "" + & W0 _1 f# H* c, u# M; V
    "<tr>" + * W" `, N' _: g# f+ |" C' ^3 ]( y
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
/ J. _2 L5 R7 q; q6 M% t      "<td>" + bomPart.getProperty("description") + "</td>" + . u& r$ |, y! e* z( l8 T
      "<td>" + bomPart.getProperty("cost") + "</td>" +
2 v% M0 u. m, x, ]8 r  u0 Z! A/ F      "<td>" + bom.getProperty("quantity") + "</td>" + - t7 A. U$ e" S& T- i7 E0 w
    "</tr>";
8 N5 F( c2 z  n' R. v5 U}
& S; U* e7 ?! k- B, ucontent += "</table>"; 7 ~  U7 e3 r8 {+ b: B% W( Q

  o- R: q9 \; P- xreturn innovator.newResult(content); 6 `7 B5 j9 w$ d
4 Z' y0 d% M6 W4 k& Q

! K/ p0 R2 ?* s& J" d% b: g  \9 m8 Q+ \# o, e$ j  z
3 ^# X6 u# r- @2 ?5 Z2 A# [
: X0 a0 H- V( B) Y6 D' |

) }9 M5 R1 o) z3 h) Z6 c( @3 }: P
# e! b  k9 F7 e  d& Q    Page 46 8 f- o9 V+ F6 m' ^
3 C) n/ t! _2 ~5 q! R4 d9 v* `' Y' n8 C
Copyright   2007
; i& \& i) O* H5 Z3 i1 f5 C  e9 WAras Corporation.  
' ?; P3 ~+ q% t. \All Rights Reserved. . N! v+ f8 J! U2 N, j5 I/ z: d5 T
VB.Net  
: [! B* y! L! X$ }" SDim innovator As Innovator = Me.newInnovator()
8 p" ]7 M% A6 J# L3 _3 @ . C1 M! }7 u$ I/ y
' Set up the query Item. % X* ?1 z6 z7 L
Dim qryItem As Item = Me.newItem("Part","get") ( c0 O' u- L5 ~
qryItem.setAttribute("select","item_number,description,cost")
1 U2 V4 x5 I7 R. ?qryItem.setID(myId)
7 Q& T$ e! `- H& H0 \- y. D
$ |3 E% Z+ z4 w7 Q$ J' Add the BOM structure. 9 G" P  q# K  o" F* O7 y
Dim bomItem As Item = Me.newItem("Part BOM","get") : m  ^+ J! _) U# w
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 8 P# p6 [$ V2 D
qryItem.addRelationship(bomItem) / a) ?2 P9 B( D- z6 I& b

$ o. L1 f% E7 K% D3 x: p' Perform the query.
* l2 l: Z4 n4 VDim results As Item = qryItem.apply() ! q+ e4 b  X" G7 y' p$ G

7 x2 U0 v; o( `. V, s8 Q# j0 t8 n, d' Test for an error.
2 J9 k) P0 i* y3 hIf results.isError() Then 0 a7 K4 v; ^* i0 B8 F
  Return innovator.newError(results.getErrorDetail()) , w5 _; t% o6 c. p5 L' I* i
End If + f# G1 t# E0 G2 L; X. R. k

, F' W# M1 W, b9 i$ Y' Get a handle to the BOM Items.
2 ^" P1 A) q2 \- u4 b( NDim bomItems As Item = results.getRelationships()
; M* ~- M2 t5 [; \Dim count As Integer = bomItems.getItemCount() . u) c  z0 X6 U6 W9 f3 a
Dim i As Integer
: o  _3 u+ K7 G. b' k% T5 J + n/ B* Z3 {9 }8 R
' Create the results content.
# U; ?: k% @7 ]1 \0 sDim content As String = "<table border='1'>" + _
2 y* G" w: p' }4 y  "<tr>" + _ % `* R- q; v! w2 H
    "<td>Part Number</td>" + _
$ I1 M  V+ A# W4 ~; s  n/ b, G! {    "<td>Description</td>" + _
" |% s' j, [5 O# t  U4 W' Q! H    "<td>Cost</td>" + _ " M, r  T+ P8 |/ `2 Y/ p' F
    "<td>Quantity</td>" + _ " X: T7 \; }6 F
  "</tr>" 8 l1 t8 v& o) N* X3 \

% ~+ P, ~4 V* F' ~' Iterate over the BOM Items * G5 U# {- n! c/ g3 [1 ?
For i = 0 To count - 1 . d! s" M# _% c4 s. n
' Get a handle to the relationship Item by index.
: ~) H, E  n! R( r1 h/ x  Dim bom As Item = bomItems.getItemByIndex(i)
* l& X/ V2 |7 { * E8 Z! R' A) L) D/ ?  x- ^
' Get a handle to the related Item for this relationship Item.
: G& ~* T5 r# M9 O  Dim bomPart As Item = bom.getRelatedItem()
* P1 k  s3 z. n5 d# y$ z4 g1 e8 q
  d" h' D+ m# r& W) ~1 E: F4 t, A$ H  content += _
* S0 o6 y0 k; h6 S$ T& L& Z    "<tr>" + _ & N5 ~' V! z' e, n
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
: |- g4 u; r. T1 {      "<td>" + bomPart.getProperty("description") + "</td>" + _
* N1 L8 c: z0 C5 ~! o5 x; S      "<td>" + bomPart.getProperty("cost") + "</td>" + _
$ N! g  k. h( J* i" W      "<td>" + bom.getProperty("quantity") + "</td>" + _ , v, H1 d# S/ p6 X! L( W! n
    "</tr>"
% U1 o5 C! |5 @$ m5 N+ oNext
, [2 L0 }1 ]; A, B7 {content += "</table>" / f5 X8 N$ h3 g9 M) E1 C

  E5 e4 R, x& H# N% W8 m5 f1 jReturn innovator.newResult(content) / p% L4 Z+ L; v' {) \( I( h8 N
/ }$ z" V* E  o. h; T$ C8 ?2 O5 h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了