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

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

[复制链接]

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

2471

主题

1276

回帖

8万

积分

管理员

PLM之家站长

积分
82195
QQ
发表于 2018-8-1 13:41:14 | 显示全部楼层 |阅读模式

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

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

x
Technique  
. x% i3 M3 c6 w0 M8 Q7 Q# hTo query for an Item and retrieve its structure you build the query as the structure
! p* |- x2 F9 W% Y$ v4 B7 v0 Yyou want returned.  Use the IOM methods to add the relationships you want and 9 E# d- `; s1 W! w. {; u( Z  W
build the structure in the Item.  The server will return the structure that follows the % I8 z7 O; P8 p8 ~# B. T- ^
request structure. + G+ h% z( q1 A6 t6 W
This recipe illustrates several related concepts together, which are how to get a set : u) @/ x7 b+ O9 h4 N, g3 x1 ~
of Items from an Item and how to iterate over the set, plus how to get the related ; [. |# o8 ~, z0 A' p
Item from the relationship Item. 7 C" v  W$ G  W0 G% x
JavaScript  3 e" |: |- d9 e, `
var innovator = this.newInnovator(); 3 Y; K0 c+ y+ ?! G$ k9 q0 [. a

; ]4 o5 l9 p2 a  t# p// Set up the query Item.
; V, q7 e7 b! \var qryItem = this.newItem("Part","get");
* I* y7 L5 `+ A' K- {qryItem.setAttribute("select","item_number,description,cost"); 8 c, K; ?' k- }& x: N& C; h4 Y* {1 J3 A
qryItem.setID(myId);
; b9 F. c! c9 X- B2 o   |& t% P. w& D% q6 K; E4 ?. a( Y
// Add the BOM structure. 6 P1 k6 l* [; I4 G. k
var bomItem = this.newItem("Part BOM","get");
% q; L. u; q+ d" qbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
( ~6 ?2 M0 Z; f0 A6 ~qryItem.addRelationship(bomItem); $ u# q0 \( @' v/ D- g0 N
1 i; q  E( I% l( R' g; a
// Perform the query.
) K. h; p$ h$ i6 F3 e. [1 ]8 Kvar results = qryItem.apply(); ; [# ?1 a8 Y' u3 v& I8 c  f
% n/ \: w( h. n  J3 L3 r0 T# G9 o, C
// Test for an error. . `* I  r$ }) G" E
if (results.isError()) {
1 w4 F3 I, ^+ i5 q) T  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 5 S8 R; M0 _! w' E& g- B! w# e
  return; / H5 A/ M+ H8 D+ {- s: G$ I- ~: {
} 5 z; c$ c2 R& N6 C1 q5 K
$ d4 b: L4 o; u, H' k8 K4 u2 [) E
// Get a handle to the BOM Items. 9 s* W% m, e# c' g+ Z0 \# |1 a
var bomItems = results.getRelationships(); % F3 d9 A9 T5 r6 t
var count = bomItems.getItemCount(); , T8 ]8 G# g4 R5 Z' f. Q, o3 e/ x2 Q

' J+ i8 I% N5 \; d1 h; v+ X// Create the results content. ; f9 W3 s$ |7 I0 P
var content = "<table border='1'>" +
& X$ Z. T* F+ `( Z/ P* Y  "<tr>" +
9 M' s+ u! u7 x5 S1 m& J+ m    "<td>Part Number</td>" +
1 V& G7 B9 a. G# J0 l' U, Q* E8 V    "<td>Description</td>" +
) ^" \5 |% _' a: H; Y6 d, x% ]) ]    "<td>Cost</td>" + ' s6 O+ C# }, n; r" s, H# ]0 o. c
    "<td>Quantity</td>" +
0 G5 j, a0 ^& p1 d# h. `  "</tr>"; 1 o& c! H( [  E* X. ^, y

, q7 P4 y$ ], l& B// Iterate over the BOM Items.
  u1 J% H% _& X6 vfor (var i=0; i<count; ++i) - ]6 _* K5 G; f4 y5 ^$ N7 K& P
{
* k7 K- |3 g% G+ e// Get a handle to the relationship Item by index. " b/ t- j$ k2 K- Z4 ^& K) U
  var bom = bomItems.getItemByIndex(i); 7 r2 z, E5 ]$ S! W; `+ t) _/ k& U
// Get a handle to the related Item for this relationship Item. / E# J+ V: a+ @* Y, J- a+ `' D
  var bomPart = bom.getRelatedItem(); - b7 c* ?9 e, P) Z/ @& X

" s! k! a* S+ N* c" n  content += "<tr>" + & v7 W4 V1 R+ L9 B2 A8 `
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
! r9 f, A# n9 ]! o0 a6 v      "<td>" + bomPart.getProperty("description") + "</td>" + ) Q! O" q# C; i; ]
      "<td>" + bomPart.getProperty("cost") + "</td>" +
2 h/ K3 U% ]6 i4 V) t3 C      "<td>" + bom.getProperty("quantity") + "</td>" + ; t  H4 ?) h3 N
    "</tr>";
6 a5 Z: N% ~. R8 Y9 e3 T# Y} 4 N0 ^5 J0 R6 I0 ]1 E
return content + "</table>";
, ]! {" [# |( D1 k$ m+ x" h: H) s/ |; `9 P

