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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  % |2 t8 l1 @5 @" r7 g
To query for an Item and retrieve its structure you build the query as the structure - M3 c& Z3 D$ n- C3 [
you want returned.  Use the IOM methods to add the relationships you want and
( M7 g) s* ~4 |! m$ P3 Y2 n  ~build the structure in the Item.  The server will return the structure that follows the . }! ~4 s1 g2 L! }. a
request structure.
  v: l! G7 A- [" y# N" I+ UThis recipe illustrates several related concepts together, which are how to get a set
& g$ G: p9 i/ E# ^1 p8 pof Items from an Item and how to iterate over the set, plus how to get the related 6 K2 R; K8 Z( |: B0 K5 B  s
Item from the relationship Item. ) o) l; v7 L3 ]1 Y: J
JavaScript  
5 C! f' s, p  J5 x* ivar innovator = this.newInnovator(); ' p. t( w$ m9 O9 ^' H* G* X+ A

& u6 q# f1 L! ?/ v/ h. g0 |// Set up the query Item.
- U5 x5 Q- {7 ^; q. o" d7 _8 N$ ]var qryItem = this.newItem("Part","get"); , X& l; ^) I; u! N# [
qryItem.setAttribute("select","item_number,description,cost");
, [5 Z6 W# |0 G) @% K, {0 _) x& zqryItem.setID(myId);
; g3 v8 Q/ [; Q( G" o% M 0 Y. C/ j. X  u) T$ Z/ x8 b
// Add the BOM structure.
: m2 a8 P/ P! O4 B) kvar bomItem = this.newItem("Part BOM","get"); ) _4 J. s& a" A" x: M: I
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); . @* a* [& Z8 r0 T: T8 |& m
qryItem.addRelationship(bomItem);
1 q1 ?4 e+ h$ z/ C2 \  I- f, ?3 A # U3 A/ k! `$ C% Q9 H9 G
// Perform the query. ( |5 C& A) s! y5 \" F/ Z
var results = qryItem.apply();
; F4 z! g0 M5 l6 `' s: ]* `& G
# V# H. e. r" h7 y9 K3 a// Test for an error. ) k) o6 n- T1 k: r( h: T
if (results.isError()) { & L- E5 T3 {3 d1 b: X6 S
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); ) S, }- l( Y* A5 {
  return;
6 s+ |3 B: R5 M+ E) i. J1 `}
, P9 z% F9 I' \
/ M' P. f% n6 k, m6 g; W2 q// Get a handle to the BOM Items.
1 _4 F$ t  z! ?% d; N" X5 d. D. G/ zvar bomItems = results.getRelationships(); . D" V! j2 ^6 Y  R# N: |% F
var count = bomItems.getItemCount(); ; c$ f9 R* @& ]# y* P

' k; v2 }$ P7 A! ?4 @7 }// Create the results content.
8 r! ^" d2 |# I5 z! |. Kvar content = "<table border='1'>" + ( D# I) }- c  j" L9 J2 N
  "<tr>" + % q) D2 d0 S& r; e+ S
    "<td>Part Number</td>" +
( V4 U# }# z- w; c    "<td>Description</td>" +
" l  C( {$ X# n' K    "<td>Cost</td>" +
% I  [: p, t/ [) n    "<td>Quantity</td>" + ( B0 Q2 \% r+ D" `/ U
  "</tr>"; + r5 M8 c$ U4 ]% U, ]
# q8 w3 T4 _5 \: {4 ?* s; p
// Iterate over the BOM Items.
8 ^+ A& U. r4 Tfor (var i=0; i<count; ++i)
) L& ^7 F  L& C% A6 M{ : I0 p6 z  \( I, A
// Get a handle to the relationship Item by index.
! A( N3 B! N4 R  var bom = bomItems.getItemByIndex(i); 2 ~: t' m5 W# B7 ?
// Get a handle to the related Item for this relationship Item.
+ t" {1 k( G: a6 I# `% `1 ]) `  var bomPart = bom.getRelatedItem(); ) e2 ~5 m3 o  E' c& O. M
- e% T1 h, Y1 w) a% I# X2 T
  content += "<tr>" + ( |/ R4 }0 g) D7 p9 z1 d' N0 k
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
4 N. k* C6 j; P      "<td>" + bomPart.getProperty("description") + "</td>" + ! H+ M: E7 _/ G5 f# t& {5 z6 ^
      "<td>" + bomPart.getProperty("cost") + "</td>" +
8 h' G  \7 V# z% i5 G0 i      "<td>" + bom.getProperty("quantity") + "</td>" +
5 l  i1 W7 n3 ]3 K. r; H& \' p    "</tr>"; + o+ `8 @3 P/ K, w0 e
} + I) y) s- l/ e7 `( x) q
return content + "</table>";9 c! \; U  M9 ^9 Q

4 t0 s$ B) S  k! W! L

7 `- L( V5 q% I3 L. W; Y! g; X/ M: i( I. b/ r$ f

) F/ j* f/ ~+ a2 \C#  
% p+ X9 ]2 v- x9 IInnovator innovator = this.newInnovator();
/ x3 J% n) s: U, a4 ^
( `3 ?8 ^  v! u// Set up the query Item.
7 K; D1 a/ |# e. GItem qryItem = this.newItem("Part","get");
1 g6 b1 R2 [+ ?0 i  m, MqryItem.setAttribute("select","item_number,description,cost");
" A1 z3 [1 B2 w- B6 ^qryItem.setID(myId); : g. z- [3 y' |! Z
- u% z; [7 f+ ]
// Add the BOM structure. # j+ c' s$ b  q% s
Item bomItem = this.newItem("Part BOM","get");
1 Y0 v$ ^5 G) x. _5 o6 N9 cbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
, Z2 f2 ]. {5 z7 u- aqryItem.addRelationship(bomItem); - j/ Y# Q3 P9 m* T* }8 _

! H# ?. R6 m' e2 C9 z/ W// Perform the query.
/ I9 S- y# {" z$ P! D7 w  _Item results = qryItem.apply();
5 T) o: P( d7 Z' e" @' F + Y3 U' s; R$ Y6 Z  `  n! k
// Test for an error. 7 C+ H5 V7 j) G- R4 r5 C, T. b; B
if (results.isError()) { % p1 a4 k! M. L
  return innovator.newError("Item not found: " + results.getErrorDetail()); . b5 a# X( `' W
}
& u) R9 d% H  e# U
7 V" X1 t9 Q# b, D! r* @0 A  U// Get a handle to the BOM Items. 7 P4 ~! @+ z/ A8 t8 y
Item bomItems = results.getRelationships(); 6 @* b# D7 x6 F1 O; y
int count = bomItems.getItemCount(); , U4 ?: t9 {* `" Z
int i; " l! _, r9 r2 s# @9 y2 {+ V
  n2 S9 Z% i$ N/ A6 W# D
// Create the results content.
4 M' x6 o6 V4 l$ r+ V+ w1 Y: Cstring content = "<table border='1'>" +
$ _8 a5 |5 N5 c3 x% y* J  "<tr>" +
7 |) ?7 T0 B6 a. ^% [! ]/ C    "<td>Part Number</td>" + " v- i0 ~, b* N) K
    "<td>Description</td>" +
+ O: c" b# m7 |3 s& t1 P. @    "<td>Cost</td>" +
3 L3 d) D2 ]' Q% h    "<td>Quantity</td>" + $ W: c# [) F3 ]2 k
  "</tr>"; 7 X. F+ x, N' Z3 ?% g

5 ]  H6 u! i+ K) {" S// Iterate over the BOM Items.
: \/ j3 }& {* ^' dfor (i=0; i<count; ++i)
" h# _; g# {( \+ `{ # D5 V; ]+ [" s' h& W3 _( _7 s
// Get a handle to the relationship Item by index. 9 t/ g( ?* d0 {  j
  Item bom = bomItems.getItemByIndex(i); & P$ ]6 v8 f- j( I; b" u
// Get a handle to the related Item for this relationship Item. ' Z6 V5 H# K( g" \
  Item bomPart = bom.getRelatedItem(); 9 C. J) K# c1 J% Y" K, Z% h
2 F" @6 b6 P! m5 n
  content += "" +
& R) y( b. }5 O) V8 A  P2 Z" s. s    "<tr>" +
) G% X' V7 Z+ [; t1 ^      "<td>" + bomPart.getProperty("item_number") + "</td>" + 3 m4 `% B1 i$ p2 p
      "<td>" + bomPart.getProperty("description") + "</td>" + ) |  i( S. C* v. `+ U' b; m
      "<td>" + bomPart.getProperty("cost") + "</td>" +
& @9 _: w1 V# t5 z2 V, W8 z' S      "<td>" + bom.getProperty("quantity") + "</td>" +
$ N' D% n% r6 q; A' N" _    "</tr>"; 6 A, s% T& B1 ^: x  F# d6 A
} 8 z$ n# O% p5 e! r9 \4 w! t
content += "</table>"; 1 h/ ^8 c- J3 g: w8 j# w; c- H

3 c3 A: @, S/ a) F; oreturn innovator.newResult(content); " F& c, ^0 x; k8 i. L0 d1 N
* k2 g  w/ O, O

5 ^4 ]- t1 ~6 d  j
, K# W7 P4 I) ^/ V1 m# ~

; H0 T) R7 Y7 p: W4 K
( d5 d, ?% R/ d+ N: `

; S1 p: ?' u; ?* T
, F& z( d5 `/ i% g; Q. e# W( ?6 z    Page 46 7 D5 S! V: N/ w* z& c5 A
1 O1 M5 q/ s# ]& Y
Copyright   2007
% V) q$ V% o5 x- ~Aras Corporation.  
7 I$ u0 U1 D7 @1 jAll Rights Reserved.
( p. c3 w  k  Q4 a3 O6 b4 XVB.Net  
0 \; j; I. I9 m  ~3 A( E# WDim innovator As Innovator = Me.newInnovator()
! @# i, H, ~7 S+ p) ?) s ; {/ z, e) f7 w) f. w9 z
' Set up the query Item. * n6 J" r# O# t+ R% t6 I
Dim qryItem As Item = Me.newItem("Part","get")
6 F6 G" {; H% FqryItem.setAttribute("select","item_number,description,cost")
5 Q! O) _% V6 d' P: gqryItem.setID(myId)
  B5 |* ?) F3 T9 E& T8 P
- B7 g& e/ w( Q% k' Add the BOM structure.
( G' n' M$ ~/ w. Z  DDim bomItem As Item = Me.newItem("Part BOM","get") # i1 |1 @$ U4 j
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
! ?# h3 O) n' ?* dqryItem.addRelationship(bomItem)
% z4 @, Z" P/ Z3 s, p- \ 5 g  X3 V3 {1 d: C
' Perform the query.
7 F. k+ d8 k. K; `7 S1 J8 X. [Dim results As Item = qryItem.apply() , a: n0 Q; W+ d/ n
: d; S) d# y  o3 c
' Test for an error.
& ^5 j) P! _* ?$ K2 ^4 UIf results.isError() Then
/ }5 ?6 P9 f3 S0 f  t! @! u' M8 n  Return innovator.newError(results.getErrorDetail()) + G- `# x4 r" L4 O
End If ! d& m: ]5 e2 H: x- P' k/ v
2 i- Q8 Q# [- t' H
' Get a handle to the BOM Items.
& n( X2 H% L& V! H: S1 V& N5 mDim bomItems As Item = results.getRelationships()
+ B. p5 w8 J5 l7 W$ o* |1 UDim count As Integer = bomItems.getItemCount() : s; H3 ?( }) P) Z
Dim i As Integer
4 F: f+ o1 g/ z
( `: r* A9 k0 ?. N0 f, l1 {' Create the results content. : o1 B3 |7 k' ~3 K( x7 P! j4 Z; a
Dim content As String = "<table border='1'>" + _ 9 ?7 v% [, |3 _4 G, D' F! h  @  r6 n
  "<tr>" + _
) `) a/ [' I) k9 I2 j) L    "<td>Part Number</td>" + _
, C( X- P0 m: v# ~' Y1 m3 h! T: P( s* l    "<td>Description</td>" + _
4 V, q  @0 M7 X% n1 K( I0 _0 ]    "<td>Cost</td>" + _
) T& }5 T5 K/ X+ D" j, Y) `' q4 @    "<td>Quantity</td>" + _
; a7 h6 T' M" L8 [- z( ?3 }/ B  "</tr>"
" p7 `, J% v' T5 }4 P 0 x; Z# X/ r7 m+ `# Q5 U2 D( I* Q% c1 x4 w
' Iterate over the BOM Items $ _7 c7 M$ W! S4 U6 g, X8 B0 J
For i = 0 To count - 1   m% d: N( f5 Y
' Get a handle to the relationship Item by index.
# w1 J" i# x6 ?  Dim bom As Item = bomItems.getItemByIndex(i) " `0 s9 w5 [/ _& q) }

- J; K/ L8 M0 O1 j! G9 `' Get a handle to the related Item for this relationship Item. , D5 ]& G: ]( R8 A7 V3 G
  Dim bomPart As Item = bom.getRelatedItem() - @( l8 ~" F- r; i4 C
& c, K, }9 m. g' e2 B; [. O
  content += _ ( }- t1 b9 S6 [" h
    "<tr>" + _
7 y9 _% Q$ Y" w3 Z4 C      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 7 U1 n( b) P) _. K0 G; L. v
      "<td>" + bomPart.getProperty("description") + "</td>" + _ % E6 _' B3 a  \% N, ^8 _4 y
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 8 t% D, U- g3 L5 I2 c
      "<td>" + bom.getProperty("quantity") + "</td>" + _ / ^/ c* d# d0 `7 F0 T+ Q
    "</tr>"
: o- M4 Z: I. MNext 7 X  \6 [6 g1 V/ a" p* ]3 |
content += "</table>"
0 |: A" y& D/ `
0 o3 S" n% j  R% yReturn innovator.newResult(content) , b7 Z* b! ^& I9 i1 [( a

) n; t, ^, S# F: r! i$ R" {
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了