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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  ) G' f( b$ G; ]6 D
To query for an Item and retrieve its structure you build the query as the structure
# E: d- \7 [9 ]* u! o8 i0 yyou want returned.  Use the IOM methods to add the relationships you want and # }- q6 F" U' G# V8 R( s; C. `
build the structure in the Item.  The server will return the structure that follows the 1 k3 g' M: h- T+ M$ S2 A
request structure.
, }) i9 W) P- OThis recipe illustrates several related concepts together, which are how to get a set
0 x% j% l; `" v) \; m% Sof Items from an Item and how to iterate over the set, plus how to get the related ' I" M$ ^- R# n! S0 d( W& z
Item from the relationship Item. ; y2 K- P( _6 \
JavaScript  % ?) k8 v3 ?, R! a8 V6 A
var innovator = this.newInnovator();
* k& N, p" i+ s6 \4 J! S* O( D6 ?$ Z ' O8 D' K" g; O& d5 ^
// Set up the query Item. 6 U& [: \. b' X  k/ z
var qryItem = this.newItem("Part","get");
1 o9 x7 q/ `3 k; y9 T+ B. ?6 ]( bqryItem.setAttribute("select","item_number,description,cost"); 2 s) u. o# z" \8 Z( t- z
qryItem.setID(myId);
- F3 Y! t" k6 E/ \5 n  Z 3 d! {( V. j% {; ~+ b
// Add the BOM structure.   ~) D6 |( R  d* h& w8 I
var bomItem = this.newItem("Part BOM","get");
" D6 N1 ~, W- t, P' O# w3 HbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); , M# _, |; w# S/ y. q
qryItem.addRelationship(bomItem); % a* z% \0 C  Q" \9 c
* s1 M3 p/ ~2 N; ?
// Perform the query. ; z2 @8 X5 `: I" k' L
var results = qryItem.apply(); ( {  w9 E( J) \* H
  o* q% R1 C4 t* r
// Test for an error. 6 D7 d0 h$ Y/ G3 u. }: R+ Y: B3 z
if (results.isError()) { ) v: I9 d3 e. _$ a. |0 B
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
2 M! w7 p7 o: J# N6 P& y  return; - P( \& S4 P4 k5 W* `9 ]! v
}
) z: A$ X2 P; h
- H4 M6 u6 j' D6 ^& v. W// Get a handle to the BOM Items. / Z4 ^0 U, s( z. c/ |: b2 e
var bomItems = results.getRelationships(); 0 V# `# J6 R" z: J, _5 K3 J
var count = bomItems.getItemCount();
; A3 T& ^. K* X2 L
: b9 g) e4 l$ E" ^// Create the results content. 6 W; w# b4 W" L- `, y0 X* X& ?8 W
var content = "<table border='1'>" + # ^7 I% g1 w& Y5 z, V( \$ ?
  "<tr>" +
2 x& ?0 }% ~4 a) R8 ?    "<td>Part Number</td>" +
9 ^" ~6 n" ^0 v: `' L" x0 ]' x    "<td>Description</td>" + 9 c% T9 a# P2 E7 V9 \& _! b8 j
    "<td>Cost</td>" + " T% n- d7 ]; ?5 j- g8 a
    "<td>Quantity</td>" +
6 ^( ~5 W( B' E; y# v  "</tr>";
' A( b3 K5 K' z6 a   A* p! `' y* f: S3 \+ n
// Iterate over the BOM Items. 7 `) y; c9 T2 b7 ]0 |$ K. v+ y
for (var i=0; i<count; ++i) ; O( u- E5 h- z+ K
{ * h/ [- P0 s) i/ c
// Get a handle to the relationship Item by index. . g" W/ O* c3 t% Q
  var bom = bomItems.getItemByIndex(i); * d, l1 g' a1 P& {) o
// Get a handle to the related Item for this relationship Item.
5 X( L7 ]! p/ Q- ~/ a$ f8 \4 D& O  var bomPart = bom.getRelatedItem();
# `3 j, g. W2 q' U# C  W
0 A7 p4 z9 |# l. f, K3 w  content += "<tr>" +
* E) r( x& t6 b3 I# a, b. Z7 C) ?      "<td>" + bomPart.getProperty("item_number") + "</td>" +
" M/ n) A1 {' `5 }; V( f      "<td>" + bomPart.getProperty("description") + "</td>" + ( B- x" \5 U4 Z0 D: S
      "<td>" + bomPart.getProperty("cost") + "</td>" +
( r- P* J) R6 V0 g: y) L. j) N      "<td>" + bom.getProperty("quantity") + "</td>" + ' e( R" H: U) X7 e7 {
    "</tr>";
+ J- A* V9 Z  w2 Z/ p. l" i- \" K, i}
, ~4 o7 n  W" c1 creturn content + "</table>";) p/ z, V3 G8 K: v2 L9 w; D- @0 Y