$ _9 j3 }4 r' F4 |( v( B/ k4 U! n8 e

% X" T8 @( ]( YC#  ! s4 ^2 M( U8 Q' U' \1 J8 c
Innovator innovator = this.newInnovator();
- m8 a1 U! H, X# r. i ' G/ H0 ?& U! K% V, O. ~3 B  M
// Set up the query Item.
8 }  ^% S: ^" }6 u# M# `Item qryItem = this.newItem("Part","get"); 5 A7 q$ T- j: a, x
qryItem.setAttribute("select","item_number,description,cost"); 7 v2 Z: ?0 I/ b2 g* @: u0 E- R- w+ i
qryItem.setID(myId);
1 @+ r( S/ A& ?5 `* y
3 G, }' @- b) U7 W' y& f// Add the BOM structure.
1 J. a7 _4 t6 N! _2 |5 [% s4 n5 cItem bomItem = this.newItem("Part BOM","get");
# ^% p- T1 a; V9 h: ubomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
1 h5 |7 x/ ~7 Y) MqryItem.addRelationship(bomItem); + b! Z# B& e- H% s% n) x
' d. [  _; `; V0 |3 r! [3 `# o7 {7 _
// Perform the query. ; y7 u6 ~) h* O9 {: \
Item results = qryItem.apply();
& L* b, W% M0 r2 v0 O0 G2 R
7 y6 p& v4 n( o1 @- B  n/ a  J// Test for an error. + S# s5 ~. }! \, T* v8 F! `+ n
if (results.isError()) {
* i) ?3 x* }. W  return innovator.newError("Item not found: " + results.getErrorDetail()); - ^+ j* N1 r: \' `) L5 `! J
}
' r  v! T" l4 R6 t& |
, i! ^  Z, Z" h0 f1 x// Get a handle to the BOM Items.
6 v/ D/ f$ U( Q, G8 n: f8 _% CItem bomItems = results.getRelationships();
+ w. \$ m2 |3 G7 X2 l2 J+ _int count = bomItems.getItemCount();
# o: c$ b: v: [int i;
/ C4 G5 H% B' K/ o/ D
# V& H5 g. k/ T9 ]8 A4 ~// Create the results content. / M/ ^2 R2 z: G* L" q
string content = "<table border='1'>" + * d2 c; @. O1 o5 m% q0 q
  "<tr>" +
  S8 N' @9 ]9 S8 ?6 p    "<td>Part Number</td>" +
9 [- R3 D& U+ |! f    "<td>Description</td>" +
; l  D" z2 T, D9 i! {) Q# p  B; h    "<td>Cost</td>" + , Z& e2 n  Z& }* Q) l: k' f5 w1 k
    "<td>Quantity</td>" + 1 ~/ ]" @3 I0 }1 i+ |3 Q
  "</tr>"; 5 f7 m7 D; b4 H$ X; Z
/ V* Q! ^9 a3 B5 P: g6 `
// Iterate over the BOM Items. 5 g$ y  A; ?% G5 [* m
for (i=0; i<count; ++i)
4 W" J! F$ f- t& x3 y* ^& ^3 Z{
' f6 R9 l9 T% I- a1 s* q3 D// Get a handle to the relationship Item by index.
  v% d0 ]) A( V  Item bom = bomItems.getItemByIndex(i);
/ N# r! b1 \) t7 u) z// Get a handle to the related Item for this relationship Item.
3 Z4 @& b+ R& N6 x  Item bomPart = bom.getRelatedItem();
( X4 [/ B' q! z
+ X' B8 z* m! g% F' i' j8 `  content += "" +
4 Q( h: H. F( I, `    "<tr>" +
' K" x3 p! V" n: |* L2 q      "<td>" + bomPart.getProperty("item_number") + "</td>" + + ^6 R: b$ Y3 ]- k# ~/ _8 ^. w) `* P
      "<td>" + bomPart.getProperty("description") + "</td>" + * w3 m) X* k; I# Z, F& H
      "<td>" + bomPart.getProperty("cost") + "</td>" + 9 b- ]2 m0 I* ~  ?3 X2 K# j
      "<td>" + bom.getProperty("quantity") + "</td>" + . e* T& e! t9 f4 c5 b
    "</tr>";
& J( ?, S- M8 O+ f1 K% N} 1 K" x' _$ o: v: R# a, y
content += "</table>"; # ^" ?$ r3 y; X6 N  l( R0 _) ]( }

: V+ D2 d8 Q. m  mreturn innovator.newResult(content);
3 {- _! F3 b& [4 r5 s& l/ D) U, m; X' H- p
0 H: g, |# R! Y. @$ G6 G
- Y  g1 W9 r1 Y% e. K; `+ g; `
/ N2 x# B! |$ f$ ^  m! A

; w# S7 x! K+ u2 P+ q+ A. b

8 m( B: S% U/ N$ B8 s
; f" F2 q1 i" F) [" A$ ^    Page 46 6 w& p! ^4 v! h/ [
" M6 g0 p3 ?/ L5 d4 s" u1 t
Copyright   2007 + U; y2 ?8 I- ^6 S3 |
Aras Corporation.    {% G: ^9 W- D
All Rights Reserved. & q% \+ A  G8 R* a# w5 W
VB.Net  " \" H, y+ ^; r. U6 B6 f& c: ~
Dim innovator As Innovator = Me.newInnovator() 3 V* O' U& E4 @( o# D* Y

& A6 r* P6 @1 K' Set up the query Item. ; r$ `3 |( n3 B( B: \1 w
Dim qryItem As Item = Me.newItem("Part","get")
# i2 [3 T6 n3 hqryItem.setAttribute("select","item_number,description,cost")
9 Q. w) O2 F* c9 [( l9 WqryItem.setID(myId) 3 j) o! |6 A# A- W! e% a; j
( x0 r/ ]) I% m, B5 Y
' Add the BOM structure. 6 u+ Q0 d/ F! k% D) m% h
Dim bomItem As Item = Me.newItem("Part BOM","get") " Z8 o- O. v6 L- Q3 ?
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 0 }+ M3 k* b5 _
qryItem.addRelationship(bomItem)
' r* G% ^# d% y2 G+ q
# x' z5 i8 g# C  P, \' Perform the query. 1 N3 Q! E/ I3 F
Dim results As Item = qryItem.apply()
( n! ^- l1 k& D3 ~7 M$ C* k1 f : k) }, ?- t7 u2 o* ^
' Test for an error. + A' L. t2 z$ g/ K( }
If results.isError() Then 8 I- W9 e2 M5 B: B
  Return innovator.newError(results.getErrorDetail()) . r7 ~1 Y/ u8 ~" _, K7 O/ O+ g
End If ) I4 K9 K/ Q' X
* N2 [/ K7 n% X- U$ K3 t' T/ N' e
' Get a handle to the BOM Items.
! F6 U% {, u1 @3 a% BDim bomItems As Item = results.getRelationships() ' A+ N4 z# l8 \) U" l' V4 }2 P
Dim count As Integer = bomItems.getItemCount()
0 g7 w( l: `7 V& f) Y0 kDim i As Integer
8 S) V! n" ?! h / @$ s8 _% v: ~% z! s4 b
' Create the results content. ' l7 P% ]( T* a! q: r, Y
Dim content As String = "<table border='1'>" + _
" _/ \9 N* V/ x2 I2 O, D2 `  "<tr>" + _
* x1 l7 F0 b. t    "<td>Part Number</td>" + _ # b7 |' ~+ d' T3 v) X# S4 X
    "<td>Description</td>" + _
% z8 \1 V+ h" g; m% K9 H' c    "<td>Cost</td>" + _ 1 ?/ I3 H* |# A% w3 w
    "<td>Quantity</td>" + _ ( \# h. q. [, l5 W: j
  "</tr>" + s5 f% P( V$ ]: W9 }

' n& m: W8 P" {" y: u" I' Iterate over the BOM Items
  {: Y4 @( w3 ZFor i = 0 To count - 1 $ ^# m+ c+ d! [. |
' Get a handle to the relationship Item by index. ( b4 z6 z5 {' |7 {8 `( B5 K+ M8 K- Q
  Dim bom As Item = bomItems.getItemByIndex(i) ! Y- t; m0 p: K4 w" j

/ ]3 h$ f8 D4 b' Get a handle to the related Item for this relationship Item. & {1 H$ t% h) b3 L
  Dim bomPart As Item = bom.getRelatedItem() ( O  f( x- A6 J! v, Y
9 P; {& I2 J8 _; \$ |0 o0 I. @5 E
  content += _ % ?. F1 @. c( e
    "<tr>" + _ / U. s3 w3 T; j3 s! [: _7 I" \" {
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ * P+ J. _5 |( q; F! F
      "<td>" + bomPart.getProperty("description") + "</td>" + _
' F9 n1 G; K; a- Z( Y; f      "<td>" + bomPart.getProperty("cost") + "</td>" + _ ; V; E* L1 L/ e6 k1 P
      "<td>" + bom.getProperty("quantity") + "</td>" + _
- r* h, d/ X4 ~    "</tr>" : q3 ^1 P5 x  }' P% G$ W* X( L
Next
9 u' @3 B) ]- R$ M4 Kcontent += "</table>"
* Y9 D3 ^4 K( i
& e3 W) h) o2 l, q1 g% \Return innovator.newResult(content) 2 M5 E/ w( u  w/ f( U! F, n  y" F

  s  i* l. c/ X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了