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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  5 a0 C) }: J4 \4 s  C: q' }
To query for an Item and retrieve its structure you build the query as the structure
9 `$ V4 L8 `* y7 [you want returned.  Use the IOM methods to add the relationships you want and
4 {4 i& T) y+ q9 ]- z, @build the structure in the Item.  The server will return the structure that follows the ) T! i( r- C3 p% H6 _
request structure.   N, g. N; _* y9 z+ N
This recipe illustrates several related concepts together, which are how to get a set 4 b" f% x7 S# M( i; }- z8 T; H6 y
of Items from an Item and how to iterate over the set, plus how to get the related   h7 ]  _5 z1 J( _" i5 F& h
Item from the relationship Item.
" ]: r8 r, L  u' D9 x& eJavaScript  
9 S  s( c9 g' F+ m7 r. Z( mvar innovator = this.newInnovator();
  A8 |% m6 W/ q0 g
& ^. T- \5 a% S2 w  }// Set up the query Item.
  o) X0 W) J$ X/ l. O1 hvar qryItem = this.newItem("Part","get"); 5 x' q- ?! X2 X+ W! Z+ V5 f
qryItem.setAttribute("select","item_number,description,cost"); " x  b! B" J5 |2 R) q
qryItem.setID(myId); 5 W' [0 U0 [7 S( E5 C

. F# v6 m( |6 I5 P// Add the BOM structure. - ^0 E5 L* E3 j' V. y9 B* ~
var bomItem = this.newItem("Part BOM","get");
* h3 {8 k8 t* A  Y; b, ~bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
) H' N, O, F; t4 ~0 _qryItem.addRelationship(bomItem); + V1 z2 v7 }( D) e* q' M

