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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
4 I; N  Z, }1 TTo query for an Item and retrieve its structure you build the query as the structure
( o. j+ W! o# @you want returned.  Use the IOM methods to add the relationships you want and   A: q+ L% }% F# b7 V) C: r
build the structure in the Item.  The server will return the structure that follows the
8 ^% _' `+ V5 n; p5 A5 Vrequest structure.
7 b5 \# o" l6 i7 L) ?0 `9 rThis recipe illustrates several related concepts together, which are how to get a set
( N  e0 n- M5 D+ Rof Items from an Item and how to iterate over the set, plus how to get the related 4 e. p: B8 \& K# J# L% U
Item from the relationship Item.
' F/ O5 B1 X( RJavaScript  
! @3 E8 S! [1 L* T) B4 B* Tvar innovator = this.newInnovator(); + \  d* T% R9 G4 W
8 m& A7 O8 _6 \1 l  l
// Set up the query Item.
( c& r( v8 q, J7 e7 H  |5 X8 i# a. mvar qryItem = this.newItem("Part","get"); # V* J/ r* o4 m3 o& X8 E+ A* P
qryItem.setAttribute("select","item_number,description,cost"); 4 s+ E, r2 g2 |" U6 q8 ]
qryItem.setID(myId);
7 r3 d( f8 j3 w, [ & Z& a) u' P* R
// Add the BOM structure.
' O, c; {1 u. ]5 @$ }( i( s9 [var bomItem = this.newItem("Part BOM","get");
7 g# _5 P! F* l0 cbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 5 i! Y$ a) B  L3 M* |- M
qryItem.addRelationship(bomItem);
+ }0 T; o/ B2 `) h4 [9 P! F 5 _1 Z+ Z1 ~) R; N) I" m
// Perform the query.
: L% W4 V6 M+ N" ]2 |1 d) n% Kvar results = qryItem.apply(); % Y: v3 M8 ~; O# v
1 Q: b9 p( v- r/ ~) K8 I
// Test for an error. ! A# |* M# v- x& _3 c
if (results.isError()) {
" ?" h6 _  Y6 F& y- {! H* S+ ~( s  top.aras.AlertError("Item not found: " + results.getErrorDetail());
$ M  V- h; N' q/ w) }* O& t  return; " I8 x6 K) z. `) H/ }1 q$ R
}
& y  `% W* {" ~, l 7 Z! O3 E6 p6 h
// Get a handle to the BOM Items. 9 C4 w7 s0 Q6 }1 A8 w. z! V
var bomItems = results.getRelationships();
" X, X3 }& [- Zvar count = bomItems.getItemCount();
2 i6 k, \# y3 J; } ) V/ N7 A3 J- C5 N9 Q8 i) h9 [
// Create the results content. 1 v* {$ M( ^5 p6 ~7 c
var content = "<table border='1'>" + , Z* F8 |( U, Z6 ^. _1 g
  "<tr>" + : y% N. k9 n' p7 ^' t- V" f
    "<td>Part Number</td>" + 3 Z+ i( w6 S& r, _$ I
    "<td>Description</td>" + $ v$ D2 j' E. f7 t6 t, b# x
    "<td>Cost</td>" + 3 m5 K/ z" @: W7 D' [  S/ m
    "<td>Quantity</td>" +
; L9 M4 N# m. W2 R8 G) i+ R  "</tr>";
- G9 |- |1 ?% v8 Q/ N6 G
% n# i% y8 L- @// Iterate over the BOM Items.
& j* u& _4 v3 g6 w7 U7 ^for (var i=0; i<count; ++i)
5 g1 ]7 J' u0 ]9 N( v" T{ / w3 p, W1 r4 l. e! i
// Get a handle to the relationship Item by index.
' ^3 z5 e' P3 y  var bom = bomItems.getItemByIndex(i); ' G& p, Q# ~; p( c5 c# I# |3 S
// Get a handle to the related Item for this relationship Item.
  ~% Q% A4 T6 `7 `. ], F. w  var bomPart = bom.getRelatedItem(); / r3 K% Q: B  T2 b
. H4 z1 f& F+ u
  content += "<tr>" + 0 L! E7 u, v# y8 P
      "<td>" + bomPart.getProperty("item_number") + "</td>" + , D- j2 ^- x; ?8 J; W# _
      "<td>" + bomPart.getProperty("description") + "</td>" +
" c  ]# D4 ?& K/ ]' A      "<td>" + bomPart.getProperty("cost") + "</td>" +
5 Z- r. u+ t/ I. f      "<td>" + bom.getProperty("quantity") + "</td>" + 8 J( w5 ^- Z3 A1 o% a5 A" x
    "</tr>"; 8 I' q/ B- @! }( J8 g- n
}
" m2 n) R9 O# mreturn content + "</table>";( h4 U3 P* u7 @; \, K1 r
% g# s% _8 \% M) F  g1 x

* @, C- r" \7 {. P7 v$ @& o* o3 ^

6 O8 [' V. C) F, P# }  ^C#  
3 |  Y9 O( g. s5 M- g, L$ jInnovator innovator = this.newInnovator(); 9 N8 W9 b7 m0 ~# V/ }- L6 B. D

: B! u6 R  ~0 Q% ]// Set up the query Item. # @+ Z1 s3 C( v
Item qryItem = this.newItem("Part","get"); $ ~$ x' }/ h  ]9 j( f, W" S
qryItem.setAttribute("select","item_number,description,cost");
& q& M. Q* v, `6 j& ~# hqryItem.setID(myId); ) _, Y" v' P* ]6 q8 a3 U* E1 d1 q0 f) D

- X1 Y- |+ k% y" u3 T// Add the BOM structure.
1 j+ U% {2 c5 ~$ h' JItem bomItem = this.newItem("Part BOM","get");
# `6 |5 v0 E; h; m) r1 ~bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); + ]- b2 l/ `: B
qryItem.addRelationship(bomItem);
8 c; \# ?. |8 A( }) b ! {% w- z# V% x' n
// Perform the query.
# f- J, P/ ?1 ~0 _Item results = qryItem.apply(); 9 ]" s" l6 X5 C; q1 {1 d
: D! h; P8 T+ g4 G" e  b
// Test for an error.
- |+ B, ~$ z* F& t( ?# ?if (results.isError()) {
4 E/ @2 |2 \6 x  return innovator.newError("Item not found: " + results.getErrorDetail()); 4 S: r4 v  k2 X. F, u3 W+ \  K
}
/ m- o- {6 O5 Z, x2 L+ I" E! V
* q4 d! P$ A) h; r// Get a handle to the BOM Items.
, S4 }* x  c+ R& }Item bomItems = results.getRelationships(); 5 _) ?1 Q5 ^; x% a: V; L: A- z& e
int count = bomItems.getItemCount();
" ?0 J- ^7 u( |: S5 @/ ]# c( rint i;
7 g6 T" O0 _+ [5 L0 G$ x5 e  A
6 }$ p7 y+ P4 U' u// Create the results content.
4 D, M5 [( Q! ?. ~string content = "<table border='1'>" +
% ^( T& h. M. \- x  "<tr>" +
, M; L+ U& R. ?  C' I    "<td>Part Number</td>" +
2 S0 M2 `8 w4 B! X* d2 X/ j, l    "<td>Description</td>" + $ @. {, Q0 f; f- u3 G
    "<td>Cost</td>" + , F; G' q. p7 `  S; C
    "<td>Quantity</td>" +
. G, d- y6 B$ Y, F' T$ p  "</tr>"; 8 e1 G+ D: d/ U- X7 i
1 s, b$ `( _+ H- w% t
// Iterate over the BOM Items. $ D! D6 U, n+ R/ H
for (i=0; i<count; ++i)
# U' U; x  A1 p9 m( `! M{
6 B0 L+ V5 D3 q: ?7 L8 D2 T// Get a handle to the relationship Item by index. 5 d. b) C, B" c/ ~/ }0 b
  Item bom = bomItems.getItemByIndex(i); ' t) y$ V; H7 H8 R3 j1 Y
// Get a handle to the related Item for this relationship Item.
$ y" Z5 Z) U0 F$ Y9 |4 n( q& q: G  Item bomPart = bom.getRelatedItem(); ! v5 a4 o3 j5 m& x% a- ~7 u
' G+ Q$ B9 B) G/ p9 C9 I7 f/ ~
  content += "" +
3 f. F. v- S. {1 z    "<tr>" +
, k$ H" Q/ ~1 N0 g. [      "<td>" + bomPart.getProperty("item_number") + "</td>" + 2 ]0 M: k1 _/ w
      "<td>" + bomPart.getProperty("description") + "</td>" +
# J: @0 b, z; ^7 C4 F) X( p+ _      "<td>" + bomPart.getProperty("cost") + "</td>" + 3 c4 d% T3 p1 w
      "<td>" + bom.getProperty("quantity") + "</td>" +
1 O9 k% M6 L0 l3 Q! Q- V6 X    "</tr>";
! {* l3 B0 I2 |( M} : J. d' h. D4 d) o, `
content += "</table>";
3 E% T* G+ j9 V0 P) V ' C7 m+ ~( [( z* \( w% ]
return innovator.newResult(content); ' H9 O' p+ u! |( G; N6 W

8 }& O! v2 W# K
+ W3 p, u" g4 T4 n7 G: x3 C$ P3 m

* p, h0 ~- Y$ f! K, j
% V) B$ A/ G; D! d# }0 S

* \% P+ m3 S% L  L- N
0 q- B5 K4 R2 j' n. X& t1 _: k: Y

6 u3 z/ [6 i" n/ A4 ~" M. L$ f; o3 k& L    Page 46 8 z9 S0 S3 M  w, X$ {

2 B& x" q+ c% w, tCopyright   2007 4 H9 g* m' Q1 L/ H
Aras Corporation.  % ^8 P4 q1 ^- A+ H- D1 S6 e8 A
All Rights Reserved.
" e) v, `* D4 K6 s/ uVB.Net  . y& J- F" B0 A+ H
Dim innovator As Innovator = Me.newInnovator()
! \: n2 `6 W( O* b: f- R/ g* _) v: v
! I: z- B  g3 U% B* a+ |' Set up the query Item.
" G8 v4 p3 a( C2 L' f+ @' LDim qryItem As Item = Me.newItem("Part","get") + a; F2 p" @6 G# F
qryItem.setAttribute("select","item_number,description,cost") & [% I4 v% t; L& E' b: N* |
qryItem.setID(myId)
. o$ s: s" B" c
! \) z8 r% z: R- ~' Add the BOM structure. ; |. K9 s1 Y- U$ `# D! H- N8 L
Dim bomItem As Item = Me.newItem("Part BOM","get")
! d* ?6 G, d6 i) m: s) I7 M, @bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
+ N( q, {) O  i- Q  ^( ?qryItem.addRelationship(bomItem) - D, S4 d- r3 F3 B

+ ^! ~+ W2 I4 ?) G4 I( G- L9 _' Perform the query. 5 b) B' s* \- p9 [; f/ z7 m# A
Dim results As Item = qryItem.apply() ( c% n1 z% ~5 J3 i. c* B2 ?2 H
% F, z% R% [' C$ p1 f9 ^$ }
' Test for an error.
0 a! f: E/ ~3 k+ s3 X0 A: v, rIf results.isError() Then
, d3 t8 B/ J9 K& y. v2 d% G$ q6 @  Return innovator.newError(results.getErrorDetail())
" I) B/ g) k. h0 e$ mEnd If
/ @6 e: `' i9 L2 a8 g9 f: s6 X5 \0 c
# B5 K+ f3 U1 R- I' Get a handle to the BOM Items.
% T- s3 U2 j  C2 |Dim bomItems As Item = results.getRelationships()
! h  X3 L- d0 f9 F8 `Dim count As Integer = bomItems.getItemCount() 5 b% _5 Z5 e1 e7 v* m
Dim i As Integer ) `( h$ P6 V/ e5 f
/ O) S, h- ]9 |( [
' Create the results content. ) m) j/ `' k6 l) k
Dim content As String = "<table border='1'>" + _
) K! v2 h. c9 O9 x1 v6 Y( |  "<tr>" + _ ; O: i6 G1 _4 n3 {; k2 K" O
    "<td>Part Number</td>" + _
- H" m2 A3 a# [$ W    "<td>Description</td>" + _ ; _5 d( U3 @1 V) k3 K
    "<td>Cost</td>" + _
2 a9 z) z% Q7 T1 ?$ e8 l    "<td>Quantity</td>" + _ 9 M' k' A% ]/ e6 v! O8 i
  "</tr>"
9 k% c7 A: T) y8 a  a
1 O$ {& g; J: j' I& S' Iterate over the BOM Items
3 ?9 {0 B# S) Q0 m! |For i = 0 To count - 1
0 u* {, K$ w8 V$ U) T1 ~' Get a handle to the relationship Item by index. # v- ~% |5 Q; O
  Dim bom As Item = bomItems.getItemByIndex(i) ' u6 l' k3 B/ O$ F  v+ {' P5 d$ ]  T

6 C/ t8 p. t3 Y  s: K' Get a handle to the related Item for this relationship Item.
7 }# Y% |8 O" n9 T% h4 _  Dim bomPart As Item = bom.getRelatedItem()
: G& g$ V4 E- ?$ J4 v" f4 B 1 c; h" P+ j+ Y, }5 w5 e( a
  content += _
2 Q- Y/ ^( R- I- N, H    "<tr>" + _ " ^" J% c4 l8 n
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ - G# I5 p3 U0 f5 }/ W7 a
      "<td>" + bomPart.getProperty("description") + "</td>" + _
+ v7 i2 k# E. J1 V: U      "<td>" + bomPart.getProperty("cost") + "</td>" + _
6 h7 L& Y2 N; i      "<td>" + bom.getProperty("quantity") + "</td>" + _ 8 v0 `0 @- X2 Z+ A
    "</tr>" + V" \, a5 C* ]
Next
+ s  e  z' Z) D+ c+ bcontent += "</table>" $ D& u6 t; @* H* U  R: s
! s3 o; g7 l: K$ d& T
Return innovator.newResult(content)
0 b* C: U( D# d9 N$ H6 o$ A0 |' M" s% W$ s
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了