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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  0 C$ K/ n7 ?: S3 P5 {5 l; o& b# c7 l
To query for an Item and retrieve its structure you build the query as the structure ' D& Z2 N5 i: ?. j* \
you want returned.  Use the IOM methods to add the relationships you want and
+ _2 N) U$ ^, b5 q1 k( {3 R- m% mbuild the structure in the Item.  The server will return the structure that follows the
  q7 m) _; L! z, _% Crequest structure. " s6 d- V1 k# }
This recipe illustrates several related concepts together, which are how to get a set 1 ~" N& |& }* ?9 f6 v0 o- C
of Items from an Item and how to iterate over the set, plus how to get the related 4 a7 U' f% Y3 e+ D& X: q
Item from the relationship Item.
7 a; f' s1 h7 z& dJavaScript  
, |0 _0 ?6 G. X. ~# F6 p# ~; P+ fvar innovator = this.newInnovator(); , w% {: s3 ~8 @; h. j2 u
4 C& Q6 o! ^% n
// Set up the query Item.
6 [+ H3 X5 }7 U- Z; T* S3 ^: Mvar qryItem = this.newItem("Part","get");
; D1 J, A- q1 i3 i, qqryItem.setAttribute("select","item_number,description,cost");
6 @5 r* {) N; n7 @qryItem.setID(myId);
. J2 ~; K, d. n( l/ V. L
! `2 \) j7 `" N8 X" \2 f4 [! n% b// Add the BOM structure. + k  ?0 T4 I0 [0 g" K
var bomItem = this.newItem("Part BOM","get"); + B& z; a; Q  C
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); * M# h1 y6 {9 ^
qryItem.addRelationship(bomItem); % M+ y0 L3 @( w2 e  C: y) d

# b' P+ ^' E- |, [  j// Perform the query.
- [& x& e) {! q& @! F% }var results = qryItem.apply(); 8 A. d3 K1 h+ ?: P, V2 F" o# o& ~

" Z" H% Y% U0 x( F# O! t// Test for an error.
  g) Q6 ]! B% ^' f7 t1 Q2 Mif (results.isError()) { ' a, C: M1 Q- R) W4 ?
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
9 B8 A" }$ E. `) |8 i* ^. {" Q  ~  return; 7 y9 w  H8 x/ n/ N& E3 j5 f9 `
} ' s, {# `- v0 l
9 a7 \8 t) x# m! m9 `* d
// Get a handle to the BOM Items. " ^- w/ {% D' }) m( u
var bomItems = results.getRelationships();
; o; T6 T- L2 F, O  R. |, m! }var count = bomItems.getItemCount();
2 \. j/ h) |- p$ l % g6 r8 S  e) U6 t* P4 p6 x
// Create the results content. 2 `  g0 ?) Y/ Y3 `
var content = "<table border='1'>" + 9 p- ]$ n' W- o0 a0 j
  "<tr>" + 0 t7 Q3 r. v# z& ~4 W; X9 C
    "<td>Part Number</td>" + + ~& N; C5 i, |7 g
    "<td>Description</td>" + 4 L1 b* A  s: T- \/ w2 c: K8 d
    "<td>Cost</td>" +
' c! R6 D2 o+ a4 S    "<td>Quantity</td>" +
4 q7 x- ^7 I( M  "</tr>";
- T4 \& D. X# _' | ; A' ?6 r  R7 T  R! [0 U. {8 B
// Iterate over the BOM Items. 0 t3 O& W% x+ W' `# N; m2 ?
for (var i=0; i<count; ++i)
9 j# Y' }$ K. `* v# N9 X{
0 K. I! q: F" R' f8 H: C' j, J% w// Get a handle to the relationship Item by index.
- ~% y- L' Q- E! n  var bom = bomItems.getItemByIndex(i);
- x% K7 F, c) `$ f/ r! h// Get a handle to the related Item for this relationship Item.
- H+ I: J3 G; T  var bomPart = bom.getRelatedItem();
- w1 @. a$ X  Y" j6 ^6 B$ q# t9 N
- Y$ N6 W6 o/ ^# b5 w  content += "<tr>" +
/ ~5 z' _* s7 w. J+ C      "<td>" + bomPart.getProperty("item_number") + "</td>" + + P0 g1 k* _. d; T4 f; n
      "<td>" + bomPart.getProperty("description") + "</td>" + 4 M% {; [6 T% w# X0 |$ H) f3 ?7 o' R9 J- P
      "<td>" + bomPart.getProperty("cost") + "</td>" + 0 j* Q0 w) W+ ]! R' t1 u# J( O
      "<td>" + bom.getProperty("quantity") + "</td>" + " t% {; z' M' @  D1 K  r( N4 q0 j
    "</tr>"; 7 D& _; I3 G9 N- m
} 2 s, [2 t4 q3 G: U2 {5 a" g
return content + "</table>";- d) \3 ^6 R2 p5 B( V2 s- I

  X( M% @( g: j: t: W  N. J

6 t3 V6 u  O6 C
0 ], A2 M7 _, r

! p. A  ^% q/ H! pC#  * X% Z# t7 ?! [* P$ O
Innovator innovator = this.newInnovator();   U- P; `; f# o, Y) t: g

