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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
; y1 z* f  A" N, GTo query for an Item and retrieve its structure you build the query as the structure
4 d% l* L! ~5 @0 K* pyou want returned.  Use the IOM methods to add the relationships you want and
0 W9 g1 f# R+ `' b' {* sbuild the structure in the Item.  The server will return the structure that follows the
9 e/ l9 S0 V, {4 _$ \6 D$ W" Irequest structure.
  _1 b' n5 I" x- PThis recipe illustrates several related concepts together, which are how to get a set + n+ s4 w" N2 \5 w3 s4 X
of Items from an Item and how to iterate over the set, plus how to get the related   `/ f- ^) e) W/ E6 J
Item from the relationship Item. 6 p: x. s' S  ^0 K. x) [1 Y+ i2 V
JavaScript  7 G0 Z; ~7 }2 G' Y+ s' G& |
var innovator = this.newInnovator(); ( e7 S7 Z: j" ]4 x( a

) C/ K; W: l! q- B% R( f+ c, y& {// Set up the query Item. 9 F) s0 C- Z, X* I9 L: k
var qryItem = this.newItem("Part","get"); 9 C& }9 x: A7 ~5 Z/ G4 l
qryItem.setAttribute("select","item_number,description,cost");
7 S( v! C3 A+ R: |$ |qryItem.setID(myId);
0 f# O4 U4 G$ c7 N0 }7 \. ?, E - k% H: L. y% m- K
// Add the BOM structure. 7 J# B8 U. v- M, \# `" ~
var bomItem = this.newItem("Part BOM","get"); & c8 w/ h) }* G) H2 y: D% V
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
# B0 w$ m) i& E% O3 t( wqryItem.addRelationship(bomItem); 4 d, v; l- E& L5 ?; O" G

) X" I$ L0 t- j+ e, r- K8 {  Q// Perform the query.
. N! l; }7 `2 D& d0 ovar results = qryItem.apply();
2 _9 B1 u) h( s# A. d- s
' X& G4 |5 i2 W// Test for an error.
; w6 ]; b! N) ?% hif (results.isError()) {
6 r6 Z) T4 R- j/ r. u: |3 X5 v# X& m  top.aras.AlertError("Item not found: " + results.getErrorDetail());
" `" O* n: c( f0 ~6 w0 m; d/ N  return;
: n+ X- u7 _0 X/ ]0 B} ' |2 i' b& x& W9 s* V5 d

