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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  . N0 _1 b! ?! e* o8 ^0 F: V
To query for an Item and retrieve its structure you build the query as the structure 3 T; o! E, \8 q& g$ D- z( d8 _
you want returned.  Use the IOM methods to add the relationships you want and " {: M; J$ R6 R' U; _! G5 G
build the structure in the Item.  The server will return the structure that follows the
- K# N1 _) m9 v9 [/ Prequest structure.
; C) C& I# L4 B, Z2 G- w7 TThis recipe illustrates several related concepts together, which are how to get a set + K% Z2 u7 {& ]- \! t8 U$ ~
of Items from an Item and how to iterate over the set, plus how to get the related % M! h, r4 J. r7 X1 E0 a
Item from the relationship Item. 5 }: `9 j% d% c2 `7 z2 B" b
JavaScript  1 w0 g' [! t2 F
var innovator = this.newInnovator(); ' v1 l; J5 d( z7 Z( E5 l" b
+ N9 R* ?+ p' i- W9 X6 ^' i
// Set up the query Item.
) V) v( \1 o0 m; x& F, b" c* P) n, ]var qryItem = this.newItem("Part","get"); ' g: x! L# ]- a' E
qryItem.setAttribute("select","item_number,description,cost");
9 Y( q  g4 q1 _4 |2 `: lqryItem.setID(myId);
* l3 {( }4 p$ o 2 H+ \& z+ g, Z+ o3 ]
// Add the BOM structure. # R' A: I; O0 F7 ~7 p" f/ |5 Q
var bomItem = this.newItem("Part BOM","get");
9 N- i  e' ]* e; |3 r# k* v# zbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
% t; O1 w$ \( r1 `$ jqryItem.addRelationship(bomItem); 9 i5 k+ [' m# m# a/ P& ?& o# t( b' A

2 K% W/ V; Y& r5 C! Q3 S// Perform the query. ; a- L6 |% ?4 n/ ]& o
var results = qryItem.apply();
* u. \- E" I) G' J% c4 x
; {! i) u- Q% t5 T// Test for an error. 8 [& _5 M" y5 M7 W
if (results.isError()) {
7 V& L0 E1 c' J# t& _' O  top.aras.AlertError("Item not found: " + results.getErrorDetail()); : y5 g: Z" @- O: C6 d  ], |+ o
  return; 8 g3 Y) ]" N! B# S5 k, r/ o
} 0 r5 ^. Q( `- `5 _9 l

. P, J* b7 j6 d2 w5 s// Get a handle to the BOM Items.
! z/ ^# f3 K& B- b- ?  m5 uvar bomItems = results.getRelationships();
- j) h  N2 D' _  L* e; P4 k7 c  ovar count = bomItems.getItemCount(); 7 R! @* M, D+ q5 j& r2 |
1 M/ h# v% D# I% `" c5 o
// Create the results content.
0 p9 Q& U* Z& `% _7 uvar content = "<table border='1'>" +
/ M5 M/ b$ _0 N) j5 @  "<tr>" + + f$ Z  U9 p# K6 L$ U" l# K5 U2 H
    "<td>Part Number</td>" + ; o; `) e4 @+ p% u) A2 I' f
    "<td>Description</td>" + 5 z1 \! X0 w6 S# y0 ]
    "<td>Cost</td>" +
