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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
* t5 w9 N" J/ z" t, u8 V0 B- `To query for an Item and retrieve its structure you build the query as the structure
  _# l: }" o# Syou want returned.  Use the IOM methods to add the relationships you want and
! k) l5 r9 g4 i+ lbuild the structure in the Item.  The server will return the structure that follows the
3 T4 s7 s, x% t6 v% j6 l7 Erequest structure.
4 q* i6 ~  Q/ r+ C; Q. E1 `This recipe illustrates several related concepts together, which are how to get a set ; U/ u% \& B& j( ^& f
of Items from an Item and how to iterate over the set, plus how to get the related 6 r! X  x/ P2 u, L1 p! O- s; k* `
Item from the relationship Item. . D+ t/ l4 O' N! k  u1 t
JavaScript  
4 A) p! U6 s9 X1 Cvar innovator = this.newInnovator(); 4 l4 {  {# ~8 ^/ q- u# Q& d
- l, F( {: y( @' c. }4 {
// Set up the query Item. # }9 i2 e1 T% Z5 I
var qryItem = this.newItem("Part","get"); ' [  _' E: \' O- z1 E3 |
qryItem.setAttribute("select","item_number,description,cost");
# H& O5 E5 s+ z- yqryItem.setID(myId); $ d. V+ @6 ~( g8 S, Q
8 I2 C4 m# r$ v: k& S
// Add the BOM structure.
+ H$ _& W9 [3 o% U" l% Nvar bomItem = this.newItem("Part BOM","get"); ( M% _6 ]& r0 u" K$ }1 D, O+ m5 b
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); + {8 V! d3 k  `1 W: s- }8 Z
qryItem.addRelationship(bomItem); 2 O$ Y: G- I* ^& c6 \: U/ [

& i2 \9 F- I. v+ j// Perform the query. 2 ?( E- L& q  b/ h/ f" d$ [
var results = qryItem.apply();
, f4 t( c# N- v9 U; _ 6 Q/ Q9 C7 l% o' k/ r' Y5 Q
// Test for an error. , N2 C  q2 k, l& W
if (results.isError()) { % c) h& K9 ~& T( `8 B/ ]$ v" x
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); ' {. a, U# B, R5 E# e: u3 P
  return;
& \; x6 K' V+ s. h8 O" B3 E* u0 Q} 9 J! |5 N  q5 [# a  G: P+ D

' p: H% l' k$ ^& K% A1 d// Get a handle to the BOM Items.
3 w( ~3 T" [- ^; ?var bomItems = results.getRelationships(); 4 k) d+ s; F9 Z+ W# d& {
var count = bomItems.getItemCount();
/ R6 N* G4 o3 t% L' y+ y+ S" E
) U6 E- ~! _& y// Create the results content.
( x3 |2 l, L% e1 T+ rvar content = "<table border='1'>" +
4 K4 J& L6 M5 T, m  "<tr>" + " ?  i+ [9 j# `9 ?5 ?( u- a
    "<td>Part Number</td>" + ! x- r! M: Y  I$ V
    "<td>Description</td>" + . {+ K) @3 G- ^* w
    "<td>Cost</td>" + 9 l9 y5 r" D4 B$ W) t3 Y( C
    "<td>Quantity</td>" + - Y- n3 j5 ?4 Q- G& o
  "</tr>";
5 {5 i* _. }9 t* F$ |/ w1 m3 N
8 l1 O1 ~8 ~; g# H3 ]// Iterate over the BOM Items. 7 [) P, s( t0 F7 v- e, `" }! O* K+ \
for (var i=0; i<count; ++i)
' D4 c! S' ^6 }4 E{ 3 q/ w3 s# P6 @4 L
// Get a handle to the relationship Item by index. % d3 U9 \+ u$ O$ h9 k; ^5 Y
  var bom = bomItems.getItemByIndex(i); " @) k# M* q& ?7 n& ^# W: E
// Get a handle to the related Item for this relationship Item. 5 L3 h3 W0 V; L) \: j
  var bomPart = bom.getRelatedItem(); 9 g' j) g% A% B8 ]# H

: h. w) ?5 C% B# l( A! D* x  content += "<tr>" + ) _- M/ U+ \3 q& p. v
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
, J& H* Q* O$ v! k7 z7 j      "<td>" + bomPart.getProperty("description") + "</td>" + # t8 g3 V' h( g& S; ]# q, O5 `( Z  R
      "<td>" + bomPart.getProperty("cost") + "</td>" + 5 |9 _. r& w4 K: B  e
      "<td>" + bom.getProperty("quantity") + "</td>" +
. S% F! K# M7 o* e8 f4 w$ Q    "</tr>";
2 I" }# _6 A6 b- g1 h$ w- I}   J8 F! \' ~0 N5 q7 L9 j  n) v" \* r
return content + "</table>";
6 F6 ?: o% q- }, U5 g, c6 w5 z8 D% J" _" M% j
! j# `- g9 @: ^, I
( q# }  A+ Q9 D" {( J; e1 {

8 ?8 ?4 D: U+ h1 e/ C; zC#  ; r& j- }0 r( {( y/ R
Innovator innovator = this.newInnovator(); & p0 w# y! c" }! b  e7 I

3 Q, _2 j6 a; f  S1 T" w// Set up the query Item.
# _- J; y6 I) w* e- Z! nItem qryItem = this.newItem("Part","get");
  B4 O; t1 c. Y5 K0 n9 SqryItem.setAttribute("select","item_number,description,cost"); 4 K: o4 y! c6 b. F# j% G- T
qryItem.setID(myId);
& R- e# D+ K( V! P5 d ! |6 E. s7 {7 N0 p
// Add the BOM structure. - t) g3 i, _9 \  K- N& I
Item bomItem = this.newItem("Part BOM","get");
" G7 @& Q* }2 q- Q! M& tbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); - h6 K* c* C( ?+ R# `  f
qryItem.addRelationship(bomItem); / u1 l. H, S6 m5 Q8 K
3 B) w* l% u/ E
// Perform the query.
2 @" n% _$ j7 f: d* ]1 w; nItem results = qryItem.apply();
/ L- o9 ^  E( [& _" f1 ^5 A 8 y& K& t! o/ k# j
// Test for an error. 2 b& w* `$ h; N6 n
if (results.isError()) {
$ k  L' f5 S5 \7 ~3 p' z  return innovator.newError("Item not found: " + results.getErrorDetail());
8 _5 Z) N8 u! L} - s* c* X, E# Y9 t9 T# K) ~- k$ B

3 V# i/ K' _9 y# J) B: r5 F// Get a handle to the BOM Items. ' ]/ V# l% a7 x$ N1 |$ [5 z- |
Item bomItems = results.getRelationships();
. Q" @+ S. C6 y4 b& xint count = bomItems.getItemCount(); . Z4 P- y& M1 }
int i; 4 g( c% A; ], g$ ?  y7 I

, T8 x' \; r* N) i5 ], K// Create the results content.
6 E9 `% I; Y1 b% Ystring content = "<table border='1'>" + 9 y9 e! b7 g/ G% {( O! n
  "<tr>" +
* W! o, J4 |) h2 _! c( D    "<td>Part Number</td>" + : ]6 E) q+ q$ }# o
    "<td>Description</td>" +
0 S2 u4 O, [0 G' g+ B3 }# X    "<td>Cost</td>" + 2 t% f+ Z; H$ r* P/ C. P
    "<td>Quantity</td>" + ! G9 e! S& v" h: l) H' p1 G
  "</tr>"; ) S1 L0 B5 |1 D' A' _, f, {

3 d  }1 m0 Q+ G" S- A4 }// Iterate over the BOM Items. 0 T' T9 [' h  O- E# Z. P) y
for (i=0; i<count; ++i) 0 P, ?: C3 b# Q$ u; R2 I7 _0 ^
{ 0 H+ G4 L2 e2 A# c; t, ^. }5 m. F
// Get a handle to the relationship Item by index. ) i& [  L4 `% P: b! f( i1 b
  Item bom = bomItems.getItemByIndex(i); - y* ~; D( S7 i; @. L
// Get a handle to the related Item for this relationship Item. ! V. L0 ~  |7 G  B  A+ D
  Item bomPart = bom.getRelatedItem(); # i+ n0 ?- r5 N  {# ~! q# z
+ N; l: Y) n  Z
  content += "" + & {" |- F: j% V( @1 [; i
    "<tr>" +
* v9 L9 T+ [. [; T      "<td>" + bomPart.getProperty("item_number") + "</td>" +
% E, M- ^3 Q/ x5 [( s. }1 u      "<td>" + bomPart.getProperty("description") + "</td>" +
) d+ t( ~# n: ?' |& A3 S      "<td>" + bomPart.getProperty("cost") + "</td>" +
# i& v/ V% y: D6 l4 a% a- S# ~      "<td>" + bom.getProperty("quantity") + "</td>" + ) R& s, _- [5 T
    "</tr>";   b, g0 y+ v! x( Y9 M+ R
} / o' i8 Y  e0 x1 P9 V9 |0 J
content += "</table>";
* [8 B2 ~1 W( b5 ^2 C0 {& E4 a
4 Z0 T$ j3 B8 vreturn innovator.newResult(content);
$ N$ I' ^3 `% t  @( n; H5 u
, E$ v5 w$ K2 x, t) E* v

1 x* E3 V# @  @, N. w1 s; c
' x3 M' o3 F8 i2 a* G( @, I

, k* O& J5 N" o( L& Z4 H7 u
/ ~; M, ^* H; t7 K5 R
$ y- d8 j' I9 f+ W
/ l) J# z% X6 i5 C
    Page 46 ' Z+ X, o2 c+ r% ?4 t+ B3 u5 D9 b

# Q& v/ R( V& i4 K1 m7 YCopyright   2007   q( f6 f) R' i# l
Aras Corporation.  
, e2 s* S/ Z1 B8 f2 z4 hAll Rights Reserved. # x: E( G8 m/ K
VB.Net  : {- h2 g0 F7 [  {  l/ c( v
Dim innovator As Innovator = Me.newInnovator() ' @' W" ?% ]0 ~
, f, p" z# u, m
' Set up the query Item. ' Q6 z1 Z+ y" I: p/ M
Dim qryItem As Item = Me.newItem("Part","get")
: g; U+ h/ q5 x* d7 w4 PqryItem.setAttribute("select","item_number,description,cost") " @7 [( C% }. Y$ d6 s% B( w$ i
qryItem.setID(myId)
4 s% |+ k& X  \6 P0 x- i9 B- ?6 J
: V# m( h0 W- T% g6 H8 {' Add the BOM structure.
2 r5 F/ R$ I  s3 ~7 w0 A0 \7 HDim bomItem As Item = Me.newItem("Part BOM","get") # @- t: x, \( \
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") + M% C! h$ ~0 h# x8 Y
qryItem.addRelationship(bomItem) 7 Z# G) J( z1 z$ ~, M

2 D. d! b2 S2 T! F6 z' Perform the query. / A. \$ Y. ]" p6 a/ o
Dim results As Item = qryItem.apply() $ _# A3 ~+ _- l4 I0 I' [
" m) U/ ^1 S  Q
' Test for an error. 0 X, a/ u5 |% _! M7 ]: S
If results.isError() Then ; V* f% `5 p: t6 k  h
  Return innovator.newError(results.getErrorDetail()) 6 N4 r, b- |" G9 |9 W& [
End If + m7 X. T2 x- o0 }8 q4 q
% u7 A$ `3 v4 ?" X. {$ [' p
' Get a handle to the BOM Items.
# T% f% a5 B% h3 d3 g4 m" B- UDim bomItems As Item = results.getRelationships()
- K* t7 k; T" x- b6 t- h4 QDim count As Integer = bomItems.getItemCount() 9 \  e. O* o1 K0 F# Z' X/ h4 |
Dim i As Integer
& V; g8 R& C6 B
( [" e1 Q) W! a8 Q  _1 b' Create the results content.
/ R" y6 w* V* E- E& A- eDim content As String = "<table border='1'>" + _
* M  Z( I8 G* f* k! _" K/ I  "<tr>" + _
3 D! j0 q- f% b" g# V* F1 c    "<td>Part Number</td>" + _ ) L7 ?% X) b2 {
    "<td>Description</td>" + _
4 u- ?! {5 @* r; ?; S/ P6 I    "<td>Cost</td>" + _ # e6 p" K: _3 U1 D# X# s8 X  f+ f
    "<td>Quantity</td>" + _ ' B- c* v* E3 v, ]  v# u
  "</tr>"
  E- c" F+ r. T- N% s) _1 f
7 |7 J+ a% D2 M; g+ m$ J( }4 }' Iterate over the BOM Items
$ \# K  O) D9 ]9 h* uFor i = 0 To count - 1 : e* @" x# L- v- a8 s  L3 e0 G* A
' Get a handle to the relationship Item by index.   X2 Y6 T2 _) U; ~
  Dim bom As Item = bomItems.getItemByIndex(i)
, w) ]/ ?3 o9 _4 q" x ) Q  f( [( g3 M5 o8 I# T) N8 B2 z
' Get a handle to the related Item for this relationship Item.
/ V6 ]) ^5 u* D: Z5 i+ z  Dim bomPart As Item = bom.getRelatedItem()
* \9 C$ E( \1 F( B" T0 h
9 [3 `0 M4 w  w+ C, m5 s+ m0 s  content += _ * k1 Q; p  [" ^% |6 m* y
    "<tr>" + _ 7 o1 y7 ]6 Q# u1 U9 H4 D8 x
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 8 I7 R0 r' B5 q  h
      "<td>" + bomPart.getProperty("description") + "</td>" + _
: C2 l) D; [$ V      "<td>" + bomPart.getProperty("cost") + "</td>" + _ . q5 q5 N/ a5 Q2 q5 c* o
      "<td>" + bom.getProperty("quantity") + "</td>" + _ " O! U' o7 x& i* W! X5 c1 h( F
    "</tr>" ) E# ?7 i$ u% Z* P! d& M
Next 1 M( B' ?9 S, \& Z
content += "</table>"
/ a/ e8 u/ Y0 v- i$ q* m + a. p& k* e' `6 S
Return innovator.newResult(content) # O4 p/ c5 E2 f* ?' J
, d! B. r" [9 Z; U$ p2 \
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了