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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  * z% \) }4 C3 R. N6 u
To query for an Item and retrieve its structure you build the query as the structure - r) G8 E& ]0 a( |( w
you want returned.  Use the IOM methods to add the relationships you want and
  O4 Z3 f4 u$ Y( A) z( Sbuild the structure in the Item.  The server will return the structure that follows the
: _8 Z/ |$ l9 T: F: Krequest structure. - _2 V7 T4 f) A1 b2 I% l& K" f
This recipe illustrates several related concepts together, which are how to get a set
! k$ v6 J5 w" |6 Y+ F- eof Items from an Item and how to iterate over the set, plus how to get the related % ~: {8 C7 q( V: B* ^
Item from the relationship Item.
# C7 \' E( w' q$ C9 {7 c5 ^: ^JavaScript  # T. u7 S+ O: p) }" l
var innovator = this.newInnovator();
, p9 U6 Y9 [% E
- z" p# e  v" a% D8 [// Set up the query Item. " A# f  m' X" j2 D* Z
var qryItem = this.newItem("Part","get");
1 _# }$ {5 n3 E2 UqryItem.setAttribute("select","item_number,description,cost"); / f! \5 R: }- x* U( _* a) a& g
qryItem.setID(myId);   |0 P' s8 H+ Z; Y

7 C; v% O6 n: o3 W' b* ]// Add the BOM structure.
+ \; g1 p( b2 ]+ k$ {6 V& P1 nvar bomItem = this.newItem("Part BOM","get");
; Y- R  @/ C( z. M$ I4 U' _bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
, o4 A+ b2 s2 K% z+ q. cqryItem.addRelationship(bomItem);
6 H; N" `) T7 U# n  M
9 N% X* c# K8 a4 t// Perform the query.
! J2 ~& |3 Y  N" D; Q9 {var results = qryItem.apply();
  I3 {0 j" S0 Q% d) S. ^
! @* s; l$ ]& T- M& g$ F// Test for an error. " [" q, a; k4 k8 o" H) r$ B' H
if (results.isError()) {
8 }+ b) d' `7 C4 r* ]. o  top.aras.AlertError("Item not found: " + results.getErrorDetail()); ' C- S, A* b+ W: |* J
  return;
5 H9 R$ O' t/ D  r5 J2 B8 d( M! R} 0 M4 C! a0 A: R$ [# R, Q) {

5 x( U6 _4 D4 A3 L" W# R// Get a handle to the BOM Items. 0 I, ^" R) h' D+ V
var bomItems = results.getRelationships(); ! ~3 h- H' X/ |+ S, Z& r! j# `5 _
var count = bomItems.getItemCount();
. b  g+ h0 u- y
/ @$ |% r% i4 b0 e// Create the results content.
" m0 x2 _0 K2 i- |; m' o! X9 [4 K' Svar content = "<table border='1'>" +
( ]5 X  b# G' j: A  "<tr>" + * a9 F! J! ~( l' M/ I3 K; r! M
    "<td>Part Number</td>" + " }. w! G# e# p# _
    "<td>Description</td>" +
. @- ?$ z$ `% R( N8 |    "<td>Cost</td>" + + l+ X5 _6 C+ j, y7 T" \
    "<td>Quantity</td>" +
& e) H5 K# E3 ?! W  "</tr>";
$ A1 X, M* y; K2 b6 C( | ! q- t3 f2 g: h: q
// Iterate over the BOM Items.
3 ?4 H0 w" q7 d6 i" v8 ~for (var i=0; i<count; ++i) ) y, q' {* j, m2 P1 n
{
# J% c% V4 R, F2 e/ M# U; }$ D// Get a handle to the relationship Item by index.
* T1 Q+ \2 Q: w5 e  var bom = bomItems.getItemByIndex(i); : u2 n! }: k) s/ J: k
// Get a handle to the related Item for this relationship Item.
8 V# M4 T; u# C  var bomPart = bom.getRelatedItem();
: n3 G2 `/ K7 J) z/ l& f9 W" j: [
. @" p" L3 j3 x9 i5 U/ [' W  content += "<tr>" + , ?0 M% ^' g, H) k. A5 D+ A& r0 u" Z
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 6 X! Q; G  }) t9 U$ c$ t
      "<td>" + bomPart.getProperty("description") + "</td>" +
6 q( F4 L+ l" U& i7 e      "<td>" + bomPart.getProperty("cost") + "</td>" + 6 p+ m6 e2 t, p  ]7 R
      "<td>" + bom.getProperty("quantity") + "</td>" + : P) B5 [9 e. U& C' U, u0 F" r8 ~
    "</tr>";
4 p/ E* s1 s9 s}
5 ~) y- j: ~' R8 r4 c5 lreturn content + "</table>";4 a& X5 q3 u0 t) N6 |
, _, M, R- b, \  Q% a! x( i
6 X$ s; A$ ]- u+ R0 z
% m2 \8 q" W% u: ]: }  W9 h9 z( }
1 V3 w1 d/ ^$ g+ o4 ^3 H' `* {, P) }
C#  
% p6 u# o/ }3 ?1 p+ O1 vInnovator innovator = this.newInnovator();   J5 G. W, X; C+ y* m

* i6 S7 H' o3 {, v2 w6 j. `/ |// Set up the query Item.
# h( T) g  F  k. B5 {, kItem qryItem = this.newItem("Part","get");
5 l4 Q0 _5 U$ bqryItem.setAttribute("select","item_number,description,cost");
9 Q- P8 k5 }' B7 CqryItem.setID(myId); 5 Y* N# e0 j  ?1 |