( c- A) y* f6 s5 v+ ^    "<td>Quantity</td>" +
( O3 F4 i4 ]$ `  C  "</tr>"; " D. ^; N1 q& a, o/ A
+ c. B, u% w4 Q# I. ?1 [4 a, o' L
// Iterate over the BOM Items. 1 [. V! r1 _1 L+ @
for (var i=0; i<count; ++i) 3 k( V$ R7 h* l; D" c, v
{
+ q% ]4 I, M: d5 z// Get a handle to the relationship Item by index.
6 z  h: |4 |) M% P4 H. u  var bom = bomItems.getItemByIndex(i); $ U& K8 D- j  h* b
// Get a handle to the related Item for this relationship Item.
# T$ N; T, W+ a7 |* X6 {9 w  var bomPart = bom.getRelatedItem(); ' U' h  Q5 _& y( F( p

- R5 G  E8 D- a1 C' e* U  content += "<tr>" +
2 X  Q% K8 W8 W0 Z      "<td>" + bomPart.getProperty("item_number") + "</td>" + 6 f/ ^. ?1 [3 w% b% v
      "<td>" + bomPart.getProperty("description") + "</td>" +
6 [4 T/ `5 x. B9 p( x) b% E+ O4 p      "<td>" + bomPart.getProperty("cost") + "</td>" + + o% b2 f6 p* v/ K0 o5 J3 M
      "<td>" + bom.getProperty("quantity") + "</td>" + ! A) Q+ a# x( n4 g/ Q
    "</tr>"; 0 T8 W: \  \( I: B2 s* I
} 7 Y3 [' q# B) ~& f9 m% w
return content + "</table>";
/ t6 F# @! p  G  u9 a* \4 F# e) T* B  J- v

9 m9 B/ }+ |& M3 z4 E: v
8 `& Z! o+ t% e5 H1 ^  P
: J  {$ o: [8 h/ k+ m
C#  , Z6 A: h$ T( K. ]  C
Innovator innovator = this.newInnovator();
8 y- |+ ?- C" v- M7 N 5 [( @" H: I" _$ ^
// Set up the query Item. + A  z; b% p. P4 r* C$ x( ~( B' N; J
Item qryItem = this.newItem("Part","get");
$ D8 w$ D8 O  p. K  JqryItem.setAttribute("select","item_number,description,cost"); ' [  h" y2 U6 U& A
qryItem.setID(myId);
0 C( k; b) }, c$ ]& p' o2 L7 X
/ D+ I! L8 [+ A  G3 f// Add the BOM structure.   S) ]+ L& q! r1 u$ i$ G
Item bomItem = this.newItem("Part BOM","get");
, H8 [6 Z. H8 C- SbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
. @/ U2 ~0 U# r3 A6 x$ w- UqryItem.addRelationship(bomItem);
9 Q" {# R" V/ c- N) `
0 |" X' Y4 `9 E3 V: T9 U* ~6 ^// Perform the query. * @& U4 R' S) `# _5 u
Item results = qryItem.apply(); $ `9 |/ x2 \8 S0 d7 G7 b  T
( P" J3 |% v1 j  p! p9 v7 Y
// Test for an error. # ~7 q7 [4 \' ?1 X
if (results.isError()) {
; |* W0 D4 `2 ~: Q2 _$ ^# P  return innovator.newError("Item not found: " + results.getErrorDetail());
0 q# ^3 r- h- r1 C1 F4 S: E} 5 D  a- V7 Y  G8 T
/ z  @+ K8 }2 P8 Q/ \7 z
// Get a handle to the BOM Items.
3 d# l! _; p; R9 iItem bomItems = results.getRelationships(); 1 b& L/ d; l6 Z; O" e2 g
int count = bomItems.getItemCount(); - d# i7 p. e2 M+ A0 X3 D; l
int i;
0 ~$ ~) S( b$ [5 y $ k7 H  K: X4 \
// Create the results content.
* y6 ]* I5 \$ [( Wstring content = "<table border='1'>" + . S" P& a, s: r; b4 A4 w1 ~( v
  "<tr>" +
/ }# o) y( y  R6 M    "<td>Part Number</td>" + ( K8 z- d; w, p
    "<td>Description</td>" + 1 g( q9 v+ t; [" P
    "<td>Cost</td>" + 1 X- L: ?7 ]6 k) N& {  G% c1 x5 B
    "<td>Quantity</td>" + 4 _, B0 N5 m6 s3 n, E- \& I
  "</tr>"; 4 W2 M/ B" W. v" o

) M, d3 }$ K9 O6 Z: j7 o" s// Iterate over the BOM Items.
' l+ R( k  o9 ~4 W, r& E: P4 bfor (i=0; i<count; ++i)
1 S  H# e" t4 H% \! p+ t- ]" V{
1 V2 x) o! `# X4 @- N. v// Get a handle to the relationship Item by index.
# L9 c9 M5 ~* a  Item bom = bomItems.getItemByIndex(i);
- ]+ X" U" s7 Q" E// Get a handle to the related Item for this relationship Item. / X* q- Z% P4 P- p+ b
  Item bomPart = bom.getRelatedItem();
" c# f, b: h* x6 b* j5 [. E" _( o & G% f" ]3 {8 ~  i+ d& j3 S  r
  content += "" + 4 s  r  q1 t: ~9 i
    "<tr>" +
# R* U$ B+ d: C; \9 u! p: w1 l      "<td>" + bomPart.getProperty("item_number") + "</td>" + % z/ r4 z$ Z' W, o
      "<td>" + bomPart.getProperty("description") + "</td>" +
, i5 X8 a2 K9 Q. u- y      "<td>" + bomPart.getProperty("cost") + "</td>" + - {9 H  g# {. B7 t8 w
      "<td>" + bom.getProperty("quantity") + "</td>" +
8 A" U6 K! ]) I# \    "</tr>"; ! h' d& P4 c  {. `& e" U; x
}
! R: B: c8 j0 Jcontent += "</table>";
2 ~# `$ Z. E4 y/ U
2 y; n7 Q7 @8 Y! H! S' H+ X" Creturn innovator.newResult(content);
2 |7 W6 f" A6 m1 a
3 ?9 h" ^2 @5 j, F' x2 q. w
+ ?2 g( H" L2 d6 D: Y9 S3 T2 ~! n
, f* \$ Q/ }) G5 G2 C& V& D
. @: m+ I3 [" \" A6 K0 B& h0 {& {5 i8 m

3 c& ]0 q3 t8 C" k3 K

