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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  / H0 \* Z8 L' O
To query for an Item and retrieve its structure you build the query as the structure 5 K: y" W1 V/ V
you want returned.  Use the IOM methods to add the relationships you want and
; H; _4 d( S% L7 s. t3 E3 bbuild the structure in the Item.  The server will return the structure that follows the + B4 s. t, H( B8 L2 o. D& ^
request structure. , P6 Q! c6 e6 n/ l- X5 K
This recipe illustrates several related concepts together, which are how to get a set
. i# r4 F  Q! Dof Items from an Item and how to iterate over the set, plus how to get the related : T8 n# I3 n- r* X- R2 k
Item from the relationship Item. ; {! P4 j$ {; d$ @5 D" p' q! @
JavaScript  
1 O! A# Y& ~. k4 g9 Vvar innovator = this.newInnovator(); 6 S, Z- ^( p  f' R, r3 B
/ t3 p. d# U7 ~( q( E6 f: F5 R( d) L
// Set up the query Item.
+ c4 M* @1 N' D9 o; Ivar qryItem = this.newItem("Part","get");
" j, M; C6 m! R# FqryItem.setAttribute("select","item_number,description,cost");
. [2 t8 q0 ?0 EqryItem.setID(myId); . T8 ]( U1 ^; T, p

- \+ H! d( O2 M: G7 x! k// Add the BOM structure.
5 y" b$ Y6 ^. L9 [+ l5 F% p4 Cvar bomItem = this.newItem("Part BOM","get"); 6 ^( Q: F* U; j
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
% W4 y; D' [; Q' i( B) b) ?qryItem.addRelationship(bomItem);
8 t1 B$ W6 d' ~4 {   b- u. ]) M1 z) x. B! F
// Perform the query. % r1 o$ h: N6 o+ w$ [
var results = qryItem.apply();
7 B0 A! g5 p5 H; O8 D8 {
. ~# o! U1 n9 M% e. T7 `// Test for an error.
; `0 Z3 v4 J) @6 g- zif (results.isError()) { 0 o( _* r  v" q' O2 [$ b
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
& Q1 v7 e' a2 v. w7 S6 {8 e, u  return; & B- K# @3 h( u( p0 }5 q
} # {+ a$ h3 K1 _9 M( q8 t$ T

2 s" P: n8 D6 ]9 X. p// Get a handle to the BOM Items.
# o/ u5 ^4 M: e- ^4 w( t; Rvar bomItems = results.getRelationships();
; \9 A( ^* L% }- z2 N4 v0 `* uvar count = bomItems.getItemCount(); ' J# q/ D& W: a: S( [- Q) N
$ z5 ?1 N9 r# U( ?
// Create the results content.
6 h0 M$ p  ^* G2 s" dvar content = "<table border='1'>" +
- e! o( G( _. w) H5 z! Q  "<tr>" + , M5 }4 `( V( W& j0 |2 W
    "<td>Part Number</td>" +
0 @9 J2 g* w$ W! J5 F& z7 ]# [    "<td>Description</td>" + 2 ~" O# |, y5 C1 i; y" l$ D
    "<td>Cost</td>" + & r+ x, ^2 K1 D
    "<td>Quantity</td>" +
& R# R- y" H8 r+ c6 U" B; e  "</tr>"; + c: _( z8 ]( @2 {  v

0 B2 y4 J( [/ m7 h9 B# \, k// Iterate over the BOM Items. ( O& I% U6 w* L6 t
for (var i=0; i<count; ++i)
; N4 z! G2 W1 F% b+ T{
0 P$ X. {$ |1 E7 I& \; |: u6 c// Get a handle to the relationship Item by index. 4 c5 O) x6 _3 |. b; w5 C( e
  var bom = bomItems.getItemByIndex(i); - ^, l  n* N, O
// Get a handle to the related Item for this relationship Item. 4 _* D6 p5 P( Q7 [$ u
  var bomPart = bom.getRelatedItem();
& t% V7 ^4 `; d7 I: G& t * j. [7 d* X, Q6 Z) y! ~; u
  content += "<tr>" +
* b9 z+ J" I/ S! c& e0 I      "<td>" + bomPart.getProperty("item_number") + "</td>" +
" A; R  u  X" e" J" e      "<td>" + bomPart.getProperty("description") + "</td>" + 5 p( a0 y; c) x+ G9 y( |# y
      "<td>" + bomPart.getProperty("cost") + "</td>" +
: k6 b: m' X* N( }% n* q      "<td>" + bom.getProperty("quantity") + "</td>" +   d9 D8 {( o) u% P
    "</tr>"; ' O# f2 U; Z. v. Z! T5 e
}
0 k7 u( p. N2 ~2 u8 dreturn content + "</table>";" B; |; E3 k; |% O

- [& D9 S0 D: `; R) X/ Q- R5 n

3 s) E1 {  V$ _' C  w* v6 I0 E
, D! ~, s% ^4 e$ r& y& ~9 a( a

6 X& p' \9 _! d3 h' c* D5 NC#  
( [0 [  Y: ^7 A0 OInnovator innovator = this.newInnovator();
/ B( ], O4 e8 @5 a' d6 [ 4 b9 j. N( w7 z2 L" n. H9 R* n
// Set up the query Item. , j9 G& E9 S2 @7 A- ?; m
Item qryItem = this.newItem("Part","get"); ( h- ^; O. q: ~$ u+ ?  O
qryItem.setAttribute("select","item_number,description,cost"); $ u8 H  h1 S2 M
qryItem.setID(myId); 6 H5 B9 X" w( H9 z

. h, z5 l% h# v( B// Add the BOM structure. ! [7 I% W+ V- ~& S6 y- V  ^
Item bomItem = this.newItem("Part BOM","get"); 2 K( V& B# C4 T, j. C" w' c$ P% s
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
: \/ y) G. R; t: ?+ vqryItem.addRelationship(bomItem);
! `6 o9 J  A' K8 B . i* d  b# Q/ Z+ {
// Perform the query.
2 Y: `. h! k6 s$ s$ I* zItem results = qryItem.apply(); / P2 k7 I6 {6 _8 C
) u' t9 I6 \" X/ A  I% P4 [& S
// Test for an error.
. [+ n+ I0 y: C; w4 q5 v$ Cif (results.isError()) {
4 Z. ~" w" B4 s/ O* ?  return innovator.newError("Item not found: " + results.getErrorDetail()); # }1 s3 d. N9 n2 A5 ^! D
}
+ \' ?7 h# @2 `. X; b* A ( z' r7 w! o/ E
// Get a handle to the BOM Items.
; m7 M. K8 E2 A, ~Item bomItems = results.getRelationships();
  Y) o0 D$ S2 x3 uint count = bomItems.getItemCount();
9 W6 m, l& D* h7 ~int i;
# }* m  R0 [; ^( y: m
' {; x  ~4 D. D* K// Create the results content.
0 ?2 {# _) u) h0 s3 R! |: V: `' |# a$ istring content = "<table border='1'>" +
: F# o8 [7 b/ T' t2 j6 Q: A# d: K! S8 M  "<tr>" +
2 N% C/ a+ k+ u    "<td>Part Number</td>" + . {4 w/ c9 V& Y; q9 _( @$ \) B
    "<td>Description</td>" +
8 u; O5 |6 O3 k0 I( c    "<td>Cost</td>" + ! m) _- l$ Z: v7 S, j
    "<td>Quantity</td>" + . \7 `3 a/ I( ]5 J! U
  "</tr>"; ) v9 K! U+ B0 {

/ s. _7 x! C% P$ c// Iterate over the BOM Items. 7 h- Y" e. ^7 O( P
for (i=0; i<count; ++i)
' b- D7 y2 F  m; C: B{ ! j, V6 |! m$ q* H2 Y) Y$ l" V) h
// Get a handle to the relationship Item by index.
5 `( D6 G7 d0 l0 d) u0 F' `! f  Item bom = bomItems.getItemByIndex(i);
1 O; {1 C: v0 Y4 B, _; `// Get a handle to the related Item for this relationship Item.
) w7 ]  h+ |2 J! A: o  Item bomPart = bom.getRelatedItem(); % g1 ^1 p6 B( q0 I$ c. _
$ L: V/ c6 I# e/ z: ?$ o
  content += "" + 4 K* x( O" l/ Q& M8 D" U4 ^9 \
    "<tr>" +
6 E8 T% B% G% F" w: I+ J* `2 \- b      "<td>" + bomPart.getProperty("item_number") + "</td>" + ( A/ M& K: I! \1 J
      "<td>" + bomPart.getProperty("description") + "</td>" + " Z2 ~7 j; H' `: ]7 R" ~5 H6 V1 C5 [8 S
      "<td>" + bomPart.getProperty("cost") + "</td>" + , D- ?3 F8 B3 K$ g8 }1 |0 v. S6 R
      "<td>" + bom.getProperty("quantity") + "</td>" + 8 K" }. I0 p! _  `- ]
    "</tr>"; 3 D# X) v- a* z
}
4 u4 C6 i6 }" d$ J$ {% Qcontent += "</table>"; ; u' y' D# |: h9 k) T) x' c

# @' p" G! ^; K0 j# r; mreturn innovator.newResult(content); ; |  `8 N9 Y' B5 H* c/ C7 d9 o/ @& c! h

; u$ [' k" F# g' G6 z3 M# P6 B0 A, w

4 G" B+ y: e8 U4 W, H, w
! b7 a! ]/ C1 V9 J
! _+ O+ @6 _: e2 L: N0 H; C# t

8 N! Q0 g/ h' D! B0 T/ n- _! O
: T# W$ T& ^8 K" |2 w/ K/ `

7 F" h/ L, @; w+ ^    Page 46
. ~0 G# e, b8 E
, m2 V4 Z0 g2 O) H$ cCopyright   2007 8 U& K! v2 W) C/ `
Aras Corporation.  , _, J% X$ ]+ a  V7 N, B# s8 i
All Rights Reserved.
% j  `( \( f6 x3 N5 o! ZVB.Net  
) T7 g" e4 K- ]  a* c: r7 T# |Dim innovator As Innovator = Me.newInnovator()
. }( L5 x7 F: s8 ~; \9 q 4 ^  ~3 Y' y4 b/ {
' Set up the query Item. ; b8 o1 G2 W  ?1 G
Dim qryItem As Item = Me.newItem("Part","get")
) [( G) F& H$ m2 t4 ^5 H% m; W1 E4 JqryItem.setAttribute("select","item_number,description,cost") " k) ]4 w( L, W
qryItem.setID(myId) 8 P7 {- T0 ^  p

# A, i+ I! K7 {8 T: x' Add the BOM structure. 3 B& w  f3 Q1 M$ u9 L
Dim bomItem As Item = Me.newItem("Part BOM","get")
8 b7 g' {6 {' }5 k! ]4 s4 ?bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
/ }: ?* K3 o7 n7 Y0 hqryItem.addRelationship(bomItem)
1 ?' B! K$ {2 ~8 d
0 H7 V( D2 E: R+ _' Perform the query. ' D2 F, G  n. W$ B# k% P* c
Dim results As Item = qryItem.apply()
1 t" S  S/ n4 }! \: K# b6 n
* x4 H( d2 R$ r' Test for an error.
/ Y# Y8 m5 N. z) j0 X$ |% JIf results.isError() Then 8 Y7 H8 r; T1 R4 T- h
  Return innovator.newError(results.getErrorDetail()) 5 o& d1 t6 I/ E% |
End If ' L* e! U( A# P$ H; k4 p2 m9 i

2 J4 c) ]; a& o8 ^1 I$ g4 X/ M2 f' Get a handle to the BOM Items. # n$ y# P( U$ ?8 y* Y# [
Dim bomItems As Item = results.getRelationships() + l! D" E  }* }, X1 I1 a
Dim count As Integer = bomItems.getItemCount()
7 ^0 S6 S: H# ]% GDim i As Integer 0 Y9 g1 [5 A/ r5 Y5 l

, _' U& @" o$ r6 C8 p. l% s- t4 b' Create the results content. 3 L8 X+ t4 h6 _" M$ w6 |/ z
Dim content As String = "<table border='1'>" + _ & M1 o$ `2 T1 @! x7 _) P
  "<tr>" + _
# r8 K' Q  i/ n9 m' @/ A8 [    "<td>Part Number</td>" + _
, e" I  E% @8 @. i; }1 D    "<td>Description</td>" + _ 2 x) s$ P6 I1 ]8 n: p6 e
    "<td>Cost</td>" + _ : J' R$ I; i# k3 _
    "<td>Quantity</td>" + _
2 t4 W& v3 v) h( Q: `& t4 m5 h  "</tr>"
# d0 n% S, R" X # i0 [% a- _5 W6 a! p5 k2 o
' Iterate over the BOM Items 0 G2 e5 P9 d0 X7 }& ?" t
For i = 0 To count - 1
  \9 }) F8 l; R& y& P7 K5 P& l' Get a handle to the relationship Item by index.
& [! m1 L  h: _9 z" Q! z  Dim bom As Item = bomItems.getItemByIndex(i)
; a8 k) C9 {4 f4 ` 7 d; F* e9 Q5 L
' Get a handle to the related Item for this relationship Item.
9 J+ @% p  d! s; P$ I& A% k  Dim bomPart As Item = bom.getRelatedItem()
1 Z- e2 X. S1 w) m# p& N$ J
( b8 Q% ?& ?  Y& [0 o4 o# [  content += _ ( S: U% P$ C. {3 _
    "<tr>" + _ - e0 R5 c2 `5 ?! e2 _  ?$ g
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
: H: i" K7 N% s8 j' A5 ~      "<td>" + bomPart.getProperty("description") + "</td>" + _
8 x1 K# i- E2 W* f) u      "<td>" + bomPart.getProperty("cost") + "</td>" + _ ' y7 F. z" B4 Q$ m) g) r
      "<td>" + bom.getProperty("quantity") + "</td>" + _
: d: l! U2 L0 t) T; R    "</tr>" 7 N; x/ O4 H; c1 n5 s5 `
Next 5 k% ]6 D& D# d5 _0 v3 |0 m
content += "</table>"
$ m8 X7 F- Z1 z) k 4 J; E6 C: A5 G6 C* V
Return innovator.newResult(content) ! v" L2 u- O7 Q2 W4 z  s
/ d( b( R9 a( M+ a& |
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了