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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  & \9 s, T+ q2 g& \6 H# B( m! k
To query for an Item and retrieve its structure you build the query as the structure - U. I% u# Y( j1 D- z' w  T2 P# G; Z
you want returned.  Use the IOM methods to add the relationships you want and
+ l. y% z# n1 A/ R) o: fbuild the structure in the Item.  The server will return the structure that follows the . Z7 j. X6 j* _* ]. \
request structure. 4 w: ]" U3 a& Z0 ?: h+ r
This recipe illustrates several related concepts together, which are how to get a set
* ^0 p& f( \7 H3 ?5 |of Items from an Item and how to iterate over the set, plus how to get the related 4 Z+ C) U4 {: l, B) |# ^
Item from the relationship Item. 8 Q" |  ?3 P) K7 m2 O+ f/ b
JavaScript  
0 `* r8 C1 W7 K' avar innovator = this.newInnovator();
" T5 _6 u" A7 V4 C
; _8 M$ F  X: b& i3 \& k, H// Set up the query Item.
) n% E# S5 D" {- f' Wvar qryItem = this.newItem("Part","get");
) a) L  a* H( ^7 `- n- X4 LqryItem.setAttribute("select","item_number,description,cost");
. H- x" e" \; W: GqryItem.setID(myId);
$ w/ m/ U' ~4 g7 n1 \4 s
# b) Q% a; c" s& _7 T. X// Add the BOM structure. 2 N" D# b, s$ m$ E' C& S
var bomItem = this.newItem("Part BOM","get"); 6 k5 }7 x- j* v! b7 E
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
! ]5 F5 Y( z  h  }! b" s2 aqryItem.addRelationship(bomItem);
3 W" a) {1 E: Y* e! K! K% } 6 H$ e# ]5 v* V
// Perform the query. # |- {2 U% t# C. z9 {! V/ L
var results = qryItem.apply(); / _7 ]2 _6 k  A! ~  ~
1 G3 U4 \" p: Z* D$ G- B
// Test for an error.
6 k% ?4 w2 j; Yif (results.isError()) { $ Y. i$ x: J) a
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); : z9 j* ~! j/ B- l8 [9 y
  return;
6 k7 m3 c" i; D}
' V7 Q% u1 p( _6 f" C( j
1 l- m: Z* Q/ }1 F% ?// Get a handle to the BOM Items.   G; Z+ j5 n0 d
var bomItems = results.getRelationships();
6 R- g) \# D$ s( ]: Uvar count = bomItems.getItemCount();
. t' }' Z/ W/ _' X0 G( E: R) S $ }2 ]# h1 z) D. P$ i
// Create the results content. , b1 G3 v, p7 B
var content = "<table border='1'>" + ; q8 G. J) q$ ?- r. P. V
  "<tr>" + / |/ u* o% Z: I: {# A$ q
    "<td>Part Number</td>" + 2 x( ~) o& V# r8 R; o) B! ~- b
    "<td>Description</td>" +
9 i: d% w- D2 n- G8 R    "<td>Cost</td>" +
( Q) Q. w/ F, s5 ]0 ^9 k    "<td>Quantity</td>" +
% m. H1 }( X* ?" Z; {+ L  "</tr>"; 8 Z# ^9 b* R. G  A+ c
9 ]& o. A6 I" E2 T+ k
// Iterate over the BOM Items.
1 `! j$ N' o' r2 O9 zfor (var i=0; i<count; ++i) 1 N. q3 q- {+ v5 `/ e* ?
{
- t( j2 G6 q+ h7 |* E) b// Get a handle to the relationship Item by index. ; u# I, s5 U( K8 e1 c' m
  var bom = bomItems.getItemByIndex(i); % R% n" h5 b/ R* N8 x: U, r
// Get a handle to the related Item for this relationship Item. % W. p! Q7 j% L
  var bomPart = bom.getRelatedItem();
. X  a! X) ?1 K1 ?
0 y3 ^: ^% ]. p* ~, `  content += "<tr>" + 4 T6 @: |9 S% y+ B5 h
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
8 B6 i: w9 _+ |& r      "<td>" + bomPart.getProperty("description") + "</td>" + & b, c; A$ y3 \: o: Z: t
      "<td>" + bomPart.getProperty("cost") + "</td>" + , K+ V. r0 S( ~6 [6 Q" O9 ]
      "<td>" + bom.getProperty("quantity") + "</td>" +
$ u3 j5 ?- a. x# G9 r8 w    "</tr>"; 8 v* n! }: }: m* t& T
}
% g# b3 {) X% B% N* Dreturn content + "</table>";1 l  X! E( v0 M5 }5 t! Y

7 J! F; p7 y9 m6 F

8 \: G+ Q4 Y  H) R
. l* L+ x* H3 d& k" |

; w& w! a4 I) ?7 VC#  8 q2 d# R  l# l' G* v1 E$ y* h
Innovator innovator = this.newInnovator(); 4 e0 ]5 X/ o/ n- R9 ~

$ K6 {0 \! `# B// Set up the query Item. # S1 {+ |! T3 d+ M0 Q7 o. x
Item qryItem = this.newItem("Part","get"); 4 e  D* ?3 W  Y3 m- y
qryItem.setAttribute("select","item_number,description,cost");
( S4 x* T% u; [$ B0 b# G$ g2 ?# \5 OqryItem.setID(myId); , {8 k! {" o6 V0 d# o6 A2 W

- h! P" E& W& j" a( Y0 [3 L. [// Add the BOM structure.
7 |! \* g* T7 D* E, ]Item bomItem = this.newItem("Part BOM","get"); 2 E; n- n! H) ]9 ^+ s7 H
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 9 \+ R$ J1 P4 d, L
qryItem.addRelationship(bomItem); $ {% E3 B( `& H9 L1 v% e

9 N, ?3 C5 x" ~// Perform the query.
# q+ G: H" s6 x, oItem results = qryItem.apply();
' U; L" e% V7 n9 D9 f# a; O( o2 { 8 Z; q. q4 T# S7 t: G" Y
// Test for an error. * w% d0 Z" n5 j+ X
if (results.isError()) { $ a# J6 o$ D" c# d& c
  return innovator.newError("Item not found: " + results.getErrorDetail());
* U2 d9 x2 \% j}
. _/ M" i& a9 T/ s& z + Q9 C% f# X, ?  V7 \9 D" G, l
// Get a handle to the BOM Items. " H+ a" m0 Z! N% b
Item bomItems = results.getRelationships(); ' a. S' [& \7 [& T3 a/ T! y0 P+ W
int count = bomItems.getItemCount();
+ O! q8 Y7 |) A/ U) |int i; : z# x! V$ h7 B2 b9 }
& F: ?% H$ b* C+ Z. L
// Create the results content.
2 I3 W0 Y2 C. Astring content = "<table border='1'>" +
6 p6 W8 _7 U) [. t8 d9 `  _  "<tr>" + 1 l7 x( U" o1 M
    "<td>Part Number</td>" + # t+ ~: k; h( r$ E
    "<td>Description</td>" +
) l7 o8 P' |3 B0 j* M    "<td>Cost</td>" +
6 [7 Q( M  X* z* e$ x# P! `    "<td>Quantity</td>" +
8 ~2 m; P( b( |+ ]- N# C  "</tr>";
) y1 Q3 [1 e$ N% a / R# D+ f4 @3 {- v  {% a7 q* O3 ?
// Iterate over the BOM Items.
5 @5 G# E" B6 V% P( }& Kfor (i=0; i<count; ++i)
) ~' b$ Q: e3 {{ ' E! {$ T4 X& i5 X0 n3 u, z; g* V
// Get a handle to the relationship Item by index.
% l+ N  ~  ^6 g  Item bom = bomItems.getItemByIndex(i);
; O! T. @; }( {1 K// Get a handle to the related Item for this relationship Item.
* x4 X  s. {3 ^5 a  Item bomPart = bom.getRelatedItem();
# H' l' u2 \2 {
: W; p! ^  H  g7 F  content += "" + * R/ b# |% O9 L$ K9 ~: m, R& r
    "<tr>" + & z$ I& m/ C4 h% B0 V3 E
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 6 j8 Q* ^! c8 N6 j! y) H! |
      "<td>" + bomPart.getProperty("description") + "</td>" + # M7 J2 k* x* z, O! X: i
      "<td>" + bomPart.getProperty("cost") + "</td>" + % y/ v2 t1 [) ^* x- ?- C: Q/ Q
      "<td>" + bom.getProperty("quantity") + "</td>" +
) ^! p' e: Q. M  i9 {7 O4 {    "</tr>"; 6 r! e9 S3 `! G& ~
}
+ y" U3 z& z: h0 u+ vcontent += "</table>";
+ e  N- F" S+ v, x8 D ! [+ J) n' d4 e) f
return innovator.newResult(content); - L$ q, e! ^$ b2 Z/ Z( i7 L

# [1 a. s# k% y' K6 m( w4 G2 `% @

6 A4 ?( u- `1 v/ V( Z8 M9 b, M, g8 F; D! I$ U; a9 Z/ U9 V

: Z9 O, X' @1 H4 R1 \# U/ `5 @$ I& a) e8 O# }
0 e8 C& B2 N1 r; p: B

, f( {; \* I& j' P# S  c* F    Page 46
0 t# z0 l+ b- k7 e3 Q: V* e
' P4 N7 {/ I' f4 b; A" dCopyright   2007 2 z2 P' e8 l4 s7 L
Aras Corporation.  
" O! l' e8 G' H- `5 v, G7 X7 eAll Rights Reserved. , x" G7 N0 x( T. t, P( m
VB.Net    w$ U% O5 T0 w  }' r3 _
Dim innovator As Innovator = Me.newInnovator()
+ ?1 b4 }: Z5 P- {
3 B9 Q' n. U- N& A1 O0 l' Set up the query Item. ) K# Z# G1 n6 i" }1 s  S- t
Dim qryItem As Item = Me.newItem("Part","get") 3 _; f$ D2 [: Z" s) i" s2 B# V8 D/ h
qryItem.setAttribute("select","item_number,description,cost")
& s" j4 d5 e9 k% I+ TqryItem.setID(myId)
8 y5 N& v* v# R1 _4 Z ) D1 _  {' t9 Y. f' K- K
' Add the BOM structure. 5 U/ H# i" N. Y& g6 X
Dim bomItem As Item = Me.newItem("Part BOM","get") 2 }: Z  U5 |- m" g& [" i6 s5 L7 j
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
  q# H" o  u  R! R" Y+ MqryItem.addRelationship(bomItem)
0 d3 Q" K/ J5 o3 N2 H, n8 ]- M: c6 Z
; |. D9 Q8 {0 Y/ }* L' Perform the query. + g# [+ g6 ?  v2 m
Dim results As Item = qryItem.apply()
  S' i, _5 i8 S0 I7 J5 s# M
8 w/ D/ l: F% [% k* \$ t8 _" G' o, x' Test for an error. 4 B+ u) T- s9 ~+ t, T
If results.isError() Then
/ o; i% o/ d/ E: a8 x+ ]  Return innovator.newError(results.getErrorDetail())   Q" }+ @/ l& s( Q7 C
End If
& @* L3 o+ \! a" [* Y' }6 b1 N . ]" l7 T( u9 @& V2 n1 T' B
' Get a handle to the BOM Items. : N1 ?  h# g2 s6 g) u. {
Dim bomItems As Item = results.getRelationships() 7 _  F8 L% [( v9 r$ h
Dim count As Integer = bomItems.getItemCount()
7 X4 G& o% A, q3 YDim i As Integer , f, n; i) ~0 z0 e
5 K: F: s* F: d% Z) K9 {9 }
' Create the results content.
3 ^- o2 E0 q5 ]) P8 `3 SDim content As String = "<table border='1'>" + _ 7 w( Q+ q* N0 O
  "<tr>" + _ 5 B; S9 K0 s3 w& F
    "<td>Part Number</td>" + _
- e9 u% c7 K! I    "<td>Description</td>" + _ ; E0 w, s% P( u2 Y+ z
    "<td>Cost</td>" + _ 8 K4 h$ s5 e% z
    "<td>Quantity</td>" + _
/ [3 ?, X0 b6 Q+ t+ q, O  "</tr>" + n: O( h0 `# U  W, ~+ d; O7 h# O
4 f3 O. n7 Q8 x; g
' Iterate over the BOM Items
) g' L* W* F* H7 i6 \/ i/ }For i = 0 To count - 1
4 C) j. E$ z: I- \" ?  _' Get a handle to the relationship Item by index.
" n8 m! c( w3 m. g% q. f2 x8 }  Dim bom As Item = bomItems.getItemByIndex(i) 4 P2 D4 b7 W, r3 X+ H
5 Y( b4 ^; b' x. D
' Get a handle to the related Item for this relationship Item.
# B0 l/ h0 u1 D4 |: o  Dim bomPart As Item = bom.getRelatedItem() # ~; x! [" I" n9 }  O- I
" I8 ~2 B6 a  U
  content += _ : D% q! m- m- X( s# T
    "<tr>" + _ ( ~6 j0 F4 _/ S: R) J, i$ f
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 6 {4 I3 n" ~$ Q: P) ?3 R* g
      "<td>" + bomPart.getProperty("description") + "</td>" + _ ; }6 L! b+ U7 p8 U5 W, T/ f
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 0 M3 l8 N( D- w" Z# S2 ~* ]
      "<td>" + bom.getProperty("quantity") + "</td>" + _
2 e) q- v8 g9 a    "</tr>" 0 ^- e3 t! a! {
Next
3 y$ k! F$ B* Z9 ~; |content += "</table>"
# I9 O0 }) W# S/ d# m # C2 H1 D3 M3 `' |7 h2 Z
Return innovator.newResult(content)
$ Q: q; ]( C# o2 ?4 t7 ]1 G
. U7 U1 \" d+ {0 a6 \) Z4 a
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了