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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  ) l0 c( m, M( ^3 a
To query for an Item and retrieve its structure you build the query as the structure : _. c/ S' x, D
you want returned.  Use the IOM methods to add the relationships you want and
1 I' Q1 o6 y! a0 \# ]3 gbuild the structure in the Item.  The server will return the structure that follows the
* o% P7 c7 w% C( Z% Y) rrequest structure.
2 v3 s  g$ Q7 c- i8 qThis recipe illustrates several related concepts together, which are how to get a set ; n6 e4 `; P, q; Y: _7 o
of Items from an Item and how to iterate over the set, plus how to get the related   c' Z4 X! X9 s0 c5 W) I0 z4 m% G
Item from the relationship Item.   ?3 C, ^0 D$ ~7 {$ s+ P, h
JavaScript  
; A; q& ?3 B1 bvar innovator = this.newInnovator();
, U; s8 L8 c: {# a 4 o7 j0 S, i! h3 R
// Set up the query Item. 8 B- w: |* |1 {4 K# S
var qryItem = this.newItem("Part","get"); . X8 _4 m' s! p0 @; a
qryItem.setAttribute("select","item_number,description,cost"); $ w3 u; C$ I/ U$ o& G/ g8 o
qryItem.setID(myId); : |+ }$ F, H7 m) R& T* n7 K

4 D; e7 a4 U% D5 I! b! W" K// Add the BOM structure.
5 h( L. k4 m3 d; g% |var bomItem = this.newItem("Part BOM","get"); 1 ]+ z( y5 u! L, ]
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); + M& `& U0 _9 |
qryItem.addRelationship(bomItem);
: }( e8 }: @; L7 @' k3 @$ M8 ~: m# {
: B! ^; a% @2 P  ], x* K// Perform the query.
9 o/ }; X5 q2 q  _& ivar results = qryItem.apply(); 9 Y3 v8 x- P. [1 t: A
# A% ^7 N! t4 n6 H! N' v4 P& [
// Test for an error. 3 |" o# w+ D: p# b! L3 R7 o5 ^
if (results.isError()) {
- L$ o5 D* m9 |6 E* D  top.aras.AlertError("Item not found: " + results.getErrorDetail());
8 L/ @9 u/ D, l  return;
. y) u" a; H1 S. j8 U}
/ n- Y  k& W9 N8 ^' V 6 C( S/ p3 I9 b. x
// Get a handle to the BOM Items.
' ]: {2 G6 C- N0 O  f, N6 Kvar bomItems = results.getRelationships();
, r& L0 Q+ `% J/ U0 T8 Pvar count = bomItems.getItemCount();   S) i  z" |- Y+ j  t/ A

7 T; h) d$ s' Y// Create the results content. 4 I, b8 ]% u, i! M
var content = "<table border='1'>" +
0 ^3 q9 @, J" b  "<tr>" +
/ r" ]- }: O4 ?; Q' g8 }0 Q  z    "<td>Part Number</td>" +
1 s$ L* g! Z8 d, D; c2 K    "<td>Description</td>" +
3 P; K2 r$ _. ?+ C( H5 u) P    "<td>Cost</td>" +
( u2 l7 j* t; G6 n& F# j    "<td>Quantity</td>" + 0 j/ y$ }# ~, m# b& @
  "</tr>"; 2 V4 w* ~0 b4 x% ~7 N6 x2 B$ |* i
5 h# K( K: t4 \3 J& A) Z% Z, P0 n
// Iterate over the BOM Items. 5 q: M% W6 J7 [/ W. d; s9 v
for (var i=0; i<count; ++i) , F) q; o7 ~4 z6 f0 R% S
{
( q% }2 R. j6 s9 W* o// Get a handle to the relationship Item by index.
# G, b" Q' B( s- n" C9 R3 l6 [  var bom = bomItems.getItemByIndex(i);
$ Z8 k' I/ C: U+ F0 c// Get a handle to the related Item for this relationship Item. : v" y  O. [& M2 j$ G
  var bomPart = bom.getRelatedItem(); : n  _. q2 c0 b4 @6 Q' Y5 H* j9 N0 ]) L

6 E# }+ U. o, k7 r9 V  content += "<tr>" + ! W: q( A% i6 m$ k4 a. ]
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
" i, D* K' Q9 ]0 R3 N3 `& @* z      "<td>" + bomPart.getProperty("description") + "</td>" + 0 ~1 O; H5 m  \# Y) S' s# A  v3 r) E
      "<td>" + bomPart.getProperty("cost") + "</td>" +
- H: V7 C+ Y6 v! ~2 r, \      "<td>" + bom.getProperty("quantity") + "</td>" + 5 e+ j2 B: V4 g. E1 j+ }. G8 L
    "</tr>"; 7 x( h* g4 u) G+ T) O3 a0 B
}
- L. k3 a/ G, f- [' Treturn content + "</table>";
/ b- S, K  R- [' G" k" X- P0 F2 i8 r: J& m9 ?; `4 {/ Q- Z

) [& I0 B0 N( w+ w; @! u+ Z2 u2 ~9 @1 {

: v# c* o2 r* ^: C. ^( m% n# ~C#  - [( N6 D7 Y( t
Innovator innovator = this.newInnovator(); 4 M: n6 h9 |0 {  p
6 v( h6 m+ h1 g! ^; _0 {, `: L
// Set up the query Item.
: }+ x  a* |3 F2 n; p# tItem qryItem = this.newItem("Part","get");
0 H: \0 G9 T: o, }6 t4 Y# r* x. k# YqryItem.setAttribute("select","item_number,description,cost");
; \& V: M) j: ^% S  b# |4 tqryItem.setID(myId);
+ R. W( \3 X) d* |: z % x9 I5 A9 ^; r
// Add the BOM structure.
: E1 x/ X% Q3 L" `* j$ ?Item bomItem = this.newItem("Part BOM","get");
/ y: |: r7 c" R8 NbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 3 I, r+ A6 c6 A0 f) J. f
qryItem.addRelationship(bomItem);
9 |: g3 f& P# c* h2 |: f$ i: S
" ^; ^/ ^8 Y: B5 c* n* P// Perform the query.
" K. Q5 A& b3 aItem results = qryItem.apply();
% Q! ]2 x* e, i; ] 5 C- z0 O: p' l9 }1 f. k+ L
// Test for an error. , N, w( {8 [; h
if (results.isError()) {
; a, K* x) O) n$ h* F3 L+ c  return innovator.newError("Item not found: " + results.getErrorDetail());
- f4 I+ z* l; q/ ~1 ]; e; ]} % F/ l* ~" [& i) }' r4 X. E
6 [( S5 P: n8 k2 V, T3 }6 ]4 ~
// Get a handle to the BOM Items.
& a6 z2 a5 x1 B" x, xItem bomItems = results.getRelationships(); $ R) ], P$ @: w( V) {# q1 z
int count = bomItems.getItemCount();   a2 I7 g- ^) ?" ]
int i;
  B7 M5 P5 {0 H( Q, r# H
1 b+ t- Z& j& E9 O1 ]4 N// Create the results content. $ G! G3 u, V0 }# M
string content = "<table border='1'>" + 6 Y& P  g/ w6 V6 U- T
  "<tr>" + % [: \- m- p6 Z: w. J5 T
    "<td>Part Number</td>" +
9 ~2 q' H2 f2 A    "<td>Description</td>" +
9 v0 \5 O5 ?4 j; c! I/ i+ S    "<td>Cost</td>" + : [6 G/ P' k( N! B# q( G
    "<td>Quantity</td>" + , ^( l. V& }7 \- a7 U8 `+ K
  "</tr>"; . E( c$ N1 n/ H3 |+ J. {, H

1 o# D/ {2 C' N: j# k* Q// Iterate over the BOM Items.
. t9 P7 d5 s+ w9 R1 w3 ?for (i=0; i<count; ++i) $ }" c; {: B  Q; L* z" p% m
{
5 v# \7 n- g$ N- T7 `) D// Get a handle to the relationship Item by index. # s# H0 \4 B; Q) C
  Item bom = bomItems.getItemByIndex(i);
8 ~4 Y" H4 B; J) x% R// Get a handle to the related Item for this relationship Item.
" d5 l5 v- a! R2 x  o9 A  Item bomPart = bom.getRelatedItem();
- Z! M' w3 f6 ^+ ^
4 |- E" ?- T% m; i4 v6 q  content += "" + 9 c, t- T9 j3 o% c' [. D  C
    "<tr>" +
) E% }: h# E/ s& h! D9 F$ ~3 [      "<td>" + bomPart.getProperty("item_number") + "</td>" +
* v% U* c, ~* j9 @' J; y      "<td>" + bomPart.getProperty("description") + "</td>" +
' u4 W1 A( K+ J& v5 ]      "<td>" + bomPart.getProperty("cost") + "</td>" + ) |6 X3 J. n/ t1 k9 h1 N
      "<td>" + bom.getProperty("quantity") + "</td>" + : _" {7 h  o: {% T& ^
    "</tr>";
