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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
. w5 U- Z' a( _( U5 sTo query for an Item and retrieve its structure you build the query as the structure " ^2 M6 N4 j% }, j1 a; Y6 D
you want returned.  Use the IOM methods to add the relationships you want and ' t+ [* R0 W$ U0 G9 C- D) A
build the structure in the Item.  The server will return the structure that follows the / q5 L' o, I$ U, d! P
request structure. : K" R& ?4 w5 p: x0 D
This recipe illustrates several related concepts together, which are how to get a set 7 y- D* D8 H2 f- M: a
of Items from an Item and how to iterate over the set, plus how to get the related % Y% _0 s: O/ \: f: T. @  q
Item from the relationship Item. % R0 W; V4 ]& t5 D
JavaScript  % B0 f9 X5 @( q+ P& A  O7 H4 }
var innovator = this.newInnovator(); , M9 r: c/ d. {0 V: B. O7 @
) E+ ~9 g  F! c1 z
// Set up the query Item.
1 x) C. b  H7 e+ F8 z5 i8 Bvar qryItem = this.newItem("Part","get"); $ T! W4 V) U1 a" u8 _0 T2 r9 q  J  _4 X
qryItem.setAttribute("select","item_number,description,cost"); 2 m( B) _" F* D3 q" U$ l
qryItem.setID(myId); + ?: I7 ]6 Q: b. N

* }  N4 Z" J$ t0 W// Add the BOM structure.
* ?, [% x! u' e4 C/ z3 f# @1 Ivar bomItem = this.newItem("Part BOM","get");
0 u0 n( Q" ?& q  Z& \8 HbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); % R& {6 k% y8 q; H- L3 _! ?2 x
qryItem.addRelationship(bomItem);
: `" u; d& j; `! g! x/ \' G0 v0 r   ^! M4 G5 C6 ?, {9 i
// Perform the query.
* |! K/ G# x1 o9 H5 z2 U/ Yvar results = qryItem.apply();
, c! \$ f- L: |  [) m, @  Q) E
' j8 E  r6 R7 t// Test for an error. % |" O5 N$ v% f2 H8 ]4 o
if (results.isError()) { 9 u8 s. [" v' D2 d. y
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 9 w! z6 z9 q4 \9 E# x; V+ _+ a
  return; 2 {# G" B) s- S6 o7 j4 n( I
} , w" C# k) Z4 f* p6 v1 o7 [9 V
7 I8 b/ S  k7 i2 _
// Get a handle to the BOM Items. % B, P1 ]3 c$ @+ O
var bomItems = results.getRelationships(); & v3 b! q" Q- G9 ]' r8 n
var count = bomItems.getItemCount(); . o8 B5 g9 k- B' f
6 S4 j' Q; V2 ?5 i6 E: y6 w' n
// Create the results content. 8 Z( ^# T; B% H2 X2 c5 p
var content = "<table border='1'>" + : W2 ?1 T$ w7 T8 e* I+ h1 Z- q
  "<tr>" + - g% k: x6 I1 ?2 u) R: }* i
    "<td>Part Number</td>" +
, l* K+ X# ^" R* i3 Y) ^; ~+ \    "<td>Description</td>" +
' {3 \: a. o# v* Z% a1 n    "<td>Cost</td>" +
* k" W$ {2 Z# D" @& O    "<td>Quantity</td>" +
$ @; q8 P- L# A6 G) X  "</tr>"; # \" j  r  `% D" Z8 |; c- w; ^. J
. q/ H1 A- J1 i# E, v
// Iterate over the BOM Items.
8 r2 a' ~/ D) vfor (var i=0; i<count; ++i)
& v: p% v/ W2 N3 u  Q' q{ 0 p" A( _% n  A+ f4 M* e6 Q
// Get a handle to the relationship Item by index.
$ ?* W7 l+ q0 Q# [0 A  var bom = bomItems.getItemByIndex(i); ! @8 U1 t+ Y, `  p( m4 ?
// Get a handle to the related Item for this relationship Item.
. a$ t) H+ |: S  |( O7 y5 u  var bomPart = bom.getRelatedItem();
7 u7 _! x4 n- F' n . S! d" S7 I3 H# e6 r
  content += "<tr>" +
- P* B/ m: ^0 C9 v$ a      "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 p3 E0 J: e0 T+ T2 e      "<td>" + bomPart.getProperty("description") + "</td>" + * ~2 f# K7 u% I# _& H* Z1 a
      "<td>" + bomPart.getProperty("cost") + "</td>" + ; ~$ O/ G  p" i
      "<td>" + bom.getProperty("quantity") + "</td>" +
% A" u. ?' U+ c: |: B9 q    "</tr>"; 6 a- O* R1 G) N' s
}
5 S$ }; S5 O) Q4 h1 f. Vreturn content + "</table>";! m* G% ~2 M/ t

