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

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

[复制链接]

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

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

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

x
Technique  - q& f) O3 e# Z
To query for an Item and retrieve its structure you build the query as the structure
5 O2 i- q$ o( }0 Q- Oyou want returned.  Use the IOM methods to add the relationships you want and
" U! O. g: |* a1 ^build the structure in the Item.  The server will return the structure that follows the
' A$ ^) F) v2 Krequest structure.
; a  e# {4 c% |/ @This recipe illustrates several related concepts together, which are how to get a set
% q& `9 g4 t; ?( Kof Items from an Item and how to iterate over the set, plus how to get the related
7 z% M# a& I4 s, V7 s( \2 o5 T9 E0 LItem from the relationship Item. 9 }0 L. q) l) S3 U
JavaScript  1 ^9 c+ o4 G, R+ A* y# n
var innovator = this.newInnovator();   j2 s2 ]9 I4 c

4 K9 ^3 S2 V, c( ?  u7 [+ C( c, |& B, {// Set up the query Item. 3 O* ~/ p5 O+ @$ q) w/ x- r3 F
var qryItem = this.newItem("Part","get");
% M" |4 Q! O) z+ n" }qryItem.setAttribute("select","item_number,description,cost"); " o9 B1 b2 u: p
qryItem.setID(myId); / |( P9 `7 U- }' f6 j