# O& p+ [* P$ }9 R. x6 O) L; m// Set up the query Item. ! |( @  R+ b3 w+ _. w3 u
Item qryItem = this.newItem("Part","get"); 6 t& F2 o$ W+ f2 Q4 b* {+ ]
qryItem.setAttribute("select","item_number,description,cost");
$ P* Y: p- H% Y2 o5 ^9 i9 _/ oqryItem.setID(myId); 0 L3 `. T5 j8 i+ b5 R, d$ U
) K2 U, F7 T3 T  _5 P2 d9 e! b
// Add the BOM structure.
2 y0 b7 x- I$ x. y2 S0 {& JItem bomItem = this.newItem("Part BOM","get");
' t( A" x/ }& V+ F" ]2 obomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); * C3 `7 S& ~/ y2 ^
qryItem.addRelationship(bomItem);
+ n- @; D7 g) r; C
* y8 e: g, d9 n( k* {// Perform the query.
0 v* a0 q$ X6 I; D" |Item results = qryItem.apply();
+ g" D5 P' d  j! a
3 i% {/ ]6 ]" Q+ g: I$ c; ~! J// Test for an error. " R& s0 R, S$ P: N, U
if (results.isError()) {
/ u$ _/ Q% e; }7 B- |  return innovator.newError("Item not found: " + results.getErrorDetail()); 9 W) ~- q& V4 A+ ]( k$ M% }4 S
}
, i' V' J5 O3 W* q5 e( T5 a% U- h+ w 7 W4 E% }! d1 j+ u& Q# G
// Get a handle to the BOM Items.
5 Z8 m: u2 P, w; h* mItem bomItems = results.getRelationships(); " z; G9 B$ s8 S# ?4 i; v3 ^; v
int count = bomItems.getItemCount();
  v& ?8 c+ Q. q2 j( T& {2 p, Hint i;
1 [. d! m3 J, N5 a0 v
" c: u5 `4 g2 \( O0 C; K) D+ H// Create the results content. 8 ^/ _9 P4 n& ?7 m6 Y6 W0 R) Q
string content = "<table border='1'>" +
  ^+ p5 [8 E, ]  "<tr>" +
! i8 o6 r2 F$ R! f    "<td>Part Number</td>" +
8 W/ b2 z, O7 o    "<td>Description</td>" + 5 X2 S3 G1 X, N
    "<td>Cost</td>" +
& `7 T5 r7 r! X! P    "<td>Quantity</td>" +
  N4 G9 r$ L: K7 `. B$ y: h  "</tr>";   H& v2 U0 a6 ~  M
; z; B( S1 [+ g" u0 g1 k) [  W1 N
// Iterate over the BOM Items.
4 B- s1 c# ?+ Zfor (i=0; i<count; ++i)
* X( O: f) i" ^' K' Q# K4 {8 _$ \{ 0 }+ r; ]2 m7 C9 b
// Get a handle to the relationship Item by index.
" S9 t! t: h) s7 h* C  Item bom = bomItems.getItemByIndex(i);
& [. G! K1 x1 ~! i0 n: R6 b# G& ]// Get a handle to the related Item for this relationship Item.
8 ^" n' {1 z! _3 \' J: l6 \6 x  Item bomPart = bom.getRelatedItem(); ; |1 J" }. X' e  W7 W  T8 }
0 o, [0 i: a# N( v
  content += "" + ' Y# C6 S( Q' @, f* G3 X$ Q
    "<tr>" + * G  X: {, M5 _- q- [! M7 b  P
      "<td>" + bomPart.getProperty("item_number") + "</td>" + : Z& A9 u+ m9 |- t
      "<td>" + bomPart.getProperty("description") + "</td>" +
7 R* V, w  v! M6 ?' m+ c% M9 @5 z. R      "<td>" + bomPart.getProperty("cost") + "</td>" + 5 |1 Z6 S; f7 D  Z. T2 a
      "<td>" + bom.getProperty("quantity") + "</td>" +
" _' N, d& c& T1 M( n- W+ T6 w$ o    "</tr>"; % Q* Y- E/ `2 L9 C/ W& G
}
  ^% l# \$ C+ V' O$ Jcontent += "</table>"; ( u* @# |2 J$ c! ~
  o* y8 g5 J3 s: x3 _0 k
return innovator.newResult(content);
8 B  P# x  ]7 L" C) [
5 ]$ X, L- K, G/ I9 Q* W
' J2 r+ o8 V# b
2 x+ K" A% n/ ~4 t/ K0 C( \- J

3 O& {" Q5 r7 o% Z& R
* v/ X# @( N* H( ^, G( R

' ~( k, \0 h9 V4 w- [
* R, j% P- s% f: z1 O/ P    Page 46
0 q  `' p0 l7 M9 H: ` ! O6 i3 p! L* f
Copyright   2007 4 |0 x7 o' Y& l6 e0 f* E
Aras Corporation.  
, a* Q! O3 o" R( t+ IAll Rights Reserved.
' c) z! v6 v% G* RVB.Net  , Q$ {/ L2 J2 E
Dim innovator As Innovator = Me.newInnovator()
# Z" F0 D8 D6 |6 D3 M # q: E8 ?2 k# J! a0 o7 C' `0 V
' Set up the query Item. 5 t6 D  U# p5 E, O7 b, v
Dim qryItem As Item = Me.newItem("Part","get") : t- p& }; V- `; y% |
qryItem.setAttribute("select","item_number,description,cost")
7 w4 }+ W% D! j4 T" NqryItem.setID(myId) ( F! u3 }& b! \! n( B& }7 @* S) R! ?. H

9 I9 q, k$ x% N' Add the BOM structure.
% p% w* V1 _* g+ H7 R% R* A) C0 R  cDim bomItem As Item = Me.newItem("Part BOM","get") 3 x1 N' K& ^9 E. T% O
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
$ a& N5 ?6 f/ _qryItem.addRelationship(bomItem) $ V/ C8 `, C* d
) `4 E5 }# G/ h) _! k. Q; e
' Perform the query.
, C) A" o  B3 o( ^/ TDim results As Item = qryItem.apply()
2 b- Y- B% L% K! e5 I - Y5 g8 c" b& P$ }# H0 Y3 @, O4 f  X
' Test for an error. 4 T) F0 B1 A% `' ?4 W" r
If results.isError() Then
1 w3 @. X$ N+ A  Return innovator.newError(results.getErrorDetail()) ' m" m" ^* e$ l# x" V# Z$ \$ L
End If 3 U, S) ~: w6 R6 }5 Y

) T" G" H0 P' {# ~7 Y' Get a handle to the BOM Items. 3 W; u3 Y" |: f7 l7 L3 {  E! D
Dim bomItems As Item = results.getRelationships()
" B& p1 S0 c) M# `Dim count As Integer = bomItems.getItemCount()
! O0 c6 q: ?1 |3 n7 HDim i As Integer
" q) ?6 r8 }$ W4 q+ s# P* y  a 4 l; v* l' d( v; J0 f
' Create the results content.
8 P& p9 Q2 o8 vDim content As String = "<table border='1'>" + _ / O5 z3 }$ Q* K
  "<tr>" + _
+ e+ j3 K" E( `0 d% W    "<td>Part Number</td>" + _
0 `  @9 @% ~! k# K7 ~* a8 R$ S" i    "<td>Description</td>" + _
- x2 m! \4 z9 A9 b  R    "<td>Cost</td>" + _ 4 y# v9 B, v+ G
    "<td>Quantity</td>" + _
2 _9 }+ E: r5 `  "</tr>" 0 u; q: W2 j8 N) Q4 c+ d& ^  M, n

