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

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

[复制链接]

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

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

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

x
Technique  
" o" Z7 l. r; _To query for an Item and retrieve its structure you build the query as the structure % _/ Z: F7 d; ]3 t
you want returned.  Use the IOM methods to add the relationships you want and
: [. N, ^* B5 U3 c5 J, S! Bbuild the structure in the Item.  The server will return the structure that follows the 3 d2 r9 b5 H  g% d, M8 V9 M. g
request structure.   b5 w0 V, B  |- M
This recipe illustrates several related concepts together, which are how to get a set
, T: Y3 f8 y' Aof Items from an Item and how to iterate over the set, plus how to get the related
, K  |5 N% p  a0 z9 L9 fItem from the relationship Item.
6 F+ g. {3 W* z, \7 c/ b9 YJavaScript  8 _9 {. [+ f5 D5 y% Z; `
var innovator = this.newInnovator(); 5 I5 c# Z8 e' v% O+ [' T* e
6 D$ v% O4 i& I6 z$ C# U1 W
// Set up the query Item. 0 L7 [0 K' b5 d1 C% X7 A' q
var qryItem = this.newItem("Part","get");
* O- C% i: ~: m1 \4 I2 X6 g  b; ?* RqryItem.setAttribute("select","item_number,description,cost"); 3 z3 e! x. @2 G/ y- [6 p4 c/ A3 O! \
qryItem.setID(myId);
: W  |+ L, a, i$ q, G) ]. s- D " \- U% E1 s+ q6 t0 E6 M
// Add the BOM structure. " Y; f% k0 _& c8 b# k. B
var bomItem = this.newItem("Part BOM","get");
" ^$ E; Q7 @% d. _/ ~8 @bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
0 X0 a) }+ C, v- |qryItem.addRelationship(bomItem);
1 C" f! r$ G  n. h; t$ m4 i
/ e9 `5 p9 c8 r! D' Z5 x// Perform the query.
8 [  g9 D. }  ~var results = qryItem.apply(); 3 Q8 ]# l% w% _1 O, e! p
9 y" j* T% M3 M# i2 O' ~
// Test for an error.
, [7 [4 ~' b# |* xif (results.isError()) {
  Q% e8 a1 m" m% G; y  top.aras.AlertError("Item not found: " + results.getErrorDetail()); ) w6 ^1 P: c# ?6 X# l( T! W7 `
  return;
' n" x5 j* @( |* w# I}
# A; B$ k+ |/ W- N * u. J' A! z8 Y) ~/ G
// Get a handle to the BOM Items.
! Q, D) }  }+ L8 W3 R# v5 Evar bomItems = results.getRelationships(); 1 N5 m& l& v  |1 y; i$ ]: H
var count = bomItems.getItemCount();
( l( m* V& Y' Y 8 T7 c1 F1 T$ O( W) j8 b; n! z. D
// Create the results content. * _7 j+ e& Y& {" [  }8 a" {8 }6 o. a
var content = "<table border='1'>" + ' E" o0 _5 `& U* N- L$ m0 y
  "<tr>" +
5 m3 g+ |: a- Y. [4 c, i    "<td>Part Number</td>" + , X9 p7 [& U0 B: G3 T
    "<td>Description</td>" +
4 w- Q* k; s. p+ B    "<td>Cost</td>" +
% d8 G" J  v: O5 u' N0 r* H% I    "<td>Quantity</td>" + : Q, Z. E/ m- M+ u. i4 [8 g
  "</tr>";
/ B. ]! P7 L7 m$ y . ~8 B9 C5 G0 n( i, L2 `3 ^+ w
// Iterate over the BOM Items.
0 C9 n' m0 M+ h/ ~  J) \for (var i=0; i<count; ++i) 8 M1 ?: D* J3 g& u3 S$ p7 `2 l+ Q+ Y# D( x
{ 9 ]& [( f; s+ E' d/ E& |! N
// Get a handle to the relationship Item by index. ; }6 L! O% ?/ `8 G# O! |- C
  var bom = bomItems.getItemByIndex(i);
8 x3 W. b8 }0 z// Get a handle to the related Item for this relationship Item.
1 u, P* [# t( E  var bomPart = bom.getRelatedItem();
3 ]. m- j# V1 r2 A6 y
$ E1 Q% C% L7 F5 N+ E9 n' d  content += "<tr>" + + L. K! {. C' D& K& Q
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
8 O# f: K5 I: W0 x# D      "<td>" + bomPart.getProperty("description") + "</td>" + 5 i& n" b& F8 i# C' }* m
      "<td>" + bomPart.getProperty("cost") + "</td>" +
: i  k% f1 h' Y  D5 c$ v      "<td>" + bom.getProperty("quantity") + "</td>" +   D) k( `0 f9 @
    "</tr>"; ( \+ ^8 P! j2 w7 }. o* w
} 6 u/ H9 A  g7 H
return content + "</table>";
& e3 y: d, a& m3 a6 N4 t7 b
+ U" L/ @4 Q7 N, I1 g
# S5 _- t( f% T# l
2 l( j" o# L0 V. s4 e, n3 j" @
- q9 ^, D+ j; p) e, ]* G
C#  # q- V" |; G- v0 U# P' ~# C
Innovator innovator = this.newInnovator();
2 n# b* m4 G" v' n' s9 T " c, @% s" v% k0 r
// Set up the query Item. : q/ V/ q  P; D8 N1 u1 Z0 |1 x
Item qryItem = this.newItem("Part","get"); $ U" _" W; j) w
qryItem.setAttribute("select","item_number,description,cost"); 4 c" k( `1 y6 m% V# s7 G
qryItem.setID(myId);
0 V3 L1 I# N: e8 @# ]% G7 Z" N  Y 9 _' J9 J' k: {! N2 I& F
// Add the BOM structure. # {# c3 L. H6 G
Item bomItem = this.newItem("Part BOM","get"); 4 `- }. N8 o5 C7 K; g3 X) ]
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 2 |' `) B% K' e$ Y
qryItem.addRelationship(bomItem);
# n+ c) A, x( a! C! n6 U/ u4 f# f 5 A0 M: R, \% R1 Q
// Perform the query.
' E5 F! P: v8 c  y" j. u% bItem results = qryItem.apply(); - |3 `6 w1 D( Y; _1 S/ U! r

. F- ^: \  l) |9 B4 ]0 X- Z: L0 R// Test for an error. " M4 P$ a, ~0 }; k- P/ l4 i
if (results.isError()) {
# q9 l4 t* g- D) D& ?  G/ l  return innovator.newError("Item not found: " + results.getErrorDetail()); - k2 W4 F4 ^* d* g7 z/ M( a* I2 `
} - o8 x( x4 Q) G4 \4 {/ @" L: f1 N

$ S5 M$ @  u# H$ w// Get a handle to the BOM Items. . L4 D# `( k' a+ [/ Y
Item bomItems = results.getRelationships(); ( `0 h0 N3 T/ Z
int count = bomItems.getItemCount(); * @2 z; D' M' u7 R% O, m) n) I$ t
int i; ) o+ }( R( t9 _7 [7 ~

  h" i9 A- F- w$ _$ O# @// Create the results content.
' N  k9 H4 a- q) a* Lstring content = "<table border='1'>" +
  j, N9 J  m7 E2 Z/ K/ {: }  }1 K  "<tr>" + / ~) v& o0 J( _" s$ Q1 U' h" `8 a
    "<td>Part Number</td>" +
) h  c+ P, [: [/ `, c6 m; }) H    "<td>Description</td>" +
0 F% a& D; @- B% ~% O  }8 y4 h    "<td>Cost</td>" + 4 }3 U' W4 ]8 O
    "<td>Quantity</td>" +
5 f2 D* {! ~( X9 i" l  "</tr>"; ( s6 u% b' J* @6 E  d$ k1 N
+ K, f4 m: Z* ^* ~6 O5 v2 n
// Iterate over the BOM Items.
6 S4 w2 B+ ]/ P# w, h$ w7 E) Hfor (i=0; i<count; ++i)
9 i3 }4 [9 G- F! q3 w  A$ z( {{
) w9 D5 L# n: s4 m) F# r# ~/ E// Get a handle to the relationship Item by index. ( F/ d3 ~4 X, V& X
  Item bom = bomItems.getItemByIndex(i); 2 ^6 B0 H) Y+ B* A- H" ^
// Get a handle to the related Item for this relationship Item. % m. C" ]; c3 Y/ O$ o5 o' m
  Item bomPart = bom.getRelatedItem(); 8 L$ Y& G: n1 h6 e
* q( N7 J0 V+ A
  content += "" +
4 b+ S1 D" U& Q  l* U9 i    "<tr>" +
8 f. l& j9 N4 T0 \2 K, I1 }      "<td>" + bomPart.getProperty("item_number") + "</td>" + 0 J' f7 P2 _+ W: ]
      "<td>" + bomPart.getProperty("description") + "</td>" +
2 d6 p" T6 D1 a) q4 X; c# Z      "<td>" + bomPart.getProperty("cost") + "</td>" + & h4 M5 L7 _" n4 j
      "<td>" + bom.getProperty("quantity") + "</td>" + 3 X( P3 a! o; S) v: ?8 N: Y
    "</tr>";
$ g- i& p1 n, B+ q} 6 _/ a9 S2 x0 a: D; Y, Z
content += "</table>"; % }3 T& C) W3 Y4 n' n- a' C
' a% P  y  g5 w/ M& r4 _+ `6 _0 K
return innovator.newResult(content);
0 Y. Z) e+ C0 i+ {; U; Z( ]* m5 R, _- d, q

4 P( t8 f" E5 z+ Z7 a3 a& D) _' n2 J- K/ y- E" p

- ]- e6 I) u/ c# b6 |0 {6 S& K5 d9 t' S) R' V; \5 A
# l! Z3 _! B, K6 K
5 @% z2 C3 N' q1 X7 D! ^: F5 U
    Page 46 * `& A2 f5 L3 }/ a% j, `) M# y- x

; ~. {+ ~0 n8 n; i/ F9 l2 _0 [( HCopyright   2007
, b8 ?/ I1 H- m4 }7 ~Aras Corporation.  ! G+ i" J  U- {# q
All Rights Reserved. . z( }8 g; p' L1 V
VB.Net  3 U8 @4 o5 k; c3 p/ i
Dim innovator As Innovator = Me.newInnovator() 0 V% M/ L3 N$ `0 Y+ x
- s) h, X3 W2 A- t' |4 T# Q
' Set up the query Item.
' \+ T9 k+ ^, hDim qryItem As Item = Me.newItem("Part","get") 4 F+ E9 y- V9 D- L
qryItem.setAttribute("select","item_number,description,cost")
* m' A) t/ B* l$ S- A# H0 ?" tqryItem.setID(myId)   G' W+ `" C! U/ B2 ]9 _! l0 a# S

5 x" |* g" W) d! v3 P* i' Add the BOM structure.
0 {: s& q4 v. s9 w  G1 ^Dim bomItem As Item = Me.newItem("Part BOM","get") " `! M" h% e) s* e* _, c: W& x  g
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
. p5 |* l$ Y: wqryItem.addRelationship(bomItem) 2 _( P+ X, m) p

1 n: `8 h5 d# z6 a' Perform the query.
/ H. F  Y% x7 g& h& FDim results As Item = qryItem.apply()
6 Y$ b- H7 C4 A2 S; d/ q
: [- d8 T: L/ ~- T' R  K' Test for an error. & S5 n- @( X' S" @
If results.isError() Then
  s& ~! J' g5 F  Return innovator.newError(results.getErrorDetail())
1 l, F! R( Z+ D3 JEnd If
& o, i9 ~! H9 r1 H6 k( g
; ^" N0 Q" Q2 q. u/ ^' Get a handle to the BOM Items. 2 H+ U" W* f+ |4 L- y" t
Dim bomItems As Item = results.getRelationships()
8 n& p% K: H3 U) eDim count As Integer = bomItems.getItemCount() ! _( a2 _" @: e- j- }
Dim i As Integer
0 |; C7 R2 s: c& n7 n' C+ h
8 W. ~  e8 g; x' Create the results content. 3 s' N8 {- B! G- W% b# }: X
Dim content As String = "<table border='1'>" + _
; h$ a3 @' M- j8 |' b9 k; x  "<tr>" + _ 2 A3 |6 g* m$ g/ P
    "<td>Part Number</td>" + _ ( c. b, o: U8 d$ \, l' D& g
    "<td>Description</td>" + _ # s8 n& U* G) P) l5 G
    "<td>Cost</td>" + _ $ o3 P7 T8 M. C3 f, ~, D" s  O; u
    "<td>Quantity</td>" + _
5 q4 E9 R, A8 s4 Q% f! A  "</tr>" + b$ x4 T  z8 E4 B2 t
" w  d% T6 ]7 I
' Iterate over the BOM Items
; N& q% A# i9 Z$ L% bFor i = 0 To count - 1 . T5 q6 H) w# ^; F$ L& [
' Get a handle to the relationship Item by index. * P9 [; k0 d  ^/ j+ v  d
  Dim bom As Item = bomItems.getItemByIndex(i) 3 q  v- {. d, L* K" \, W& V5 t. Q. x
* y  Z  y; b+ H2 o: p
' Get a handle to the related Item for this relationship Item.
, t3 |7 v5 ]4 f  Dim bomPart As Item = bom.getRelatedItem()
3 E# w/ b0 f" {; X  O" q1 _6 r  n
2 b4 ^. k/ E6 t$ n0 V  content += _ - \) n( z% l; Z' d6 j0 `5 j
    "<tr>" + _ : K; k% K# k6 |5 q' V, |5 I
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
9 K2 a* P4 |6 |$ y9 G+ H, a      "<td>" + bomPart.getProperty("description") + "</td>" + _
) A- X- r4 o  r: ^+ K2 I9 G; }      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 4 u% e3 _8 E( S1 i. S/ b! Q% @) q
      "<td>" + bom.getProperty("quantity") + "</td>" + _
' z8 F- `1 `$ T' N2 u. A    "</tr>" ( u/ [0 _, P' u& R: ?5 V5 A
Next 7 Q& o1 l7 u9 E9 d3 N  j
content += "</table>" " n& m2 Z8 {* W* a/ o7 T5 S
" o) I/ J* N/ @8 N- d& _9 Z9 i
Return innovator.newResult(content)
9 }  g- _2 A9 e  O3 g$ ?( \' p
3 U% u* C) Q  ~" |+ ]! n
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了