$ _8 s6 V: ?! ?6 A- b// Get a handle to the BOM Items.
4 T: ~4 Z* ^0 _var bomItems = results.getRelationships();
' |+ O$ p& Q3 T9 ^+ fvar count = bomItems.getItemCount();
9 H) U3 G# E2 v2 |) T1 t
% n/ D* ?( j+ C+ ^// Create the results content. # q' j' f8 L9 i3 ^
var content = "<table border='1'>" +
" M; G: j0 o, g3 e9 E  "<tr>" +
+ M& m2 ^( H0 o    "<td>Part Number</td>" +
. b& ?) g$ |1 Q5 e; K    "<td>Description</td>" + / |3 [- u& l( ]+ T  N( G
    "<td>Cost</td>" +
  z% w5 d3 G+ B" U, C' w/ J    "<td>Quantity</td>" + $ Z3 O! k0 K( z* ^
  "</tr>";
5 @5 t- z. u6 R, K+ h' X. A
  E( e0 C$ p, z; K// Iterate over the BOM Items.
7 c# Y0 F5 z0 Z. H. ffor (var i=0; i<count; ++i)
  r- n- u  ?: Q( P/ e3 p/ b{
- @* T- Q) k- W& p2 B1 ~4 m3 x// Get a handle to the relationship Item by index.
& F9 r& s# w7 d$ o  var bom = bomItems.getItemByIndex(i); 8 c. Y  l1 H1 o: x9 X$ P
// Get a handle to the related Item for this relationship Item.
' w) s2 i1 f. c0 l! l  var bomPart = bom.getRelatedItem(); , v" Y7 i7 c8 P

- U( r* S% O9 h$ L  content += "<tr>" + / h4 P, ^) N/ v) k9 H
      "<td>" + bomPart.getProperty("item_number") + "</td>" + % N& y0 R& D5 t7 a% r
      "<td>" + bomPart.getProperty("description") + "</td>" + , c9 v0 [/ w6 A
      "<td>" + bomPart.getProperty("cost") + "</td>" + % }! J5 q$ {0 w7 v3 Q! `
      "<td>" + bom.getProperty("quantity") + "</td>" +
3 [& u% b" J& k1 H! z$ a9 D    "</tr>"; 3 t, o. {7 J5 y+ v3 R+ v/ h$ U
}
8 O4 ^8 }4 m- e+ G# Creturn content + "</table>";) V5 P% p# Q  c1 D) n* O
/ N5 f, R( ~/ I) b* h

' t6 F9 }. N8 i. m' f1 y# R7 y' }; M. @3 M. T" b

* s9 s7 G/ J: y7 `2 r- yC#  
2 w! g# F6 F9 d" ?1 KInnovator innovator = this.newInnovator();
& d& _  W  L/ m  x ) a% B& E- v7 I! g, F
// Set up the query Item. 2 L  H: K) l1 z2 W" e7 g6 G1 Y/ C
Item qryItem = this.newItem("Part","get"); - n# K* R, `& i) [7 C* z+ c
qryItem.setAttribute("select","item_number,description,cost"); ) T, r& R; k6 K
qryItem.setID(myId);
( `# X# z0 {% @  o+ L ( A$ e3 _& Z1 s3 }; k
// Add the BOM structure.
) z+ }, U5 |( |0 S0 ~' ~: h! LItem bomItem = this.newItem("Part BOM","get");
  @8 z4 K+ k; SbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ) O( w4 @$ u! j: Q1 G! j
qryItem.addRelationship(bomItem);
  l1 z+ B: I5 d / P# G2 Z- @7 U0 L5 c; Q
// Perform the query. ! B6 C# }! x4 E! d( p
Item results = qryItem.apply();
# G* C1 N) \' f8 l. Z7 }) ?( G
( j4 |* e0 w  w# P% U; x; H// Test for an error. % X1 n. E: u+ f- h) t0 ?0 Z
if (results.isError()) { 2 y1 b' h3 _4 o: b& z& Q6 D
  return innovator.newError("Item not found: " + results.getErrorDetail());
, g) @1 f2 U3 V2 I* |* T9 c) p/ w7 m  x} 6 b7 v: P, `, n6 T# ]% K$ _
3 n8 p# Z  Y" m% Q, m
// Get a handle to the BOM Items.   K% e1 ]- Q0 M1 i( q+ s
Item bomItems = results.getRelationships(); ; A% u1 Z4 I0 I. f/ X9 R# F
int count = bomItems.getItemCount();
8 \! c! F% d5 Q# F9 {# K( Oint i;
$ `9 Y; N* d% o4 I; m; l  \ ) v& H3 [4 n$ z$ L5 K" _8 k
// Create the results content. : y0 T) B  T6 e' R% H8 j6 ]
string content = "<table border='1'>" + 8 y) `) e0 M5 \* R+ a
  "<tr>" +
/ W. T& n% ^$ w: `( K    "<td>Part Number</td>" + 2 M9 {8 k- T1 w) q0 `: d$ w
    "<td>Description</td>" + 9 G8 l) Q% p! e% i' q
    "<td>Cost</td>" + 8 t8 f1 a* {! G( v& u, B& p' ~
    "<td>Quantity</td>" + ( H7 p1 f9 q4 z/ O9 m
  "</tr>"; 0 t. _! g, \& T; [
( w+ W& o) _3 A! _; C3 n* A
// Iterate over the BOM Items. % u/ V) |  m4 o4 L
for (i=0; i<count; ++i)
- V/ Y! ]7 q# L{
6 R! |# X4 B& m  h( K' n+ F5 @// Get a handle to the relationship Item by index.
" X* e& P3 p) e9 w* Z1 n8 V0 t  Item bom = bomItems.getItemByIndex(i); 8 K5 C: I- z5 c: e# X) X* t0 A
// Get a handle to the related Item for this relationship Item.
$ I1 D; @9 t) Z- ?, M' h, U2 n  Item bomPart = bom.getRelatedItem();
8 W- {# V4 _5 u( X& n. C! o' M, _! J
7 O1 \2 U8 M. K/ K7 ]4 q# h. Z  content += "" +
$ K, q1 i, E9 L    "<tr>" + # {- k" x% k& h" @6 \2 V" o
      "<td>" + bomPart.getProperty("item_number") + "</td>" + , [+ z  y" b! P9 k
      "<td>" + bomPart.getProperty("description") + "</td>" + ( G% {6 t: J# W4 U8 u
      "<td>" + bomPart.getProperty("cost") + "</td>" + ( `/ b2 u- [. n1 \; h: G4 c
      "<td>" + bom.getProperty("quantity") + "</td>" + + a' q( k& B$ B1 @5 Q5 v6 i6 t
    "</tr>"; 4 S2 M' V- ], E: }/ R8 o! i* U
}
( a, h1 b; ^# W8 x9 v0 Vcontent += "</table>";
( ]/ W5 ~) p- R8 M* Z; S$ |. X9 y
: O4 A5 y6 b+ @/ k! areturn innovator.newResult(content); - i. e# E* U. a$ E  {* |9 \
+ }3 o6 ]; c2 S

/ o9 O, z) }: V
, ]1 i2 y( d5 x9 E8 O" \3 c

: E1 R1 f& m; U6 I
3 `" s& G- Y  W' t3 k3 B  C

) e* I0 W: j! s& B% l
" C/ y' L  P/ x  U' c0 L8 k0 L& _7 O    Page 46 0 e4 m5 ?! N- R- w' E

" J% N- y$ w2 w3 {! J( V  c/ ~; eCopyright   2007
3 U9 o. }  o) `0 r. ]Aras Corporation.  
0 t- v, l* U8 SAll Rights Reserved. 6 o" V5 t# |/ S8 ?( N, Y
VB.Net  $ Q2 N0 Z! `! Q7 J0 Z+ ~0 i
Dim innovator As Innovator = Me.newInnovator()
) U$ @* n, n) v% A2 Y+ g  W6 e
! m* S3 ~* i; Q& y0 H; {. G' Set up the query Item. / u9 c- x. s# H: j% b
Dim qryItem As Item = Me.newItem("Part","get")
" k- P' _$ N# L/ WqryItem.setAttribute("select","item_number,description,cost") , G( P& _, c$ x+ j8 ?; M$ X
qryItem.setID(myId)
! `; i0 b. Y: N3 }- G0 \* c2 o
+ @0 f; ^$ t# [/ p, R; S7 C# R" G8 y' Add the BOM structure. . B" N5 t6 ~: q- {7 t' j. s
Dim bomItem As Item = Me.newItem("Part BOM","get")
7 S$ p" k4 ~4 _! L4 e0 zbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
8 z* {6 M! @. L" H4 ]qryItem.addRelationship(bomItem)
+ M1 {% H; X. A+ d3 }& P
7 S9 b3 H" \8 w) E# W: B# ^  u' Perform the query.
" o* u2 y: N) h" {; n6 HDim results As Item = qryItem.apply() / o9 y6 z  n: [9 v

3 I3 y1 O& B9 W$ `* s: x# C1 r' Test for an error.
* `. B* G' s5 Y+ @& p8 VIf results.isError() Then 5 x/ _& G: o# Q% i4 {
  Return innovator.newError(results.getErrorDetail()) 7 t$ ]% V- H2 g& v  P7 S  C+ _
End If 1 a5 ~2 K( S" U$ g4 ]
1 |" ]5 N9 Y2 z3 r! T& J1 o* s: W
' Get a handle to the BOM Items. 2 y6 }6 E8 U4 S$ @2 _9 s
Dim bomItems As Item = results.getRelationships() 1 I2 t1 a! c+ S. }9 D% ~% x
Dim count As Integer = bomItems.getItemCount()   [& F* w9 H1 T! Z
Dim i As Integer ' o2 K# A, ^$ A4 n( D, ?

; Y9 b$ g; S. r# I: x! V' Create the results content.
. f+ i5 p, S& c$ ^8 ?6 ^Dim content As String = "<table border='1'>" + _ ' m, l2 Y1 _2 }# V. O
  "<tr>" + _
* b8 P: t: v$ c    "<td>Part Number</td>" + _ + S  q3 d, N6 I+ _+ s
    "<td>Description</td>" + _
3 S- \7 O  O0 J, h    "<td>Cost</td>" + _ 6 C0 k7 x' z, G1 N3 s* Z, |
    "<td>Quantity</td>" + _
+ i% }+ |9 x' y% j. Q( ]  "</tr>" ! C, H' D$ h7 V3 ^
& E9 Q* ~  A& ?/ R5 \, k1 j0 O
' Iterate over the BOM Items   W/ a% T" w4 D' [' w
For i = 0 To count - 1
. x1 U% f4 p$ m. a9 p# M' Get a handle to the relationship Item by index.
' i) ^. y& z9 G4 v5 j! V  Dim bom As Item = bomItems.getItemByIndex(i) ) Z9 V: p. Z6 {  t& l# r) k& I

$ q$ J0 l* L- J! G, `3 L& L' Get a handle to the related Item for this relationship Item.
% k7 e. o( Y/ t6 q  Dim bomPart As Item = bom.getRelatedItem() 2 ~) x% [" D) n  [: g

6 y3 H4 v4 a( ]3 X3 ~* S1 Z1 T  content += _
  f- T* V1 i, d- V/ |& I4 u. c# a: e    "<tr>" + _
8 a& Q: p& d9 H! M. j; k      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ! Q" y  p# m- L: x$ c/ S5 r( A1 T* d; O
      "<td>" + bomPart.getProperty("description") + "</td>" + _
- S% v* o1 X. f+ j% z" e4 c      "<td>" + bomPart.getProperty("cost") + "</td>" + _
$ g" c  n! n5 Y% n4 y      "<td>" + bom.getProperty("quantity") + "</td>" + _
5 ^5 s3 ^. d7 n    "</tr>"
0 R6 H! D7 D, ^# O/ YNext : M( N" n5 w9 o% X
content += "</table>" , [8 L! e# f) {0 i* U# S

& Z3 L5 g1 D/ l  M- Y; x7 Z0 g$ s! wReturn innovator.newResult(content)
; w. A& f, Z/ F: O) E4 F/ Q( p* v. p+ K, 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二次开发专题模块培训报名开始啦

    我知道了