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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
+ a# M  ~( z  ~To query for an Item and retrieve its structure you build the query as the structure
7 v; R2 J" x9 Dyou want returned.  Use the IOM methods to add the relationships you want and 5 y8 A1 j# M' d' K* P
build the structure in the Item.  The server will return the structure that follows the
. ^, n/ ], n- b( K" Arequest structure. 6 V$ f: I* O! {5 X0 a: ^/ Q% B! G# h
This recipe illustrates several related concepts together, which are how to get a set ' H( T- |  i* ?" ]1 D! R; `; ~
of Items from an Item and how to iterate over the set, plus how to get the related + ]/ c0 \' o0 T! i
Item from the relationship Item. , r# T9 ~7 n, Y" v
JavaScript    n7 y; g; T! ?, ~0 E- o
var innovator = this.newInnovator(); ) k8 ]4 |9 \5 C
' s0 o4 }( f# X$ J% Z# s
// Set up the query Item. 1 Y5 s/ b# U3 Y8 v( X
var qryItem = this.newItem("Part","get"); 8 x+ ^: w! G, F4 y3 @2 l: V
qryItem.setAttribute("select","item_number,description,cost"); 8 {9 [( c/ L. r8 ]0 b) `* J0 k% a
qryItem.setID(myId);
( r3 L& m; y; b ( L" b% J4 q4 m# ^* h5 a. a
// Add the BOM structure.
. f$ @$ h# z! J4 V4 k% xvar bomItem = this.newItem("Part BOM","get");
% E3 |4 n4 K6 V) e: QbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ! N( E6 X! E4 Q+ \7 M+ c  l
qryItem.addRelationship(bomItem); 9 r" z% n" b. b
4 I& D" p2 q  h1 _1 I" i: r
// Perform the query. . V( O# w% y! g8 u
var results = qryItem.apply(); ) c% w6 X" `* ]- N- v- B( k7 g

) A+ T1 J; o  B// Test for an error.
( n# B5 x* j3 D' g6 e/ J# [if (results.isError()) { 2 |9 ]% S' b: ?6 v% F$ E- p
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); - t5 ?% _, N9 b( I+ U
  return; 5 a' v3 R/ ?9 Q8 {3 s0 Q; K
}
! K$ f! k+ I$ M$ G( G& k- j) r 0 I0 ]) H. h7 T
// Get a handle to the BOM Items.
0 u! X* H; o0 Q! u. Zvar bomItems = results.getRelationships();
; J& I5 H  {. a7 q3 avar count = bomItems.getItemCount();
- T3 f% }. c9 t3 ~/ ]& ~
: p* d) b( L" z, p1 i: Q, ~// Create the results content. # y6 R! |  T' K) e$ y: t
var content = "<table border='1'>" + 8 J: L5 ?9 ]# V4 H, L) v4 c/ _
  "<tr>" +