' j0 C/ k# y6 e2 x// Add the BOM structure. 9 X6 }6 S) p  Q+ n1 T$ r
var bomItem = this.newItem("Part BOM","get"); ; G; \0 Y. E$ u( c; F
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
. A# a# z* D' I$ w3 i% \" \8 T6 AqryItem.addRelationship(bomItem); ) |* j, J7 q8 i: R' J* ~. V
' B0 f9 O  k  J8 U2 t7 H
// Perform the query.
6 E- W7 A5 P7 q$ L2 Qvar results = qryItem.apply();
) g8 d- c' N0 z3 ^) n& T  ^& C! F 3 p" i; B1 r) z. {
// Test for an error.
6 [: G4 C/ X& h: [% R2 ?if (results.isError()) { ' q9 Y/ Y; h9 s8 ~0 P! ^
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); % c' `. j$ _5 ^1 a( I
  return;
" K/ O7 n. {5 k}
1 D- _, [: H3 {: V: \ ' n" L- L& ?& \& z$ p
// Get a handle to the BOM Items. # X# U0 ~6 k7 n7 n
var bomItems = results.getRelationships();
9 L7 P, Z7 T9 p9 t+ u+ m8 \4 {var count = bomItems.getItemCount(); ) I! p" p0 T( g5 }2 {1 f. n

1 h# u. I0 \3 V+ {9 d$ e// Create the results content.
9 q' Z9 [1 |! g  |, p! jvar content = "<table border='1'>" + + m5 ~8 B1 [( u& l  Z, i
  "<tr>" + - @% t' n$ A2 L
    "<td>Part Number</td>" + 2 U5 R* A  u" I' |
    "<td>Description</td>" + ( {- a3 z. c# `& O- S+ v
    "<td>Cost</td>" + + s/ w' W5 h4 ~7 F) l( a
    "<td>Quantity</td>" +
* G2 w" `8 v, }5 l! i! X  "</tr>"; + `+ k. p& J2 E
5 V6 @1 y2 {5 X9 i7 X. k! w
// Iterate over the BOM Items. ; O' @# |, ?5 v- r% i
for (var i=0; i<count; ++i)
" Z1 {0 }5 Y5 Y. z& f{
3 H& L) |2 I6 e- O// Get a handle to the relationship Item by index. ' [8 C- b0 w& ^
  var bom = bomItems.getItemByIndex(i);
8 I  @; M9 x) p, w* q0 b# s// Get a handle to the related Item for this relationship Item.
7 Z+ x; f4 F" l# u  var bomPart = bom.getRelatedItem(); 9 @% R. U* V+ z+ }; x
3 H- H/ m3 O* y
  content += "<tr>" +
4 i/ i! P4 Q' P1 a$ B      "<td>" + bomPart.getProperty("item_number") + "</td>" + 1 g. d% v. f. `5 B+ r* V
      "<td>" + bomPart.getProperty("description") + "</td>" +
; ?1 h3 l2 n: C8 W# @4 ]2 b      "<td>" + bomPart.getProperty("cost") + "</td>" + & ~" F3 l5 `" j7 n5 Y( D0 {* a5 d
      "<td>" + bom.getProperty("quantity") + "</td>" + ) @1 @( r2 v# K! F8 S0 v/ P
    "</tr>"; 1 u7 E" H* r, j8 p* U! Z: u) u7 \
} * `7 {# t( X, ]% x9 X* x9 u  G# r
return content + "</table>";
) K2 w$ T4 |3 I! _( g
  A2 C1 r7 a/ ^) L8 V
! U6 r, k; j1 P- V& [
, C' z& S2 S& s! @$ {
8 q9 f' A! C; [- x$ F+ g; P
C#  8 o7 N9 ~" l* q9 X" ~
Innovator innovator = this.newInnovator();   ^3 v0 B( a/ r0 y4 n& H1 \
' t( r. I% P$ ]9 E$ N' T5 C2 i; k
// Set up the query Item. 3 h4 I) E! Q/ v9 E7 `# {) L; H6 a* x
Item qryItem = this.newItem("Part","get"); + }: S* `9 X: x+ R' @; G- K
qryItem.setAttribute("select","item_number,description,cost"); ( r  q; q7 Q" F% x2 T% E) N
qryItem.setID(myId); ( M" j! }. A" `' ^+ l6 |

" D" m$ z" f$ P2 z- C4 G$ ^3 h// Add the BOM structure.
: i0 Q% H+ {  Z5 h; X& uItem bomItem = this.newItem("Part BOM","get");
: L/ \1 x8 j$ ~; C; o( k. T+ EbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); & L6 ^! V- I* u1 s. o/ K
qryItem.addRelationship(bomItem); % t$ p6 m( M& p" y. Z2 \
( T. \- {0 [' Q8 R4 I4 J: L1 x6 M
// Perform the query. 7 F, m( Y. N  c* m
Item results = qryItem.apply();
" [7 }+ t7 D% f5 I1 {$ A 7 C( J; `1 M! s, h: o; n
// Test for an error. 2 G! J7 a5 d' q6 v
if (results.isError()) {
" g4 x( T) h7 s+ _  return innovator.newError("Item not found: " + results.getErrorDetail());
. _: v  F( J+ t  F1 C" k- N/ U# ~}
$ }: b3 G$ J. ^5 A. z$ h0 q  _
! }6 _2 Q; J4 d  Y// Get a handle to the BOM Items. & b3 C/ V" S8 J, s0 d
Item bomItems = results.getRelationships();
  p: \4 b4 g+ Y+ P) }# _int count = bomItems.getItemCount(); # L, {8 b3 R* X& F& k; ^+ s8 H, E
int i; / U" _$ Q3 J# N, Z; @

, t& t, f9 G/ ]% Y( z1 Y( u// Create the results content. ' O" z6 I9 b! a9 Z' `
string content = "<table border='1'>" + ; \0 G5 ]' q3 g6 e" I& ~% H
  "<tr>" + / {7 m. T+ N6 d9 ~0 Y
    "<td>Part Number</td>" +
: s5 d9 o5 b+ Q. s: r% T    "<td>Description</td>" +
9 C; k6 z" P# E1 f  @$ ~4 m    "<td>Cost</td>" + " i9 x, Z. u# O
    "<td>Quantity</td>" +
0 Q; Z. M( N) }  "</tr>"; 1 M2 U$ q  H0 E9 h
2 X! R2 q$ w( N( e' l6 m
// Iterate over the BOM Items. ' ~5 x2 Y$ K' J6 C0 ^3 h6 q
for (i=0; i<count; ++i)
! G4 D# E8 ]* F, X1 \% G7 O. a9 \{
( o2 ~* |+ f9 S& E" x// Get a handle to the relationship Item by index.
6 _4 _" z' a+ t/ i8 H: ]* c- J  Item bom = bomItems.getItemByIndex(i);
; `2 W7 Y1 q8 E/ X7 T// Get a handle to the related Item for this relationship Item. ( \7 Q$ W  m1 S% J
  Item bomPart = bom.getRelatedItem(); ! C! Q" R5 _( y8 a: T. |
& [. }% I: `" O9 V/ S1 |2 T
  content += "" + 6 g+ Y% r+ I+ l2 K& Q
    "<tr>" +
1 u" S% F9 C$ |      "<td>" + bomPart.getProperty("item_number") + "</td>" + 4 v5 _' C2 |( j# O" f- N
      "<td>" + bomPart.getProperty("description") + "</td>" +
  h, r% v- Q* K      "<td>" + bomPart.getProperty("cost") + "</td>" + & y! R2 O+ v# u! b6 L8 j
      "<td>" + bom.getProperty("quantity") + "</td>" +
4 M. E/ L& R$ s    "</tr>"; 6 Q0 \" k+ ~9 c! _' ~# L
} 6 g: _; R# S  R* @& }
content += "</table>"; + |/ Y! {3 T/ H( E3 p' u

- v1 E$ h0 A$ G" s* O$ ^5 Preturn innovator.newResult(content);
  Y" W  z' v% ]% t. H4 V/ u
1 d# f, G0 @; t- d$ M9 ]
# s. M$ \( M, _6 l& U# X9 }/ o

# W7 ]* I4 u  i% A

- Q# K0 E* i3 j1 y' v: w- `' U. |
1 c9 e8 @0 L2 x: f; B

" G  M+ v, C) a. A
0 V+ U8 A; i9 o. Q) S1 w, H: w    Page 46 * A, a8 u4 `, H9 }, [% n' r& d
! f3 P' `: q; K
Copyright   2007 7 n( e* m6 e/ F7 a! p$ }; S
Aras Corporation.  7 z1 {# l7 \# R! g* }' t8 ^5 S
All Rights Reserved. 8 H: X( q: M3 B+ g
VB.Net  
: [2 ]" u3 h0 W$ U0 fDim innovator As Innovator = Me.newInnovator()
' s: G# Z" a% r( _ 2 o7 w: K0 f  z% O' C2 \- C
' Set up the query Item. 5 K4 I2 ^4 \0 i$ j! w4 ^
Dim qryItem As Item = Me.newItem("Part","get") % [0 N" h* k" F3 W9 Q8 t
qryItem.setAttribute("select","item_number,description,cost") : {) X( t4 |, A; L) ]  a
qryItem.setID(myId) 8 R3 a) M' h9 k1 Y/ n

% I2 Y9 x( k' V4 q3 x/ O' Add the BOM structure.
8 a% T- \5 Z1 O5 S# n% a6 MDim bomItem As Item = Me.newItem("Part BOM","get")
# |6 U1 ]9 @, c; SbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
; U. C) j( {5 N* I6 x0 Y3 p7 \) {qryItem.addRelationship(bomItem)
/ G+ V$ ?5 i. W5 a  u
: @, ^, F. W2 x% s1 b6 ^' Perform the query. 1 A* t% z( K7 A) W6 C
Dim results As Item = qryItem.apply()
* c- p5 A) a2 m! z& Z/ T- l  ~
) J1 l- b4 [6 e; t( q/ M' Test for an error. 0 Y1 d( x: A% V3 W. u
If results.isError() Then $ _, Q# ]% W9 h+ g$ f$ C
  Return innovator.newError(results.getErrorDetail()) + @! S1 k* `) J2 }% B( l$ v! f
End If : h- d' [6 i* J1 z

' B: Q0 a) C  i# R9 A9 m4 [% k3 h' Get a handle to the BOM Items.
! ]* S8 q0 q7 Y, `- N& {Dim bomItems As Item = results.getRelationships() : t) J5 {7 R+ G$ y% C9 |
Dim count As Integer = bomItems.getItemCount() # v' N( W  l. ~- t) Q3 l9 [
Dim i As Integer . g" E7 M0 |6 |  u% E( L+ u" Y

; k2 W8 p2 i7 ^7 I, ~1 t' Create the results content. ' m& a# E# \$ u: B$ O7 h$ @
Dim content As String = "<table border='1'>" + _
6 E* R. Y# \  ]' w: ~  X8 T  "<tr>" + _
7 c0 @! M3 E. f! B1 I' G    "<td>Part Number</td>" + _
& X# |" u* c6 v3 G1 `    "<td>Description</td>" + _ ( z# i  |6 v' T, y, j; c
    "<td>Cost</td>" + _
/ R& N" J+ S2 j; G) M    "<td>Quantity</td>" + _ 4 B7 q; e5 g) D$ C5 L
  "</tr>" # w/ D) J  A' C+ a* z* q

' {5 X8 ^5 w  ^  z8 E& V0 P3 K; c' Iterate over the BOM Items
. [, ~" K( ?. H! jFor i = 0 To count - 1
8 C* h: u7 p: X/ p" y6 V' Get a handle to the relationship Item by index. 9 x* o& P# S8 J2 U- W! I
  Dim bom As Item = bomItems.getItemByIndex(i) 3 h- U. a5 i/ H# V! q
6 O. P. Y/ N/ Y1 M3 z/ h$ p( ^
' Get a handle to the related Item for this relationship Item. 7 |, C* W( W0 X! |$ U/ R0 p  |
  Dim bomPart As Item = bom.getRelatedItem()
' |  v, D2 G- D ! |0 T4 }3 F. `& b, e  s, m& `  O
  content += _ . x4 `6 k5 X) L# G
    "<tr>" + _ , a' V( G$ j$ @% K
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
- a& w) Q: U% H, h0 {$ n4 o      "<td>" + bomPart.getProperty("description") + "</td>" + _ 9 W6 [0 I/ ]: z" S
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ , r& R% L: R+ e1 }0 j* a- T7 m/ F4 b
      "<td>" + bom.getProperty("quantity") + "</td>" + _ ( r4 h8 t3 ^3 a6 ]% @
    "</tr>"
! o  X" O" _' l9 m# ?  p: NNext
$ C$ Y' z- s, T0 J, [$ Q& p2 Icontent += "</table>"
+ ]0 M  L: j  d% W % Q0 K% @# v: r" e7 o, a& a9 e. J
Return innovator.newResult(content) 3 |: e' O+ F. p! n+ B
8 b/ Q# Q( Q0 F0 v& W
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了