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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
% j8 m$ v. T8 W& X* B" dTo query for an Item and retrieve its structure you build the query as the structure
9 m& J/ y6 x0 O) q2 a% yyou want returned.  Use the IOM methods to add the relationships you want and # e' H/ E! }4 m4 g( h4 o; Y
build the structure in the Item.  The server will return the structure that follows the
3 G8 i: V& t  d4 y# ~request structure.
" G9 F7 K' l, s9 N- {This recipe illustrates several related concepts together, which are how to get a set
' x: W$ G& B' k+ I" y; y. L" Rof Items from an Item and how to iterate over the set, plus how to get the related 3 n/ l" f! g" W4 P( m
Item from the relationship Item. / n% I, ^" l+ s: r* l5 q
JavaScript  
6 f6 {/ Q! b5 o' |) R5 B; evar innovator = this.newInnovator(); - `+ ^8 G/ d9 b5 P) }  T
( q! |3 t# U; R8 Z
// Set up the query Item.
0 T. X+ k6 l1 V$ g! r9 xvar qryItem = this.newItem("Part","get");
: o9 C3 I0 X! ?qryItem.setAttribute("select","item_number,description,cost");
4 D& V1 f' Y" [qryItem.setID(myId);
4 C8 s1 r0 ?6 @2 J+ t( D) S 5 n6 B% e% p3 T6 K' q* |
// Add the BOM structure.
. d' E" N: @8 g# C, zvar bomItem = this.newItem("Part BOM","get"); $ z6 k7 \5 T4 i  C3 v
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
) m5 v1 l+ v3 N2 j; VqryItem.addRelationship(bomItem);
' @! q) a- ^0 F# P" H ! N1 {1 ?4 C' Z
// Perform the query. 7 r8 H2 ]9 S/ |+ Z, k2 f+ |
var results = qryItem.apply();
6 v( y& U5 |/ l( t- O1 m
  G$ t- I% i( s7 l6 W8 |$ \// Test for an error. & y  Q% g4 r3 J
if (results.isError()) { 6 t) O; F0 z1 U6 ^
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
# N2 M. ~. h" p+ F% H4 [7 ~  return; # [+ l/ Z3 p  |4 a
}
: @1 `" q% H: u. j , F/ G  |* y2 m  C8 c' F9 S
// Get a handle to the BOM Items.
0 T3 c( B0 v3 \2 Q9 r! Bvar bomItems = results.getRelationships(); & ~9 D. H% J" q3 G" ?$ V" E
var count = bomItems.getItemCount();
1 r+ I8 [% W+ s. |
1 a8 p  n  `8 Z; N7 c: P# h// Create the results content.
( E, D3 ]( Q% C9 r+ P: w9 ?var content = "<table border='1'>" + 9 }( O0 \) c; G- ~0 b8 W( H% ]
  "<tr>" + 7 i1 I9 J/ R3 Y; O4 I
    "<td>Part Number</td>" + , W+ ?( Z, e2 o
    "<td>Description</td>" + - I8 j! g! c% `* _. F8 E: _: N0 b
    "<td>Cost</td>" +
' Q1 F' P8 P& p8 x! }; V    "<td>Quantity</td>" + 6 [+ g1 g- f/ Y! |0 P
  "</tr>";
% [' f6 A9 ?# |0 c4 [4 B 4 }# v. Y7 z5 B6 O" u: V
// Iterate over the BOM Items.
8 g/ W) Y4 o" V8 r0 x# X* D& }9 |- mfor (var i=0; i<count; ++i) # C$ ^" D& Q" E! r" s: ?8 M
{
% \2 O+ |- E2 x, u6 p  c// Get a handle to the relationship Item by index. # j& S* A  i4 c
  var bom = bomItems.getItemByIndex(i);   w/ E9 N# S! d: d& u; Z: y  N
// Get a handle to the related Item for this relationship Item. 1 @, n+ A& f6 H# }: q, F1 G
  var bomPart = bom.getRelatedItem(); 8 v2 O8 s( Q% d, @& M7 ^

1 g# ]& Q! d+ W) c- _* J+ a  content += "<tr>" + : `  O% I' `+ P
      "<td>" + bomPart.getProperty("item_number") + "</td>" + # `/ _" u6 |, H/ S, ^4 ?+ [
      "<td>" + bomPart.getProperty("description") + "</td>" + 8 Y9 o0 H8 i: i" f
      "<td>" + bomPart.getProperty("cost") + "</td>" +
" v& E, ?3 U: [      "<td>" + bom.getProperty("quantity") + "</td>" + ) Y3 X) ]2 @6 g, _) x# I
    "</tr>";
' }  b' y$ {/ D) i9 d/ w3 p2 [}
1 {% m1 B* S# H  z* d4 ?+ Qreturn content + "</table>";
0 ^3 m$ f& s. `( m2 Q6 A5 C/ w- ^; A7 F8 a# S
- J9 D0 r6 x& e
& P/ m2 ], F% L0 X1 a' m

# d0 D; y# L0 T) }- mC#  0 U2 D4 V" q! ~- {
Innovator innovator = this.newInnovator(); 6 Z) T1 G  D8 x0 Z& g
' Z8 ?8 D# }% [8 d9 u0 @, H
// Set up the query Item.
1 g7 e8 [# q* Z1 S( qItem qryItem = this.newItem("Part","get"); # F$ u; ]5 v' C6 a
qryItem.setAttribute("select","item_number,description,cost"); 0 ~2 ~/ D' ~% P
qryItem.setID(myId);
# H! n! C8 C: r8 t9 l* J
7 e; `! d! |8 `- W// Add the BOM structure.
* a+ A5 `* {* o  {3 OItem bomItem = this.newItem("Part BOM","get"); $ N# ^& p" G. Q$ ?
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 5 v( q5 ]: h+ c$ M0 _
qryItem.addRelationship(bomItem); ( w: `$ l1 i4 N4 K

3 J( A0 F( i$ i' E# i2 v! t// Perform the query. $ f- R, g  @- [; K* R8 H8 E. g  h8 \! c
Item results = qryItem.apply(); 4 e2 k1 g# y0 x1 S, Q
& F. y8 o, v$ A1 v0 ]$ R
// Test for an error. $ x2 L' K, B. l& {$ Z
if (results.isError()) {
- _3 n- N* Q7 l  y: j3 d3 b% S  return innovator.newError("Item not found: " + results.getErrorDetail()); ! m6 U  |: q' S2 x5 t8 n
}
* |; h) o4 m' A; B% [7 y# v
& \3 m2 Y$ M5 z0 N  V// Get a handle to the BOM Items.
. L4 B) D; s8 ~7 G9 [Item bomItems = results.getRelationships(); 3 `6 v( q& L1 }7 w) M0 |
int count = bomItems.getItemCount();
5 l) K! W6 @9 z1 o8 Dint i;
. F, M* |+ o1 S  M
/ L( d9 U$ W3 F( D+ V3 K// Create the results content.   \% g) M; N9 l5 U  b8 r
string content = "<table border='1'>" + : @# k- s7 O9 U- \1 |2 X  [
  "<tr>" + % I0 v3 \$ D' }% j' F, X" t* V
    "<td>Part Number</td>" + ( d- b! j& X3 [5 F' R5 ]
    "<td>Description</td>" +
5 ^4 c, e$ L! v; m    "<td>Cost</td>" + 8 e% X, E  F) ~. l! K# c. l+ Y
    "<td>Quantity</td>" + 2 J3 A+ C9 X( R4 M" k4 w8 F' h0 ]
  "</tr>";
# }, W  Q6 S0 v% Z- Y& V( C9 y ; l7 K  ], ]8 y
// Iterate over the BOM Items. 7 _, {2 W( u7 D' c
for (i=0; i<count; ++i)
. t0 Y( S' Z, D5 o{ 2 e8 [  t9 l/ n% q" Q+ V% C( W5 Y8 K% K  T
// Get a handle to the relationship Item by index.
( l& h! O5 e( P& `5 L9 ^  Item bom = bomItems.getItemByIndex(i);
9 U& v9 L# V0 v9 u: n' G$ O// Get a handle to the related Item for this relationship Item.
* [, Z: F4 b* V* e  P  Item bomPart = bom.getRelatedItem();   C1 r7 \$ L/ N8 c5 f8 m

! q- n& g: ^1 G% @+ @9 l% _& G- C  content += "" +
8 K* t0 A& W6 A  c' b    "<tr>" +
0 ^3 Z7 o. N8 G' \3 [4 ]$ G3 C      "<td>" + bomPart.getProperty("item_number") + "</td>" +
7 p1 J4 B8 J" Z  q1 L      "<td>" + bomPart.getProperty("description") + "</td>" + 2 b. g) a$ E4 P, P! O9 q% n' G4 {
      "<td>" + bomPart.getProperty("cost") + "</td>" + * D& o8 K/ q" ~  V2 ^! y
      "<td>" + bom.getProperty("quantity") + "</td>" +
% B8 h$ f7 q# D5 y$ T' m4 l    "</tr>"; * t7 y8 m! F7 ~. n# u4 |# o
} - N7 |6 P$ i9 \% C
content += "</table>";
( D* R. e  @' \0 W# q7 z" J
9 G% x+ u: W  |: G2 yreturn innovator.newResult(content);
9 d7 @/ q$ D& p; g) x4 d: i- v. L" q! {0 }5 U
) h2 ]' ~( s4 E  O0 _# Q- _
4 E& e. a$ u; @! y- h( ~( T

8 R, I' X* Z1 X- G
( Y( K: m. d; s' c

# x# Y+ \* b0 D/ m. c3 j 9 |5 G% ]1 W; x+ M# x8 j
    Page 46
! ~; B5 K' q" Z9 _% w
: j8 v1 ]& \; yCopyright   2007
& V9 h! }& L; bAras Corporation.  
% s& x' D) G$ h4 o. pAll Rights Reserved.
) W6 B2 w* W! K  k' Q6 r$ eVB.Net  $ i3 K6 r  _8 }2 O4 w5 a+ j% n
Dim innovator As Innovator = Me.newInnovator()   h8 T; M, _/ O3 ?# |: N

2 T; e% S2 D9 s! I$ V6 N: z' Set up the query Item.
" i/ M6 T+ c$ o3 g/ wDim qryItem As Item = Me.newItem("Part","get") 0 z0 |  X& _+ C/ J% N; _
qryItem.setAttribute("select","item_number,description,cost")
+ P$ ]2 H* M+ dqryItem.setID(myId)
0 [. |) U! u, j8 | . a8 f7 M* D" B- K  q4 a
' Add the BOM structure.
  a! T9 y, t3 Q' s1 {4 cDim bomItem As Item = Me.newItem("Part BOM","get")
$ @. i4 ?5 M: H, zbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") % r+ e1 g2 z2 @. x
qryItem.addRelationship(bomItem) ! D+ F* ]7 s5 `- l6 d$ D
- Q7 V6 E4 @# j: J! j3 U
' Perform the query. $ o4 I0 ^# m* c. q9 I! i
Dim results As Item = qryItem.apply()
* @# ]4 a6 o  x3 D2 q8 }. K( n 2 V; x/ B7 d" t9 [
' Test for an error.
6 \- N2 Z+ P9 q9 @+ mIf results.isError() Then
' ]8 a# O* b$ d' q# k  Return innovator.newError(results.getErrorDetail()) 3 O6 f% f+ y2 I4 [6 e4 {9 t* s
End If # F. r# {% D7 K9 z9 s# ?
  ^: k) f% ~7 p+ G# D& Q
' Get a handle to the BOM Items. 8 t) [# P2 v+ a! _
Dim bomItems As Item = results.getRelationships() : m, D4 U$ N! I# r/ O7 j" H
Dim count As Integer = bomItems.getItemCount() ( J+ Q4 i) ^2 V3 ~1 D; [/ E  O
Dim i As Integer
; Y5 a4 n8 c' K- @3 K4 c1 t
8 W$ C: F$ o% W% g+ W. ?1 A/ u$ m  A' Create the results content. / H0 {; Q3 \0 x+ S* V
Dim content As String = "<table border='1'>" + _ * q' E5 q" \- V; g
  "<tr>" + _
# J% p$ D% R: Y& _( e2 a/ p+ I    "<td>Part Number</td>" + _
' @8 w& L$ U+ ^7 g    "<td>Description</td>" + _ + [5 E( t/ Q  p7 H: \3 p+ L; r
    "<td>Cost</td>" + _
3 c$ |4 o# N( h8 j$ U    "<td>Quantity</td>" + _
2 ~$ V* F' n2 e) v  "</tr>"
2 X: r# N3 y  N3 U6 O  L * H: F/ K$ j: P: V! U
' Iterate over the BOM Items 5 D$ r/ e! }/ p2 d1 ?
For i = 0 To count - 1 / y7 T. ?2 |& h: c6 ^
' Get a handle to the relationship Item by index. ; r: w& W& C; V: Y! e7 K
  Dim bom As Item = bomItems.getItemByIndex(i) , w# X+ x2 Z6 j

  I. {; L2 \+ m( |3 y$ w* }' Get a handle to the related Item for this relationship Item.
( \3 O: n+ l" m1 T8 L  Dim bomPart As Item = bom.getRelatedItem() $ ]4 I  C3 C2 `

) Q9 A' }2 D, p" a  content += _ 5 U: P$ x' x$ X$ a% R% `0 d) Z& ~
    "<tr>" + _ - O- M. K# y6 ]3 d. M
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ( m/ M/ W/ Y9 a. p( c
      "<td>" + bomPart.getProperty("description") + "</td>" + _ * ?: t; d- P1 [( P0 A* r. l1 u
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ % d) \4 D* t* h/ `' n1 w7 @# S0 n
      "<td>" + bom.getProperty("quantity") + "</td>" + _ & r$ m/ [- ^/ N; a
    "</tr>"
4 p0 K" f* z" v) H: i9 o, _9 QNext
7 O  J* f0 _2 Q1 m+ tcontent += "</table>" 8 a. ~; h- y; ?% c& U* @
/ w7 O) C6 U& x; S, O0 A
Return innovator.newResult(content) 1 M/ h: @6 \' ~9 ?1 g. ~8 R
' p3 V* y: H% L* l+ @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了