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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  % D, f/ b4 g$ Y% l( Y/ g! K
To query for an Item and retrieve its structure you build the query as the structure
# s. z8 G8 I8 O+ G( xyou want returned.  Use the IOM methods to add the relationships you want and % w+ `- g/ C, n7 ?
build the structure in the Item.  The server will return the structure that follows the & r" X/ d9 S$ `. [
request structure.
0 Z) g2 [' m6 m' ]; V9 F7 zThis recipe illustrates several related concepts together, which are how to get a set
8 U3 c! B# R- ]$ l- Uof Items from an Item and how to iterate over the set, plus how to get the related 1 |0 u  g/ V! k, |
Item from the relationship Item.
9 O* D  R4 l# X" K/ VJavaScript  5 {+ ~6 Y+ d: E3 x; `5 g2 _, L
var innovator = this.newInnovator(); , p9 e" N" d* K: u" [5 F9 |6 G

  H% B' ?3 {2 z4 v// Set up the query Item.
$ }# x4 v" _* d8 z2 Wvar qryItem = this.newItem("Part","get");
! T  }9 I( E! _! U) u" ^, MqryItem.setAttribute("select","item_number,description,cost");
& w! o% ^5 b" I. [2 M* UqryItem.setID(myId);
) w9 Q& y4 w. U: r& ~/ J
+ k' f8 }( R4 q! q& P& S9 w// Add the BOM structure.
2 E. P, E8 S9 J7 U. t3 b' ]var bomItem = this.newItem("Part BOM","get");
8 I4 Z/ J, A# }( w4 XbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); : H% U5 V) N+ ?! p8 J+ b5 f
qryItem.addRelationship(bomItem);
7 L( H0 V6 M3 \4 s1 ~2 b/ v( J9 o
- t& b* l9 Q1 @* A6 F1 s8 q$ m. s// Perform the query.
! Q5 `5 w/ M  `var results = qryItem.apply(); # `* j$ z! x' t( x& j) d' n
7 }. @, F, c2 i. D3 U
// Test for an error. # A8 @5 P  r+ F7 ]* c% D) W& z
if (results.isError()) { ( s/ N9 i" ]4 ^+ [) l. p
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 1 }! z( s4 }' R
  return;   F# W5 W. u$ P, _0 v3 Z" G
} ( f! |2 `" y& M' V3 O( t3 `
6 V7 [# j; v2 V+ M" _
// Get a handle to the BOM Items.
# [/ i: P" U) f3 T: @% qvar bomItems = results.getRelationships();
' T' U  s7 D: n; ]! i( M* wvar count = bomItems.getItemCount();
# ~+ ^3 `2 k* Y! s. u
+ h, U/ |. W6 `! X# x  S* P// Create the results content.
+ {# l7 ^7 _4 l, b% ~var content = "<table border='1'>" + 7 S# a9 _. C! C5 A4 d, @( Q
  "<tr>" + , P9 i: F5 X. V9 r- ?
    "<td>Part Number</td>" +
: Q; ?  d; B' F4 z2 U    "<td>Description</td>" + # P) ?4 x2 |& [+ ~, l; v
    "<td>Cost</td>" +
: Z' Q9 x2 k6 a* b0 V    "<td>Quantity</td>" +
+ O% d0 s, n* h/ Z- b6 t  ], t6 G  "</tr>";
0 _" O) T  k" @5 Q4 v3 C
% m& `4 |' X" b  q4 m// Iterate over the BOM Items. 8 Q. Y. o  p" A: [) L. A
for (var i=0; i<count; ++i)
- M: _% X/ S6 g{
) z- y1 B' Z# ?& j5 [! o; \. U% n// Get a handle to the relationship Item by index. , F9 g3 x- F! I! ~5 `4 R& t! y. y
  var bom = bomItems.getItemByIndex(i); , a- O: u% c% p
// Get a handle to the related Item for this relationship Item.
, A4 k. i, j: `8 t  ?; |) p5 a( w+ {  var bomPart = bom.getRelatedItem();
( i3 Y4 s3 w/ h# ?0 b5 E + W! `2 U# `. |
  content += "<tr>" +
4 d, _( P" `' Y! Q      "<td>" + bomPart.getProperty("item_number") + "</td>" +
- [2 B5 Z' H$ e! H* q$ |( C: L      "<td>" + bomPart.getProperty("description") + "</td>" + ) h' D8 @/ \$ R' r1 Z: |
      "<td>" + bomPart.getProperty("cost") + "</td>" +
% c2 q$ t" D& V& R2 Z      "<td>" + bom.getProperty("quantity") + "</td>" + , v* i) \9 S# h; F4 H' b
    "</tr>";   f+ R* e) s& y3 i9 e' u; {
} - R' F' n( p* k8 f' i/ v
return content + "</table>";
# O& \+ s0 |: @: [+ u8 B% Z' `9 f( w  _8 R
$ A, @' m' t! L" P$ k6 U1 Y
9 @/ T" ?2 g+ ~* X
5 H4 ?9 r% m! P7 b" j4 U) L
C#  , u  W4 `- @! z  x
Innovator innovator = this.newInnovator();
# O0 w) ~2 g7 a% S  w: [
8 \2 B/ e; y1 L! |$ p// Set up the query Item. 1 ^$ t& V% t9 a* \/ Q
Item qryItem = this.newItem("Part","get");
; O# B5 ^% d' V5 h4 kqryItem.setAttribute("select","item_number,description,cost"); 5 b) Y2 n& y/ W  o. Z( T" U
qryItem.setID(myId);
* I! z4 `: a  t* _- L( M6 B- { 1 C& t  i$ r6 b! Z+ a
// Add the BOM structure.
3 ]8 H/ P; B0 j# |* }Item bomItem = this.newItem("Part BOM","get");
- d7 ?( F1 H" b+ F( x  P9 E! kbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 1 h& L( r: \) ?0 H
qryItem.addRelationship(bomItem); ! I0 V6 Y1 G) [3 S5 \7 U9 N4 h

  x. f+ `6 W) i. E// Perform the query. " Y8 A5 ?; K5 g6 v8 `* n
Item results = qryItem.apply();
- s6 n2 y$ y" K; ?8 ]% n2 }
0 I% B2 A( @" R// Test for an error. 9 f: p4 M% y7 @0 R& M3 B0 W
if (results.isError()) {
5 j' ^% A- ^5 q  return innovator.newError("Item not found: " + results.getErrorDetail()); 0 S0 R) v! d$ Y9 \! F4 D
}
3 w8 j& `( F2 b9 e- L1 T * T6 J, X- ~. O+ f3 Y: }
// Get a handle to the BOM Items. ; a; f" B, U9 E- \( [
Item bomItems = results.getRelationships(); . q1 Y, C+ o. Z. C. o
int count = bomItems.getItemCount(); . G, ?& V& [% p! e9 R* }' `- U
int i;
2 s- Y- f  j4 r- S 3 C+ V. E, O: T, t
// Create the results content. ( j- Y. N0 J4 _% }* `3 M
string content = "<table border='1'>" +
- z. A4 g/ h# Q  "<tr>" +   Q& `3 j+ B* Q
    "<td>Part Number</td>" +
- R& c  M$ r, R  i$ r* k9 B& v    "<td>Description</td>" +
4 p( ?; F: B6 D1 R& h# m& ?# k    "<td>Cost</td>" + . _: L3 b4 }( Z* p# d  @. A+ _( ?
    "<td>Quantity</td>" +
1 j6 n. }2 S5 D% k6 z  "</tr>";
. S" _7 `. N" Z9 G, I' E+ c2 h + p" p/ m  x- W  V0 ^% l, L0 X
// Iterate over the BOM Items. ; ~1 c6 H% ~2 L+ ^! ]% Y- b
for (i=0; i<count; ++i) / s5 J, E& R; _1 ^0 i( R
{ % B" }# e8 A* C0 ?5 k6 ^$ N( L3 }
// Get a handle to the relationship Item by index. - N$ ]2 ~1 ~0 V8 ~1 {
  Item bom = bomItems.getItemByIndex(i); 4 g* O& E3 W& `- |7 h* o
// Get a handle to the related Item for this relationship Item.
; ]/ m% j# P0 R( h  Item bomPart = bom.getRelatedItem(); , I' B. D( ~9 M6 ?6 ]7 H6 W

% p4 a* D* S; W5 h  u3 L  content += "" + 7 e8 E/ Y  Q  U; N- O
    "<tr>" + ' @  C1 D3 w) @- r7 {7 U
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ( [: n3 h2 ^$ x. [- x
      "<td>" + bomPart.getProperty("description") + "</td>" +
# w2 ?, i. r* O: T/ d: x0 `      "<td>" + bomPart.getProperty("cost") + "</td>" + 4 o7 J" g+ f; Z  q. A. Q9 r
      "<td>" + bom.getProperty("quantity") + "</td>" + 8 ?& n6 e+ d0 ]. F  l
    "</tr>";
# X( `3 P( N0 b; W* M} 9 J$ D- ]) g+ f% d& b7 p( J
content += "</table>";
' v6 D; m& a2 j 0 k# C, r2 b  N- W
return innovator.newResult(content);
! I- X; D/ s/ X4 f
8 `- H+ H) H9 `6 s/ ^& b; P: r6 C

. s9 s) K: \+ J8 B: q& G3 a, d
+ R1 q# [( w3 U* r
! ^; b1 c: w/ {1 T0 g

5 I4 S: p7 Y4 A+ N

3 u! d0 b5 o1 I1 j9 y 2 F4 _6 Y: B0 e: |
    Page 46 1 Y  l! a* @% N/ t

) D  Y$ n% p) M! F$ [! \Copyright   2007 ( _  W& C+ a3 U# Q% z, M/ L9 h
Aras Corporation.  
$ B9 J( D# q  M2 D7 EAll Rights Reserved.
" {( C8 z) {& O  LVB.Net  " G; B; e* b: g4 t- N/ b* k+ @
Dim innovator As Innovator = Me.newInnovator()
1 E9 q, e5 E; s: c- Y$ f8 L) p
6 ?2 H8 `+ n8 a  D: G' Set up the query Item.
$ |0 R/ h( M* O! t# c6 z1 F/ p2 WDim qryItem As Item = Me.newItem("Part","get") ! M9 I0 d3 i7 R6 R+ E7 o
qryItem.setAttribute("select","item_number,description,cost") " p' \: m9 ~) B' u. O# W
qryItem.setID(myId) ' s, J* g- p5 K! A: F
7 }& U" [: Y% w& ^
' Add the BOM structure.
3 q' \" @) P9 a7 `: N# p$ y  oDim bomItem As Item = Me.newItem("Part BOM","get")
3 K3 ]& f- v& _  T8 w7 ebomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
' ]/ b6 H! N' _qryItem.addRelationship(bomItem) 7 f, A0 x1 f) f8 G, j6 d
( d7 u# `. f" S: j
' Perform the query.
' u5 J2 _& S6 iDim results As Item = qryItem.apply() - @2 R, V3 @( u" P; k0 O8 g7 N

7 @5 P- P3 \* V9 {  o( J' Test for an error. 5 u9 D: D+ w2 \( ]# q
If results.isError() Then - K0 O% {1 ]& ~, r1 P1 Z
  Return innovator.newError(results.getErrorDetail()) % @# m) w9 x, |5 |0 B6 F
End If ' r6 x: h& y' @* i
# z6 x# \. A. }' C# f7 q) k
' Get a handle to the BOM Items. 2 z! f9 G- [3 }+ m% j  D5 q
Dim bomItems As Item = results.getRelationships() ' L# m3 g) r' Q8 J" ~
Dim count As Integer = bomItems.getItemCount()
% l7 q& T* F  j; a% CDim i As Integer * ^! u8 E& \9 t! a
; b" y+ M1 \0 q! ]- c0 f( W
' Create the results content. , S/ a) f/ w1 ]' u
Dim content As String = "<table border='1'>" + _
9 F. w, y3 q+ @7 U0 I9 @2 C* V  "<tr>" + _ 4 Q6 e" V2 N! y
    "<td>Part Number</td>" + _
" _% L4 C& Q1 X5 ?    "<td>Description</td>" + _ - A5 v  d2 @: o; Z2 O8 L
    "<td>Cost</td>" + _ # ]4 G  k: [; Y5 r0 Q( H  i- V
    "<td>Quantity</td>" + _
( c2 V# M) u1 o0 a0 E  "</tr>" 2 m9 r; t, X2 E( y3 `7 Q) p( o
' H/ K" ]$ v) x7 D% g( T
' Iterate over the BOM Items
6 P8 N7 g  P# G  JFor i = 0 To count - 1   S4 \0 L0 N: Z, k/ a4 h
' Get a handle to the relationship Item by index. + ]7 o* e( l  D8 g8 V  z
  Dim bom As Item = bomItems.getItemByIndex(i) , b' M; j4 b3 q! a6 c

. g! P3 h7 Y. L, T+ F' Get a handle to the related Item for this relationship Item.
2 L# _" g% }! e/ ]  Dim bomPart As Item = bom.getRelatedItem()
" {# }1 K- F% W+ j9 M3 `8 \: ~ 1 C; }& s* Y5 a+ j* @/ C0 o4 m& N
  content += _ " H" d9 g3 M  r7 Y9 I
    "<tr>" + _
6 s7 X& P7 Q2 L5 Z2 R+ E6 o      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ : n" i* D0 c+ T8 X
      "<td>" + bomPart.getProperty("description") + "</td>" + _
' O6 |( H' q4 H' L0 b. l5 d( L      "<td>" + bomPart.getProperty("cost") + "</td>" + _ + Q. r! m1 N4 A) O' e0 N5 d
      "<td>" + bom.getProperty("quantity") + "</td>" + _ * r7 M1 w4 h# D
    "</tr>"
- ^7 N  Y( Q. TNext * Z# J; F. p9 }
content += "</table>" , x! U: x8 B+ T3 H$ H& i5 H5 T( {

5 ~6 g9 H' @: \% a2 v$ {5 EReturn innovator.newResult(content)
9 S/ L, ?8 @0 u; P- b9 N, M* u& M& q( D; @; i  o) 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二次开发专题模块培训报名开始啦

    我知道了