$ z4 p- s. N' W! p2 Y3 C" d( { + d) S$ L8 ^% Q- S' G
    Page 46 - _; k" I& ~$ U1 g8 O7 s

2 l' h1 t, K" [( P/ gCopyright   2007
" ^1 t3 B* D/ }4 r% z4 Q' kAras Corporation.  
7 Q1 s8 I* M+ g2 ]All Rights Reserved.
8 N9 X, ?9 p0 XVB.Net  1 s" M: ^: ?" m
Dim innovator As Innovator = Me.newInnovator() # ]  p: w8 m- N, n# u

% B6 a1 E. {/ k  C' Set up the query Item. ' v/ b8 Z! P& d
Dim qryItem As Item = Me.newItem("Part","get") 2 s7 `$ B6 \, k- ^
qryItem.setAttribute("select","item_number,description,cost") # C; o# e& `+ a6 d6 a1 d3 ~3 \
qryItem.setID(myId)
" x# \5 B$ o/ s% O6 V7 c: l
' e5 `$ A' V8 X" G* ~8 W5 U# e' Add the BOM structure. 6 s/ B8 ]# I, k; U0 _* ]4 t1 D9 N8 f
Dim bomItem As Item = Me.newItem("Part BOM","get")
1 J4 [7 D) S( L& N1 D6 \# k$ }bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 5 \+ J! C2 g6 {
qryItem.addRelationship(bomItem)
# b: q/ \0 r9 Z8 ~
; A; z  W; C/ U' Perform the query.
6 }/ [- j: Y7 VDim results As Item = qryItem.apply()
- i% B  J1 h* Y8 U: z+ l2 ] 3 n- ?! T* r; Z/ Q( K0 @4 U* R- q* G
' Test for an error. , [4 R# Y: P" }, j) S  L2 i0 g
If results.isError() Then ! G% x* L/ M5 _' I' J3 U
  Return innovator.newError(results.getErrorDetail())
4 `" r$ y4 J2 V7 hEnd If
6 y! v* H6 G% L$ O7 R1 {1 ]
7 i9 Z$ G6 @/ Z9 e4 I' Get a handle to the BOM Items. ) X0 H" y/ {) Y$ p* _
Dim bomItems As Item = results.getRelationships()
' h( I% C2 @& H) P0 tDim count As Integer = bomItems.getItemCount()
. V3 U" i9 m3 S0 k* ^9 ~Dim i As Integer
3 w" R, F1 {6 b0 I7 H' V
2 `* H$ K; r' t1 y' Create the results content.
+ g: ]% T9 w/ \: {2 vDim content As String = "<table border='1'>" + _ - q1 |! S0 z4 A9 H* X- }
  "<tr>" + _ " Y0 Q+ L1 s" @% v% h, m8 T1 m
    "<td>Part Number</td>" + _ # N4 @+ [4 L7 K  \" f
    "<td>Description</td>" + _
) |; Y8 J: R' d; g    "<td>Cost</td>" + _
* o4 b0 x/ Z$ H% n4 |    "<td>Quantity</td>" + _
( _! A/ ^* ^8 B  "</tr>"
- `5 r% d* u4 y
' ]4 ?* ?+ F, J3 z3 D' Iterate over the BOM Items 0 A6 L- {' J% h" b& M4 c. w
For i = 0 To count - 1
# S7 \! o1 @  I# M' Get a handle to the relationship Item by index.
$ X* S$ l# Y( X. P7 W, z  Dim bom As Item = bomItems.getItemByIndex(i) * ^. P  Y5 m( T+ [

1 p+ D, [5 i! i6 O+ R' Get a handle to the related Item for this relationship Item. * j* f( r9 D* g3 E0 T
  Dim bomPart As Item = bom.getRelatedItem()
2 M& m+ o; a; z+ N! i. L9 l * N1 Z- i. U6 r+ S
  content += _ ) c' ?9 m6 ?6 s9 I: u3 n: O. T( }& z
    "<tr>" + _
, z! m+ D: h! U8 M      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 8 [) w( E9 r6 @; {
      "<td>" + bomPart.getProperty("description") + "</td>" + _
8 H1 C4 \% _, }1 C: S  U7 I' l      "<td>" + bomPart.getProperty("cost") + "</td>" + _ - n) f8 M& b, Y$ G& C
      "<td>" + bom.getProperty("quantity") + "</td>" + _ 3 v0 |2 N6 V  o- }
    "</tr>"
8 z  i  c/ c7 X/ U+ ?Next
. ~% v. `$ r1 i7 t* X7 Icontent += "</table>"
0 p8 }8 y& N0 m1 t / v+ y/ d$ l6 @3 z5 h, [3 d
Return innovator.newResult(content)
0 H. y$ l- G# g& l6 u& h# p. q1 I( P1 i7 S$ Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了