; L* F. `" y" c1 E. U}
4 @* b$ k$ x" r8 O2 d' T( P& Lcontent += "</table>";
6 C& }7 X3 H0 t# A9 N4 [ & D: `6 N& K& g1 N1 D
return innovator.newResult(content);
! |4 Q; K0 i4 k8 a3 y3 I" h9 c6 }0 U# \* R* ^
  h" Z" a# W! N" Z& ^

0 b/ s" `% [1 i/ \' r6 D' b
# F5 h( L; a1 l3 [5 K+ V4 s

. w" X; S0 I/ [/ |5 q5 T2 `

+ x( W/ t# \7 \* ]4 t
  E+ x3 q: K$ r( n4 k    Page 46 ! a( L- `3 [3 s. }! j

# B3 ]/ v9 ]' X3 ^$ l2 }( UCopyright   2007 0 i% W$ @' {( v" r% L6 Q
Aras Corporation.  
: V) I. v# @# t& q0 M! i5 RAll Rights Reserved.
) r# D( u" I( i" mVB.Net  
" c/ J6 \) z0 ]: B$ O: wDim innovator As Innovator = Me.newInnovator() 9 s: b' s& Z* b' h% _
" ]' @9 h( c' q1 Z% j/ j
' Set up the query Item. % J2 Q" J! E5 K0 I
Dim qryItem As Item = Me.newItem("Part","get") 0 Q  |, b' r$ o% _0 r7 U; v
qryItem.setAttribute("select","item_number,description,cost")
5 ]" p7 A  n. X3 YqryItem.setID(myId) 9 q! E' Q5 R% z$ I
* \2 W0 H6 p1 M- _& b! `" q
' Add the BOM structure. * n* A' k2 I0 N. ]8 p$ O7 M/ q
Dim bomItem As Item = Me.newItem("Part BOM","get")
' M! M6 Y0 {, V# T) ]0 M6 ?: cbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
0 A5 ]- b8 t6 M1 m) n( A/ c5 dqryItem.addRelationship(bomItem) + R- l- v" P3 A0 Z3 ~
5 m! l( W* X! ?% |0 C$ [4 j* F; p/ v
' Perform the query.
7 a. G$ r5 Y# A0 k" y. ~1 I1 DDim results As Item = qryItem.apply()
- A6 I6 O, g1 a8 g1 X5 Q/ l5 p
+ w8 e! w( \& P3 D' Test for an error. - |, n+ q+ ?. E  y
If results.isError() Then 9 K9 H2 ~2 M0 W; _  R
  Return innovator.newError(results.getErrorDetail()) 9 [4 X0 K& j9 F; X" \- [
End If   l9 J' o: [  S. ]

  `; U. d! R- j0 l' Get a handle to the BOM Items.
/ O" F- w0 J7 F. I4 F$ {Dim bomItems As Item = results.getRelationships() $ T; ?0 M) a3 s( o. h* k6 C
Dim count As Integer = bomItems.getItemCount() : L5 S7 B5 M, g4 O6 p% U
Dim i As Integer
! B# r2 k7 q: ?0 ^% J! K7 l' z , P6 @* q8 A0 ]' v( L' \, u* I
' Create the results content. , E  Y6 u$ `1 g9 j. Y8 ^% C
Dim content As String = "<table border='1'>" + _
( e2 y! k! a7 c  "<tr>" + _
2 K5 K2 V; Q. |1 t1 [, n; d    "<td>Part Number</td>" + _ 3 n" h$ x0 M: }9 ?
    "<td>Description</td>" + _
5 B' \$ q0 |; K* J/ ?' M    "<td>Cost</td>" + _ 6 e4 \( D2 Y; v, ~. Q. D4 F
    "<td>Quantity</td>" + _
, g: h, w6 i5 `  F  X5 A- A  "</tr>" ' O8 ?7 p, Z$ ?, w$ e% U5 B& d! c
- P6 ]& h( K1 L
' Iterate over the BOM Items
* l* m% _1 S' _& UFor i = 0 To count - 1
: j' M2 _' K" Y$ }3 D5 D8 g: p5 A' Get a handle to the relationship Item by index. ( a5 M$ f: N1 ~
  Dim bom As Item = bomItems.getItemByIndex(i) 7 R; V: b7 l: u6 l3 |# m

: Z( s; }5 L4 x' z2 c& b' Get a handle to the related Item for this relationship Item. % }0 {7 x% J/ p3 w% e$ k
  Dim bomPart As Item = bom.getRelatedItem() - p2 G: b/ e8 C$ X
* v  j# s; x+ o& w, E" o: J
  content += _
$ C3 t# D/ D0 B9 _7 z1 x  v    "<tr>" + _ + P% [& s( f$ c; O8 o$ [5 `! L* Q
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 |) z3 u3 Z) C* f( P8 P/ K- u$ P& E
      "<td>" + bomPart.getProperty("description") + "</td>" + _ # i  F$ ]' }" y3 s$ A" e2 A
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 0 A7 j9 }. D% ?0 d& L( b0 K" b  U
      "<td>" + bom.getProperty("quantity") + "</td>" + _
! h; B% C! q2 J    "</tr>" + P5 i) `( x1 P0 u. J% m$ ]9 w4 `
Next
$ P! v. J# q8 b4 jcontent += "</table>" 9 Z2 ?" g( Q2 v7 r- Q
. w$ ^. m7 ?# O2 d, e
Return innovator.newResult(content)
4 _" h3 P7 G) b9 K8 \$ u- E# S6 h6 L  e
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了