3 h8 y; v8 \# i$ `! {9 V0 y// Perform the query.
8 i2 `  u* {/ f  pvar results = qryItem.apply(); 1 V: X9 A9 B' n8 F. e+ z4 R7 B
6 N9 l' y: Q. e. J
// Test for an error.
, |  |: d, d+ a. }if (results.isError()) { & n; n) S. d5 ^
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); $ a* }$ u- w4 I) s5 I9 }+ V
  return; 2 N  Z& e1 B6 h
}
' P( W! y# C" M( \+ j 4 @$ g& }0 ]7 @4 ?
// Get a handle to the BOM Items. 3 T0 ]9 l) P+ P3 h$ v
var bomItems = results.getRelationships();
& \; a! e* J6 |+ Q2 E  G1 Nvar count = bomItems.getItemCount(); , L$ ^( }, k) X! y

$ G( i. w/ c! M( A$ c9 e1 n// Create the results content. $ [5 V/ ^9 a  z& H' i
var content = "<table border='1'>" + : ]5 e! ?5 P! N. u3 v, l; t
  "<tr>" + 3 B$ y6 c4 Z$ k; D$ ~7 m
    "<td>Part Number</td>" +
. V. ?4 |  ~0 x* y( x% x) Q    "<td>Description</td>" +
  Y0 L% E+ p" Y; v/ N2 C    "<td>Cost</td>" +
. E  i( v( A8 P1 p! K" T8 m' o    "<td>Quantity</td>" +
; @% n& W: ?$ D0 ?( v) x2 B  "</tr>";
, V) e) [6 T0 @# N
! i2 A& d# P6 ]! Q+ C8 Q// Iterate over the BOM Items. & H8 ~, _9 e, c+ j
for (var i=0; i<count; ++i)
  p! k2 o& i9 ]' S/ i{
" ]. b1 n6 \9 v9 R$ {% u! z1 k) P// Get a handle to the relationship Item by index.
: p  ?9 `( K- |( Y3 ]9 {0 ?4 r  var bom = bomItems.getItemByIndex(i); 7 G* w! u& x. S' Q( ^
// Get a handle to the related Item for this relationship Item.
8 V' p8 I* p0 m+ C$ F1 n  var bomPart = bom.getRelatedItem();
" e- U9 a; ?. d: U6 c 7 R  b% V+ [' k/ K; x  a
  content += "<tr>" +
" ?" G3 Z. W+ g5 k, y* z0 A3 S      "<td>" + bomPart.getProperty("item_number") + "</td>" +
( H; t, c1 ?6 Y  b' L      "<td>" + bomPart.getProperty("description") + "</td>" +
/ E( M1 C+ K5 v" b1 y: q3 e      "<td>" + bomPart.getProperty("cost") + "</td>" +
+ Y3 e  F1 d5 ~; _      "<td>" + bom.getProperty("quantity") + "</td>" + * O, d3 l2 F6 M' E9 s( H/ x! l+ v7 K
    "</tr>"; 7 S! b6 W/ y; G  G- V
} 7 ]+ x" K8 f. H; ?* @  J/ n- a
return content + "</table>";
2 x% F3 t; r( ?- v( k
* ]4 P/ O4 U0 q+ H

+ e8 a2 a) V# U( y+ P2 u" A0 U" h
& C1 d7 Q8 J; L9 ?* _
C#  
$ W2 V* G" [9 V5 E+ T  KInnovator innovator = this.newInnovator(); 4 B/ H. F0 l  a& ?* j

6 ?% G2 d$ q$ U1 u: E// Set up the query Item. . O3 ]/ o. H/ F0 [7 S* V
Item qryItem = this.newItem("Part","get"); % t/ a, n1 ]8 q% g- z# |$ z6 {
qryItem.setAttribute("select","item_number,description,cost"); ) m3 o) e/ c4 w3 g. t" l4 ~
qryItem.setID(myId); - |2 J/ y- o' m5 @5 p4 p! w6 o
" `# k% u/ W/ U6 {0 I
// Add the BOM structure. 5 o2 @- a; {  Z! p3 a
Item bomItem = this.newItem("Part BOM","get"); 5 @- ]' M: S% }( Q) \# `1 z; M
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
; M6 V, o! k2 `" p* ?% `) KqryItem.addRelationship(bomItem);
: p% [2 J; c5 t4 x: J* C+ E8 _
& `7 f2 ~8 s, b, N2 @1 U0 ]// Perform the query. 0 J8 k% J8 _: r5 J$ M) d2 A3 A
Item results = qryItem.apply(); " l- i, D+ f5 w. |; r
1 p' b) o. V  H% p% h' X
// Test for an error.
  J0 h" @* A( L2 m9 sif (results.isError()) { ( j6 y1 n& C- p' O! o$ Z
  return innovator.newError("Item not found: " + results.getErrorDetail());
* @4 ^; ~  W2 V5 u. [& }} 2 z2 j+ m3 ~! W
( K: g2 z) Z/ g% b
// Get a handle to the BOM Items. 7 v( \( e8 |/ H1 s; o' q; w. Q( Y3 ?
Item bomItems = results.getRelationships(); 3 L( z2 ]8 q( S; ^7 {: C- v
int count = bomItems.getItemCount(); , O0 w( P; L, q- k% O
int i;
: @: a8 E$ N% v& \; c1 q( b 5 X# g, H8 d! W- z& N! o! J
// Create the results content. * Q7 Y0 g2 T% q
string content = "<table border='1'>" +
$ t& [) J- M8 P- L8 \  "<tr>" +
# b; o; |9 @) E6 e% S0 J7 N    "<td>Part Number</td>" + 3 }+ K  @# d) j' |6 f( x4 [: `
    "<td>Description</td>" +
& N/ [2 i" p/ z9 j+ A. u& m1 z2 ~- W! r    "<td>Cost</td>" + ) Y" Z$ u- ^3 }
    "<td>Quantity</td>" + - K/ h1 C: ~; i( Z6 L
  "</tr>"; 9 a% U/ u8 X! U. A2 j' x; s

  ?7 P. [2 S/ D$ B/ X0 [4 c+ S// Iterate over the BOM Items.   M, E1 g0 ^) n3 r
for (i=0; i<count; ++i) 8 a. Z% v' A9 T+ u! F
{ ! Z' d; n1 C& e  B" G2 h
// Get a handle to the relationship Item by index.
. }4 U' c4 p& R, H# \2 l  Item bom = bomItems.getItemByIndex(i);
% y8 L. r" S$ u, P: f+ i! ~! B  c// Get a handle to the related Item for this relationship Item.
* l* h. m2 P4 j  Item bomPart = bom.getRelatedItem();
' y' a, T  Z% V, o . S' m3 Y+ M' Q+ ~% |
  content += "" +
# ^/ J7 {( @8 M, V* g    "<tr>" + + `- E, a$ @8 A+ G! \
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
1 Y3 N8 Y( J. b& \& I6 H4 f& I      "<td>" + bomPart.getProperty("description") + "</td>" + , o1 `: `2 _: z$ r7 i! A! p( a
      "<td>" + bomPart.getProperty("cost") + "</td>" + - R1 n, e8 l$ J# l% l5 ~6 _& i
      "<td>" + bom.getProperty("quantity") + "</td>" + 5 ]7 v- |0 X9 ?$ z
    "</tr>"; 4 P' I  n' r  f& i& Q/ K+ J( P
} / P' P9 A& e+ p
content += "</table>";
# v+ q4 p% K* c% g1 l0 j; @
1 O& ?" J0 E  T& {7 greturn innovator.newResult(content);
+ }& W( G+ h) d( G3 f
' r$ i' D- A0 j0 s4 |6 _! ?2 \

, z( I8 C2 K) _' D6 d/ _+ \( H$ i/ Y- w' s2 M- ]+ M4 i) U2 Z
1 {7 D1 f7 |0 [% Y
- n' y% u  R5 E& h

5 z) D, @1 s9 L3 l& R. S7 H  o
" W" e0 n% V6 V: _    Page 46 3 p( ]( R8 O& @9 w- K
. Q& x# u& k/ Z% {: A% _
Copyright   2007 ' \1 E: h. I" K
Aras Corporation.  
/ [8 V) ]% K- u( p1 TAll Rights Reserved.
9 c/ _: K% W2 F: c# `/ ]" zVB.Net  
# \0 D2 Q, }1 m' S1 RDim innovator As Innovator = Me.newInnovator() % |: Y8 @# |4 q1 X! I; S

( Y9 c( E: ]' q# g/ ^7 D: U( i' Set up the query Item.
6 x. A; ^; e3 @0 b) nDim qryItem As Item = Me.newItem("Part","get")
, ~& T, q7 ^, H, j2 zqryItem.setAttribute("select","item_number,description,cost")
5 x0 s+ S; u: k# v; IqryItem.setID(myId)
9 q0 W6 C  f7 u2 f" Y) e, C. n, s
: ?& w1 E5 u1 P9 S' Add the BOM structure. ( u; P/ G; K: h' ]/ ]5 ]0 o& T
Dim bomItem As Item = Me.newItem("Part BOM","get") " T% q' ^% u  S0 H
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") # {3 T# E) h/ |
qryItem.addRelationship(bomItem) , |5 z, z) }2 y4 Q( G, n: K( |

( C) E# ]4 H2 ~: F' Perform the query.
/ R9 @2 c) w- {! Q1 @$ E1 i# }Dim results As Item = qryItem.apply() ! u' Q0 |. D$ D8 \) M! b. A# l

* [: b& }6 Q4 \' K* ^' Test for an error.
# q" I% S: H  k8 VIf results.isError() Then
4 y6 w9 U6 \( }  Return innovator.newError(results.getErrorDetail()) ; \! @1 |# S' k) N$ X; y7 f2 |
End If
( E( a! I! y, J% w( g: s: d  X
, v* m$ g9 O& `- v' Get a handle to the BOM Items. 9 Z! P- G1 r* S8 X
Dim bomItems As Item = results.getRelationships()
* e- L/ f3 ?( n5 a  K% R, H# gDim count As Integer = bomItems.getItemCount()
5 M( W/ U9 t8 Q2 [Dim i As Integer . _% I+ j8 ~' ^2 n5 f& l

1 P# P5 h* Q8 D" q' Create the results content. ( p7 p+ J9 a3 ~% y4 o! i# h
Dim content As String = "<table border='1'>" + _ , T6 Q5 V) \, D% J& G' g: G
  "<tr>" + _ 4 _7 w& i0 ^* }. M! {+ j
    "<td>Part Number</td>" + _ 5 O0 W- `+ ?1 w; B
    "<td>Description</td>" + _
- [; V0 ]  D% Z" ~    "<td>Cost</td>" + _
& X8 t! A0 I4 r, g3 k1 B  e    "<td>Quantity</td>" + _
; i4 @# S) _; I" n  "</tr>" : S; R  W' _6 b+ A5 M6 m& Z

  b/ F' ^" K) f' Iterate over the BOM Items
2 N( v6 ^( u' A/ M4 Q- g" oFor i = 0 To count - 1 * o- X/ @! {5 F. a7 l5 ]
' Get a handle to the relationship Item by index.
0 f. q$ x9 g7 f" v1 x  Dim bom As Item = bomItems.getItemByIndex(i)
# m/ |) y; C) L  r8 t/ i6 T
. v8 t- y& H6 U/ R$ H- u, e9 n% t' Get a handle to the related Item for this relationship Item. : o# ^& @7 u6 u' f2 h
  Dim bomPart As Item = bom.getRelatedItem()
1 Y6 [, ?0 ~/ C+ m5 @1 i7 D' X0 d
4 Y, H" i  `5 r0 m8 \" c3 ^% d  content += _ % z' c& O+ b/ [  d( Y1 U# ~3 Y$ f
    "<tr>" + _ , k$ L- I8 D" C& a0 o9 O1 ]
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ - p! u$ T2 C, }5 {
      "<td>" + bomPart.getProperty("description") + "</td>" + _ ! ]- k4 O5 H  b; \! M
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
/ X: k: }) S7 p$ U* Q: o$ l. d      "<td>" + bom.getProperty("quantity") + "</td>" + _ 9 L7 B1 T0 l0 n- N2 x5 b% ]
    "</tr>"
1 G0 D: l) p# \. ?Next $ J$ ~  U6 J$ o" ^
content += "</table>"
# X% D6 G4 G+ C7 {% ` ! O1 ]- O9 M) d/ i) J" d
Return innovator.newResult(content)
. ?: d) {  h# s5 F$ ~5 `$ F* l5 Q' ]- R  c  O! K1 T
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了