8 o1 J' B) S! B+ u+ u$ B: c

* U3 X8 L# J2 ~2 s% I  C& q5 u$ Q& s
  }) C; g( ?% q* Z# K) C
C#  
6 Y# W4 u6 Y3 ~0 x; j; w; \, |Innovator innovator = this.newInnovator();
! g  Q" j( d. O5 K6 l9 X/ J 4 l( Y% g2 ~( _  j8 s# h5 T
// Set up the query Item.
3 n" `0 }9 N2 d/ Q" ^2 G5 ?Item qryItem = this.newItem("Part","get");
$ d9 ?' [# R% e& l0 f3 [! }qryItem.setAttribute("select","item_number,description,cost");
( {- b0 M+ X; mqryItem.setID(myId); 8 L  H% c6 B5 L: j' a' u
5 A3 R- f/ L5 N( M; N5 {
// Add the BOM structure. / a* I; |7 g3 ?6 i  K' n8 P
Item bomItem = this.newItem("Part BOM","get");
4 |0 I' A8 G3 `( V& C5 qbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); - Z- _5 q  T- X" C4 ~
qryItem.addRelationship(bomItem); * s, Q- Q9 s- ?
( e5 C( n/ c; _: U
// Perform the query.
. I  j: m0 ~: V, i4 @2 A: DItem results = qryItem.apply(); 8 ^; m. s: o! x  \* F  \

$ D6 V9 j6 E# S& s// Test for an error.
- K% v' r$ ]& \3 g' k: cif (results.isError()) {
# J$ s$ a$ D9 f1 t$ H2 @  return innovator.newError("Item not found: " + results.getErrorDetail());
; ?4 e: ^7 y: @( J} # }1 T5 U5 t8 ~2 }" L

- X% e" ]) \4 p6 P' O6 W  p  _! n// Get a handle to the BOM Items. ; q5 c, y- Q: J" z( x5 ~% B
Item bomItems = results.getRelationships(); 5 V8 r  k! L3 \6 s- c
int count = bomItems.getItemCount(); . ]* L- {9 c# ]* B1 [9 J
int i;
- u% q( S/ J2 Y( y1 Z* p
2 ~' q7 B9 ?0 R# d# V// Create the results content. 4 W. p/ c! ^' e4 h5 \; ~) F( U
string content = "<table border='1'>" + ( g- z" w  q+ c+ _
  "<tr>" + # y; V) F3 C# a: e9 D  Z; `0 C2 i
    "<td>Part Number</td>" + 1 [4 u2 {4 ]2 |( J; p+ I8 g+ p
    "<td>Description</td>" + 4 B& z0 `& u) U, \- A
    "<td>Cost</td>" +
( P3 w3 @4 i6 j  T2 b% z% U    "<td>Quantity</td>" +
, y$ q) M5 P/ d! t7 h/ Q& _) f( a( m  "</tr>";
+ p2 D: Q/ D# y+ n   i* ?% ~3 ^+ o% \- A
// Iterate over the BOM Items. ; u6 `8 @+ g- r. c& }
for (i=0; i<count; ++i) : F, U+ y, H0 {% @
{
- S- J2 h& {6 Z! j- K7 R// Get a handle to the relationship Item by index. ' d+ q. P" J" ^: H
  Item bom = bomItems.getItemByIndex(i);
3 H5 s7 P$ l  |1 t4 H// Get a handle to the related Item for this relationship Item.
3 ~5 S, V, o% M. h* v9 |# m  Item bomPart = bom.getRelatedItem();   k4 A' X/ ^0 H; g9 Y
4 L( C7 M7 S* s2 u; j8 T
  content += "" +
; q* H5 d/ c' R* B0 ?! T    "<tr>" + 1 @$ `  T1 s6 _' X6 e
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
# T/ s/ O) T  M2 R) y+ N( [      "<td>" + bomPart.getProperty("description") + "</td>" + 5 ~/ G: Q* b" l% E3 G4 n
      "<td>" + bomPart.getProperty("cost") + "</td>" +
  k) B2 _5 o2 A) A8 f! h) |      "<td>" + bom.getProperty("quantity") + "</td>" +
8 y- [6 u/ ^, ~# O) t6 y    "</tr>"; 0 X4 n. p6 S( P3 c& K1 `
}
: B  m( a1 o( m6 bcontent += "</table>";
, K9 W$ q8 j1 A4 m2 J. Y
3 |" g# J  y6 {5 b3 Ereturn innovator.newResult(content);
( a% n- s$ N) C7 Y7 x. D2 n' l; W. J! ^$ G( w# w. W" t

+ w0 Y7 t9 l. c  x
! U# R: q) t5 l8 L  r8 D. I

& Y0 C) I. E8 X% Z, J9 r4 |* J+ V$ U# U5 }* U! k! w

& ^5 c' X$ ?: n
6 z* K4 J% n* g9 O+ S    Page 46 ( w: @' m# K0 Q7 y# K. m, _

7 d- R6 }9 k/ iCopyright   2007
3 i3 J* H- p  r9 j: CAras Corporation.  
' X, @, {$ x! ]: G; tAll Rights Reserved.
4 E4 _' a# f( aVB.Net  5 o5 D0 k: S4 n) w9 C3 a' s
Dim innovator As Innovator = Me.newInnovator()
, u$ V3 f& X9 \+ Y' i% z
( u  t8 F- U+ {; `, e' Set up the query Item.
; u& Q" s/ f! n( R: cDim qryItem As Item = Me.newItem("Part","get") 1 O* Q. a9 K0 K$ t# w
qryItem.setAttribute("select","item_number,description,cost")
0 F7 n- R6 Q1 R: ^- @0 E! oqryItem.setID(myId)
1 E8 k& Z+ c4 Z2 v, \0 \ 5 w* ]2 D9 [( a( ~( u1 Y/ l
' Add the BOM structure.   e* {8 U* w. E; [
Dim bomItem As Item = Me.newItem("Part BOM","get")
8 |0 S- P8 ~* a6 X* X' rbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 3 ^" M4 Q7 S) K2 D
qryItem.addRelationship(bomItem) $ ~* [3 o. e" f# E! J2 d  ]/ f

5 n5 [9 u  ?- W4 F, Q' Perform the query. : k. n) R8 I6 V4 K
Dim results As Item = qryItem.apply()
3 L/ W' i8 B8 F8 }5 U% {$ p1 h # c/ v8 g6 |1 L* i2 B
' Test for an error. ) D: X# f7 k1 d& J
If results.isError() Then 3 B8 x: [: F1 p. S# ~& d
  Return innovator.newError(results.getErrorDetail()) 2 z! n+ r( B. m  n& f! F
End If ) J+ H4 D. a& u+ O( M& I

# q; h0 i! Q. i: V. J2 y+ a' Get a handle to the BOM Items. ( |7 ?$ ?. @5 R1 U7 v$ O
Dim bomItems As Item = results.getRelationships() 0 X- @1 L; u" c" U2 n) G
Dim count As Integer = bomItems.getItemCount() 9 Z* Z- t- g5 b7 c
Dim i As Integer 8 {& k2 e) O4 N$ b
+ P0 o+ I/ h4 J1 j! m% x
' Create the results content. 7 Z) @* A5 \% o$ Y
Dim content As String = "<table border='1'>" + _ 8 Y. E; y5 I3 m$ c5 z1 I) B  d5 Y
  "<tr>" + _
' x5 j4 ^  R# q2 ^9 e    "<td>Part Number</td>" + _ ( H! g- B& k  A. H! ]! a* f" `8 h! @
    "<td>Description</td>" + _ * _+ q1 U5 W$ M
    "<td>Cost</td>" + _
& _& c" r3 U" l    "<td>Quantity</td>" + _ 9 ]& P3 c' Q# q# o. g5 E% w) g
  "</tr>" - l/ Z4 O1 j, D  H
( u+ S1 J* z3 T# c: t' l
' Iterate over the BOM Items
8 I3 g8 f* `7 N% \- ^For i = 0 To count - 1 1 ^* z" E$ x! Q
' Get a handle to the relationship Item by index. ( a  F3 `) i& F8 Q1 U) D
  Dim bom As Item = bomItems.getItemByIndex(i)
* Y. J8 \5 n/ ^+ w! |. S" _
. c7 v/ z& e5 S* t8 c# c: H' Get a handle to the related Item for this relationship Item.
9 A; b! Y% _: |+ Z% M  Dim bomPart As Item = bom.getRelatedItem() ) i* G6 y/ I' g$ G) g& C1 P

6 E. B' k' @9 g3 x: {: {  content += _
3 g2 g0 D+ }3 Q2 U/ J    "<tr>" + _
2 u* u2 `; q" I; [5 i  t$ b      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ \; [# m! k4 T
      "<td>" + bomPart.getProperty("description") + "</td>" + _ % r/ y# q: F5 `+ r2 M
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 6 A; j; S3 a6 E+ P3 J2 L" _
      "<td>" + bom.getProperty("quantity") + "</td>" + _ : `' s. _/ \* s, x# W! _
    "</tr>" + h; z4 L1 j$ J
Next
' Z1 _7 K' |! ?! ^9 w' Icontent += "</table>"
2 V4 c; h, H0 T8 g5 a # ~8 i  A& `3 E, h0 l" ^0 B( O" u2 r
Return innovator.newResult(content) : D( \$ W- {) ~* E7 J, ~

/ K9 w1 u+ [; {, L( 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二次开发专题模块培训报名开始啦

    我知道了