3 a8 A* g- c/ D# Q/ `4 t// Add the BOM structure.
5 Q$ x( Z  Z+ X) s2 R# ]Item bomItem = this.newItem("Part BOM","get");
7 I, W4 C  U$ ?0 F0 CbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
) [% _, C& b3 L9 q: N% uqryItem.addRelationship(bomItem);
# S. Z, h5 ?4 C1 O
9 {& t) ^' d3 h// Perform the query. 7 J0 B" @4 b) K1 ^8 E
Item results = qryItem.apply();
) C1 v/ g5 t- v! o ) l$ B6 D* j! G3 _3 Q
// Test for an error. ! m2 t8 T8 K  j
if (results.isError()) { 1 }, L0 w' O* T. `
  return innovator.newError("Item not found: " + results.getErrorDetail()); 6 r, Y0 Q5 {. ~
} 8 b9 R6 }& J0 }7 t7 Z4 a! H

8 _' n+ y4 t7 n+ N2 a7 o! l6 E+ x// Get a handle to the BOM Items.
; a7 s1 H7 v2 z+ f! R. _  P: WItem bomItems = results.getRelationships(); . Z9 @7 W  o% u0 }3 X" w2 S
int count = bomItems.getItemCount(); ! T$ T0 k) F* D9 X7 U
int i; : c. l" f; ^+ ~7 G3 D
) ~, [, W/ C4 N: X
// Create the results content. # ~3 G! u7 N- z. T- ]
string content = "<table border='1'>" +
. U" }: Y5 z3 Y: a' p. U8 k( q. Y9 R  "<tr>" +
9 j; c6 a4 ?0 Z" T# r    "<td>Part Number</td>" +
4 f3 Z- L% c+ m# T# Y) r- p    "<td>Description</td>" +
1 c  C0 M/ E  U# t    "<td>Cost</td>" +
. ], n. x' r3 n    "<td>Quantity</td>" +
3 l0 w+ J; v* K/ q% t( t5 S  "</tr>";
4 \7 K3 E# ]6 H" l' L  o4 t8 T5 \ & I5 p7 D- s: |, T7 k( Y
// Iterate over the BOM Items. 1 K2 h: t/ ^4 R) Y4 T! @
for (i=0; i<count; ++i)
. t' @. ?& e& J6 @; L{
( Q, K/ k/ F& k# {// Get a handle to the relationship Item by index. ) P5 `- Q: Y7 \4 k9 G
  Item bom = bomItems.getItemByIndex(i);
5 l& P% O3 s: x6 @// Get a handle to the related Item for this relationship Item.
% Y; s# B; y9 O9 V  R- v  Item bomPart = bom.getRelatedItem(); 5 `$ j3 c! ?8 [1 ?2 f
) b( `- E' I$ H. A3 Z
  content += "" + 5 h6 h8 X/ Q% U: K: R6 j0 R
    "<tr>" +
! t' r% ^9 u+ M) G      "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 j, z4 \0 b' P+ P+ T      "<td>" + bomPart.getProperty("description") + "</td>" + ) ~$ ?4 O5 J. S6 J, G( z/ i
      "<td>" + bomPart.getProperty("cost") + "</td>" + 8 H9 o' B% V6 Q9 X% q
      "<td>" + bom.getProperty("quantity") + "</td>" + " X5 ]* u# u$ r1 j- Y
    "</tr>"; 6 a$ d! f; g/ G& z
}
% B( ~, m* |6 G* `, V' [content += "</table>"; ( E/ Z7 R& M0 F# D
! e1 \  l9 m1 t3 a  u' f: z- I
return innovator.newResult(content);
% K9 M. T0 m' j2 H, d& @1 U5 R# Y
" c" N4 P( ?3 p& h

9 h6 ?# i' ^* @0 z. O0 K
2 H) D( s4 D7 t5 G

  |% _) W% j6 G3 [: ]4 W  x! n6 @: }* u% F1 [

/ C8 W7 Q. F6 `+ B' e7 |% N
, |4 Y( P6 z4 j3 ~5 n! D0 X    Page 46
9 X! K2 p$ M$ f1 B5 m
8 ?/ A* A9 w0 S$ W, R2 P2 ^. E3 \9 YCopyright   2007 / i5 P! i6 `4 S& b
Aras Corporation.  4 {/ `! L. \6 m/ @$ v! Y, }
All Rights Reserved. ) G. M, @& P, n/ l, I
VB.Net  6 {" N  a) R5 ^0 a* |- C  j
Dim innovator As Innovator = Me.newInnovator()
" H# @# |+ J+ o" I  ~8 k0 d- G
1 I1 ^2 \7 Q& M" X% {' Set up the query Item.
" p. W5 X& s9 ]( Z5 f- ~; ^; EDim qryItem As Item = Me.newItem("Part","get")   J! E0 X1 S7 U+ Z0 |' g
qryItem.setAttribute("select","item_number,description,cost")
, e- h$ b# U9 U0 BqryItem.setID(myId) 5 y1 l7 h, m) B/ F. x
0 i5 L4 w; Y! P3 {
' Add the BOM structure.
( n: o% R6 W& hDim bomItem As Item = Me.newItem("Part BOM","get")
! ?) H! f9 ?4 c. H. pbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") $ W0 j+ _. ?  E/ n4 U: ]+ X; o
qryItem.addRelationship(bomItem)
3 f) A: J0 O$ z1 L1 [; N
% m8 q8 D6 L" {$ l' Y' Q' Perform the query. 0 |& [; s: y) H
Dim results As Item = qryItem.apply()
: C6 A4 a- g& ]/ Y / Y1 b2 c! H, P9 A" p0 Y! Z
' Test for an error.
3 G. b/ Z% f+ }" ^$ `1 ]/ \If results.isError() Then : Q/ ~/ m9 T( m4 b) ~* b/ P
  Return innovator.newError(results.getErrorDetail()) 0 O+ t5 o0 ?4 Q; @  d
End If
" K" ~; c4 J& @% f. {& i) N. g" D
/ p7 R8 _" w7 H" G7 d" i: o0 v, w' Get a handle to the BOM Items.
, p6 ]3 j, r' ]Dim bomItems As Item = results.getRelationships()
3 F: M7 \3 a" J8 ^3 Q& u/ C' zDim count As Integer = bomItems.getItemCount()
$ |+ ^+ f8 S/ u+ |* ]  gDim i As Integer
7 B# p1 X5 k+ k
/ N/ U, b4 t) L* ~1 A/ X' Create the results content.
2 K0 c2 U1 k: a6 |: {Dim content As String = "<table border='1'>" + _   V$ q/ Q8 R  C- l: r
  "<tr>" + _
7 D  T7 E& h" s6 B    "<td>Part Number</td>" + _
- \# R3 Z' X6 f2 T1 M    "<td>Description</td>" + _ - \/ e  t) p: S  Y+ g- U9 c% u
    "<td>Cost</td>" + _ ! k" C6 [/ f# x' F* Z' \, g
    "<td>Quantity</td>" + _
( u0 C" N; ~5 ]: H# v  "</tr>"
( f  k3 `0 Q+ t- L8 {* u" x% q; j 0 r# X3 o9 F4 r4 v4 p! D' |6 w
' Iterate over the BOM Items ) t* a& j; `' K' r
For i = 0 To count - 1 3 ]: O( B# n4 B6 Y# [
' Get a handle to the relationship Item by index. 5 E# B% J1 |4 D  B* _
  Dim bom As Item = bomItems.getItemByIndex(i)
. L  v" a5 r2 I6 S/ [
5 L) h% }3 Q' q2 V% M' Get a handle to the related Item for this relationship Item.   |2 r2 A0 v0 j8 _$ o
  Dim bomPart As Item = bom.getRelatedItem() % \/ Y* v4 O* ]1 h5 W

% M, N9 {. b, W  content += _
! C% Y; Q$ }& J3 L/ G- w, D+ h+ e    "<tr>" + _ % g: ^4 w/ _+ \# X5 f
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
# c* ?. U9 l. |5 E. C' K      "<td>" + bomPart.getProperty("description") + "</td>" + _
- ^  v& G& [* i, k$ w- g      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 4 Q+ Z" x- Y: r4 O
      "<td>" + bom.getProperty("quantity") + "</td>" + _
, H$ J7 q/ {7 y$ ~; q% H    "</tr>" ' {% u5 S# _  h; }. n
Next
, H0 G/ [' ?, G) C; Pcontent += "</table>" / G3 h, M4 ?  F- M6 Q7 g# G: R. K
7 g$ G) V/ c* c4 b- m, U/ {1 P6 O
Return innovator.newResult(content) , H5 Q9 q3 x, M' ]
  ?2 D# e$ p1 f& _% h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了