+ Z1 e% A* r/ B' Iterate over the BOM Items
1 B! `+ J2 l+ ^, a0 b; d5 o* ^3 JFor i = 0 To count - 1
# b8 [( ]4 F! w$ b: x4 b/ H1 b' Get a handle to the relationship Item by index.
" q2 j5 p' o5 z+ M% G1 v/ R: f  Dim bom As Item = bomItems.getItemByIndex(i)
) g' J6 T& I* H' u) U- |& N
+ u" d, L6 V4 g' Get a handle to the related Item for this relationship Item. / j8 u0 `% X. l- e9 H
  Dim bomPart As Item = bom.getRelatedItem()
" L9 N3 @$ W! Y0 L: S2 N
1 B+ d! Y% Q# p+ l7 G  content += _ 7 ?, E. ~" Q2 F% ^! \9 v; T
    "<tr>" + _
, S. V* ?/ r8 T- G0 C: v6 t      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
/ G% Z$ P, b2 B' s. [      "<td>" + bomPart.getProperty("description") + "</td>" + _ 5 S2 Q: D% U2 f. T! G$ N2 q
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
5 n% ~% b3 B! f* c9 I# n9 J+ G      "<td>" + bom.getProperty("quantity") + "</td>" + _
, c- ?& O' a8 g    "</tr>" $ \. X8 ~0 [' h8 b
Next
+ p2 I' f. g8 |( P8 |content += "</table>"
: g7 s  b. X) m" @* b
9 o! i: f! e2 F/ D% S( ^! z; nReturn innovator.newResult(content) 9 n, {8 m9 y4 @1 c

3 ]6 K/ L5 ?1 P7 b: 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二次开发专题模块培训报名开始啦

    我知道了