, o0 S2 l; g7 O4 X6 {

( k5 T3 }) ^. ?. f+ F' R% m9 n1 `9 Q. J
* [) P& |" a: x1 K8 ?1 ~" g' {  j
C#  
) F" f, o% D$ v0 E8 ^# C" |Innovator innovator = this.newInnovator();
* L. _' u& i, o( x! C6 o / M7 }/ k, Z; A1 y% L
// Set up the query Item.
  _* E/ ?7 _2 G; a1 R# G6 W; mItem qryItem = this.newItem("Part","get"); 8 `2 r+ q2 o5 c$ q0 w( B
qryItem.setAttribute("select","item_number,description,cost");
) y: g! _% r9 ~: i4 S/ `. N6 S% b0 C; yqryItem.setID(myId); ! _: }, b, |9 W

" H# e1 p9 |2 s7 K7 g// Add the BOM structure.
. Y$ D* D0 e# p' B' P- u% n+ W9 ^0 aItem bomItem = this.newItem("Part BOM","get"); ! @* K7 i& O) O: v, e* _
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 4 `3 b4 j, h% M! [1 k
qryItem.addRelationship(bomItem); 9 U0 I- _; j2 R+ ?. b- J3 s' u6 q' [

7 u5 X; l" I/ B1 i2 X// Perform the query. 1 x6 j- A! H4 s, D: i
Item results = qryItem.apply();
+ z& K8 }7 o( F$ W 5 }  W4 B8 b* G
// Test for an error.
4 _+ W1 x( k& F. U- hif (results.isError()) {
. p3 k% S$ U7 o  o. Z  return innovator.newError("Item not found: " + results.getErrorDetail());
# I; \( k, C, A, f}
" d* M. t" D8 `9 E; _6 W : `2 H: L, B7 B" ^
// Get a handle to the BOM Items.
: m* H  R0 S. iItem bomItems = results.getRelationships();
5 j+ w+ Y9 N" J8 W# ~. Vint count = bomItems.getItemCount(); 0 q5 v$ Z- Y9 T1 `: K# c
int i; ' M/ ~! `; E& A5 N+ l, B
% q+ j9 Y+ n; ~$ U2 E
// Create the results content.
9 J: L0 l' t( wstring content = "<table border='1'>" +
8 D. q4 Q0 j: G* I! H; V) W8 C6 L  "<tr>" + ) j; |& r) V+ v5 E
    "<td>Part Number</td>" + + m& X2 T/ _. W2 H" Z
    "<td>Description</td>" + 9 }& B2 w  M. o2 h! h# @
    "<td>Cost</td>" +
- A* i, J2 w- ~8 F    "<td>Quantity</td>" +
1 g2 @7 z' a6 P1 N+ [7 k9 v  "</tr>"; 7 y9 N7 j. m6 p7 o7 G7 I

  z8 z/ ?, }% @4 s1 J0 _/ j// Iterate over the BOM Items.
3 s$ H: |$ S; S' a) }for (i=0; i<count; ++i) # }& \+ D& P; q8 Y4 v1 C
{
% l% J. c& ]7 S3 s# R6 l1 G// Get a handle to the relationship Item by index. * U" U' L. D$ I. f) T& _
  Item bom = bomItems.getItemByIndex(i); 3 ]/ Q7 K# p* Q. z+ }% `
// Get a handle to the related Item for this relationship Item.
) F, I" k% S: i1 C1 j" ]  Item bomPart = bom.getRelatedItem(); " x8 ^/ p" G7 L6 B6 }/ `# q
7 O1 ?. u) \' ]" I1 s3 ?9 a
  content += "" + 3 \; K3 r$ ~: i: @1 R5 {1 Q
    "<tr>" +   [) N( {5 @7 u, {* r
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
* h* q& s9 o4 _- Y* g+ U+ I      "<td>" + bomPart.getProperty("description") + "</td>" +
" G* {4 g6 h" w- P      "<td>" + bomPart.getProperty("cost") + "</td>" +
7 U: x! `7 C/ G0 v' t      "<td>" + bom.getProperty("quantity") + "</td>" +
" `8 U+ I" e+ T. i* T) D    "</tr>"; + Y8 l3 N0 m) C' R, Q
}
  r- w& y' s8 o  H7 dcontent += "</table>";
' p+ a, b; K- [3 n 2 K3 i7 C- k4 U5 N1 m; w( s- W
return innovator.newResult(content);
0 t8 h* z8 Q8 i: x3 l* ?. A
8 c$ d  b; \+ r# f

% U1 w; X9 h/ ~4 ~" ]) i6 l8 t4 I
3 O2 `& ^$ [% x+ M
, J. q) `+ f% D5 S8 S1 c. k
. ~& H7 R8 j2 l; N- f