! A5 \! P, I9 A' l  L: S    "<td>Part Number</td>" +
, ~+ U3 @+ I, I( f    "<td>Description</td>" + $ B0 S+ _7 d* F9 V! G7 Y# u
    "<td>Cost</td>" + 1 J. u9 Z3 `+ b) O
    "<td>Quantity</td>" + * \, [1 Q2 ]. L/ d( I
  "</tr>";
; I$ W$ V2 S& A; r3 X7 c 1 X5 ^: V, Q. |1 F9 V
// Iterate over the BOM Items.
1 a! S5 a& N( T9 u7 t6 p0 mfor (var i=0; i<count; ++i) 6 [) |  f. M% {$ Y2 k
{ 8 A% k$ X6 r3 T8 F
// Get a handle to the relationship Item by index.
$ n; I% D6 B- j' \! Z  n  var bom = bomItems.getItemByIndex(i);
& c/ {7 Q- C# \, O3 V+ O" O// Get a handle to the related Item for this relationship Item. - T) O! \0 b9 f& h& \# W9 k
  var bomPart = bom.getRelatedItem(); $ w3 M, ?# |. ]0 E+ Y/ v/ O  x

' U/ w3 ?' ?( [- C% w9 O3 n  content += "<tr>" + + u5 Q7 i" E8 d' p& s, E( U
      "<td>" + bomPart.getProperty("item_number") + "</td>" + * b# O1 |) r, |- S& R, ^1 Y+ g! m
      "<td>" + bomPart.getProperty("description") + "</td>" +
# e5 x; G: c2 s8 _/ z5 @/ K      "<td>" + bomPart.getProperty("cost") + "</td>" +
8 z  U3 g9 U9 Y- y. ^/ o      "<td>" + bom.getProperty("quantity") + "</td>" + . b" t) b/ g% z8 V! }7 N
    "</tr>";
: E* @0 u3 g8 v/ [}
/ j$ Y- K( K; F/ Dreturn content + "</table>";5 R; C+ F3 x% b2 A
: N1 P# }+ c6 Q5 \

% b  w9 M& N* V; R
1 b0 g  {. ^- r# |* ]2 @+ k& X

. U) D& d3 Y) }+ fC#  
% f: `; o; M' i$ s1 K* NInnovator innovator = this.newInnovator(); 8 j; f4 X9 N, P
" w/ D( r' W: r7 U4 n  z: n  _5 \) }
// Set up the query Item. 6 B5 v- X( m6 N" i8 E5 h
Item qryItem = this.newItem("Part","get");
8 X" L" D# Y2 o1 B1 mqryItem.setAttribute("select","item_number,description,cost"); 8 e. F: G$ J+ ~
qryItem.setID(myId);
( B! F/ v2 |8 Z5 B  E) g% l* [( f# \" M+ G
5 h; K1 A0 V" Y. h3 W7 p' \// Add the BOM structure.
$ D2 I: D2 ?8 |# Q# }! p* yItem bomItem = this.newItem("Part BOM","get"); " Q8 \# c# k1 C8 a) B5 V
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
& ]6 k) k+ d% v8 [1 s" X% E8 _! mqryItem.addRelationship(bomItem); . e" q& t; u/ E% d1 w- L/ Q; h- b+ Q
" t0 Y5 W8 H$ i$ K$ e
// Perform the query. # ~/ v) z/ x0 _
Item results = qryItem.apply(); & {* K8 N5 d: x; i9 N$ Y! V
3 v( k9 f8 C' Z
// Test for an error.   u1 K8 j. H* D" P! Q' m
if (results.isError()) {
8 x8 i, {3 Y0 `5 ?  return innovator.newError("Item not found: " + results.getErrorDetail()); ! [% D7 }, ], {# |( `; v' v
}
& f) u8 ^8 k. x0 s/ d' d 9 q: ~7 `- }- f! ]( v; o
// Get a handle to the BOM Items. 8 I8 l- C3 R4 m, ~% s
Item bomItems = results.getRelationships(); & q$ E9 U7 Z' ]) v
int count = bomItems.getItemCount(); ) U9 C, v  ~7 V! V1 E
int i;
. e2 [# Y3 a, k( |& ?  y % v7 k- Z$ p/ x
// Create the results content. + c; o8 d7 ~( B" T  s& x
string content = "<table border='1'>" +
8 A5 D% U' F& L) Z! p  n  "<tr>" + + v# q. K6 D( Q* `* K$ ~+ e
    "<td>Part Number</td>" + / i6 J5 t- U* K% [
    "<td>Description</td>" +
; S+ z' w( w$ F8 [8 g0 v    "<td>Cost</td>" + , a* i) O9 F+ M9 }
    "<td>Quantity</td>" +
4 ]+ I' P# J2 J1 m, d. o3 t0 v8 d  "</tr>";
( x4 ~* S- a6 Y7 k
. Z$ y0 g6 H6 E7 T" \// Iterate over the BOM Items.
* n% P9 x, X9 m, ffor (i=0; i<count; ++i) * L# J" ]( r/ B
{ * L5 |4 S, Z2 B/ q! ~% J8 W% \
// Get a handle to the relationship Item by index.
0 @4 r6 F  m. j6 c! [8 I  Item bom = bomItems.getItemByIndex(i); 1 [, z  T- P- _: S; r; u, l) _
// Get a handle to the related Item for this relationship Item.
7 h8 O  b# n4 @5 t% `  c; I  Item bomPart = bom.getRelatedItem();
* D6 `3 E1 u  V8 }5 O% g
! X5 b; I4 F% g3 r$ z: g$ J  content += "" + 5 K) Z4 U9 I2 F! L0 W
    "<tr>" + 4 l/ @6 p  x; V3 s  N
      "<td>" + bomPart.getProperty("item_number") + "</td>" + * p' @' x: K( R0 s* p# C
      "<td>" + bomPart.getProperty("description") + "</td>" + " U3 A$ U- m8 B5 `. V
      "<td>" + bomPart.getProperty("cost") + "</td>" +
# h9 o4 O& |3 p8 l' k5 n      "<td>" + bom.getProperty("quantity") + "</td>" + 8 R8 |6 `7 G' S4 |1 \
    "</tr>";
7 B0 I* Q% g3 b9 u/ L8 @# R4 i} 2 l: L( w6 [2 l6 O3 l+ a
content += "</table>";
! C0 B0 M; C8 L& H8 d * l' i' @% K! U- f" g( ^' }2 j) @
return innovator.newResult(content);
$ k$ G/ t" L: }, [4 q+ n( F0 G+ w! _. t( r* B

# A2 m* G% _6 q4 a  G+ T3 o) d' I) X. y- o2 K9 D

/ [+ |' p' }& o, [; e7 U0 t1 {' r3 d0 b$ |
9 B6 J7 s0 y. ?9 l! _
; K7 Y1 z5 [% |
    Page 46
3 s2 t8 ~7 d7 L: Q . {9 a3 G7 k: s2 _2 r" @
Copyright   2007 , D5 m/ j" p$ I
Aras Corporation.  ) }- g/ q8 d; U! C7 H- X, y; L0 ?
All Rights Reserved.
3 U6 K: N* [& A3 k' {VB.Net  2 p; a: y& d( z- \9 F5 i
Dim innovator As Innovator = Me.newInnovator() : x0 m5 y2 h  H6 a# \

* U* W$ e' l# V; {  O$ @" U' Set up the query Item. % G& ]: z3 `6 A9 F% u$ D5 _6 D
Dim qryItem As Item = Me.newItem("Part","get")
+ U1 K& a$ H8 f, L2 qqryItem.setAttribute("select","item_number,description,cost") 2 i) i) |9 I" e4 `, `, T
qryItem.setID(myId)
0 p$ X: Z! T, \2 N( \6 c 8 |2 _; W9 e# O) T" b
' Add the BOM structure.
: X- g; |+ \0 L4 j8 S% P2 FDim bomItem As Item = Me.newItem("Part BOM","get") $ C- K: f7 Q: J0 x) }
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") $ z: `+ V$ F0 C4 E! j( }
qryItem.addRelationship(bomItem) : G9 e5 F, U; o# O
. `0 f, K9 o1 ?% o! y& z6 R; u' R
' Perform the query.
: A8 J+ K8 W5 a9 f9 s, x7 s- aDim results As Item = qryItem.apply()   L8 X) Y# u- M& c% l
6 q  n) w* ~. q" G) w" G% b; V
' Test for an error.
+ o6 U: R6 P9 q1 |If results.isError() Then 8 b- z/ ?3 f$ D! @; W: r
  Return innovator.newError(results.getErrorDetail())
' S* \! j" |  w& sEnd If * [* I1 q5 s& }+ r  \* F1 g

( B+ `6 s* G6 S0 f' Get a handle to the BOM Items.
2 c; S! X9 H, ~# }, r9 z  cDim bomItems As Item = results.getRelationships()
7 P, w6 K: p- ODim count As Integer = bomItems.getItemCount() . s: [$ O! X) u+ D; ^' v8 Y" x
Dim i As Integer
% W* Z7 u# s3 J5 x7 y
1 R( ?2 r, O/ z4 t6 h$ l' Create the results content.
7 Y( A) G$ p/ Z8 s0 o, ^+ }Dim content As String = "<table border='1'>" + _ - G, d( N+ U- h4 b" w. B
  "<tr>" + _ : T" u& e5 k  g% z/ k$ h
    "<td>Part Number</td>" + _
4 @) @. o  s( c, P    "<td>Description</td>" + _ 2 `) ^' C/ l2 S2 k; R
    "<td>Cost</td>" + _
  N8 I; t( x" ~. Y    "<td>Quantity</td>" + _
2 X8 h9 Y% e! F2 d, v9 C7 c# T  "</tr>" " a6 C3 R) C9 F
; @$ y6 L6 w! k2 V  c4 s" Z
' Iterate over the BOM Items
$ |7 a0 h# L& e% U0 e. [: ^For i = 0 To count - 1
9 s$ I/ k" e7 C0 a* F0 k' Get a handle to the relationship Item by index.
5 U" {( b: _4 K2 `9 }2 o' t% e7 p. M  Dim bom As Item = bomItems.getItemByIndex(i) . M5 h) ?4 Y9 x! A! O

( E3 @+ K' B1 k' Get a handle to the related Item for this relationship Item.
3 \+ G  {7 T9 F6 u  Dim bomPart As Item = bom.getRelatedItem()
$ B( ^" R( p: J! S
" p4 D& a* ]7 F/ H6 P8 e. |  content += _ ! t7 j- N, Q, }8 b
    "<tr>" + _
1 H9 V4 V3 G+ m7 x/ B% I4 W      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
9 O2 M+ c0 O0 |) @$ t+ {      "<td>" + bomPart.getProperty("description") + "</td>" + _
2 A4 g  W' h+ Q* Z' t      "<td>" + bomPart.getProperty("cost") + "</td>" + _   W6 R; k7 [+ d; K  m3 n) J
      "<td>" + bom.getProperty("quantity") + "</td>" + _ / v. ~, ?+ ~1 L* h% Z8 Q
    "</tr>" 3 T% ^* y4 F2 H& s7 D3 K
Next & @6 v) I3 z6 S
content += "</table>" . U: H; n2 ]" T% c8 H  X/ @9 t6 W
7 ^9 f& H" r2 z
Return innovator.newResult(content) * n! I5 N8 |1 w: G9 m

3 O  Z4 T& Y) P
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了