3 e: c6 d* H$ ?    Page 46 ' B( ]# G1 I& r. n& e6 C( q. Q

' H+ t' y+ U1 O) H" wCopyright   2007 & [- z7 U1 W6 X7 d+ x4 v: T
Aras Corporation.  " H) q' F* T, @' X4 V+ n: ^
All Rights Reserved.
3 c( a: E: m! Q' Z* {9 ZVB.Net  
( c4 z# [+ W8 s, _4 ?1 E* U) ZDim innovator As Innovator = Me.newInnovator() , t9 c6 p& w6 m1 v6 Y+ w( r, Y
4 z% n5 e1 A% q; `) H7 x
' Set up the query Item.
/ F# R3 X7 G  E# yDim qryItem As Item = Me.newItem("Part","get") - t# J: R, n* f; f5 U, Y5 Q
qryItem.setAttribute("select","item_number,description,cost")
* T" a6 X1 q5 rqryItem.setID(myId)
2 o3 |* Q% D  M4 k0 G* G 5 f( o7 @6 f5 v, X1 p7 D- y( y
' Add the BOM structure.
/ S  U5 y1 S6 Q- {1 l- [Dim bomItem As Item = Me.newItem("Part BOM","get")
& W0 _7 r9 h$ v/ L/ CbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! |, K. ~; d4 R( @; NqryItem.addRelationship(bomItem)
3 N/ X+ D# f- V- c7 w, Q 3 L2 |' T% M- [+ X7 _  X6 _  P
' Perform the query.
# w1 j; ?  O+ g6 b7 n; B# C; KDim results As Item = qryItem.apply()
* [4 N3 ]6 M+ Y
! b( p9 L( S2 P7 f# C/ D' Test for an error.
! W1 w4 `: T+ e* G) A/ ?% d& \If results.isError() Then # J* \% ]  u0 L; O- X! u9 s- _$ T
  Return innovator.newError(results.getErrorDetail())
5 U# k; X$ B8 \& [- D) u  A( GEnd If
5 {* B3 Y5 n3 V$ g) ^ + m  k! M, L; s# m
' Get a handle to the BOM Items. - f. X) B+ V6 K5 N4 q, x
Dim bomItems As Item = results.getRelationships() 3 N& U* x. X1 f- k! `  ?3 R
Dim count As Integer = bomItems.getItemCount() , f# w* C8 h2 `$ u3 g3 x0 }# z7 W. g& i
Dim i As Integer
8 D3 W2 C- \0 C4 H' } + ]8 s1 m+ F, I# a3 ?
' Create the results content. 4 b# z$ a( [' L
Dim content As String = "<table border='1'>" + _ 3 Q' L5 H/ d6 C3 E6 ]0 n, J; G: q
  "<tr>" + _ - ~2 V: H; ~" W7 L
    "<td>Part Number</td>" + _
) s% d& j$ ?* Q% K    "<td>Description</td>" + _
; r% h! I/ g9 s7 W& w6 n  j    "<td>Cost</td>" + _
  x" z$ Z& R9 o: G    "<td>Quantity</td>" + _ , \9 c8 R% p" u# c. A8 F- I2 j" h
  "</tr>" ) T$ Y1 Z: s$ f2 |1 M3 A

' W" L& P: w; `- z% F- ]/ u  @! w' Iterate over the BOM Items 5 V8 \7 w( s6 j7 |
For i = 0 To count - 1
" o, W* j. s" c, U5 t8 E' Get a handle to the relationship Item by index. ; o: k3 B! |4 d
  Dim bom As Item = bomItems.getItemByIndex(i) 6 I- t, l( {* V% _5 D
% l2 {' k$ d* k- z) g% a( U
' Get a handle to the related Item for this relationship Item.
( j4 X* v& |! D- u8 }  Dim bomPart As Item = bom.getRelatedItem() # s8 [( t: ^  L) H4 e4 y, s

1 u' s- X9 S& i& z( v; p0 ~* h  content += _ # Z" R3 w" P" h  m. Q" q
    "<tr>" + _ # P: e4 I; e4 a+ t
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
7 U2 w2 M# m- D      "<td>" + bomPart.getProperty("description") + "</td>" + _
( V; \; p- Z1 E+ E: ]      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 6 e3 b1 F% Y2 |+ t- _
      "<td>" + bom.getProperty("quantity") + "</td>" + _ 5 V) J$ l" W. a5 H5 S, i
    "</tr>"
. u; Y7 K# T* a. h/ k9 XNext / S0 m$ P- c& T" Z7 c1 n
content += "</table>"
, h: y  D; s/ }# s3 l" d/ g) A) Q& v6 ^ - r* `1 H& F: w* X
Return innovator.newResult(content)
1 W* L/ g8 i$ k/ |4 M% ~, Q& L+ a* c) Q) c
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了