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

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

[复制链接]

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

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

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

x
Technique  ' R9 v  Y3 Q2 u
To query for an Item and retrieve its structure you build the query as the structure
  T9 _& V$ p4 f$ I. A! t1 P) lyou want returned.  Use the IOM methods to add the relationships you want and
& C9 _, n+ v; v% c. }$ T. y$ ]build the structure in the Item.  The server will return the structure that follows the
% X% e" p& g. h+ prequest structure. ) V9 o+ F  l1 n' ]) u. q! g
This recipe illustrates several related concepts together, which are how to get a set
: ~* o9 d$ q2 g0 X4 d0 Dof Items from an Item and how to iterate over the set, plus how to get the related
5 O% g* b+ A+ K9 ^Item from the relationship Item.
) h+ q) x% s5 {$ g, B4 G9 bJavaScript  % v6 D: ]+ J1 i- Y9 S& d# r
var innovator = this.newInnovator(); * n# ~3 }- W/ G# |9 }
% b3 K: r  R  l. W- Z% E& x
// Set up the query Item.
: a% Z9 B+ n6 V( u) [- W2 Bvar qryItem = this.newItem("Part","get");
# D/ ]( W% d4 U, m  H3 BqryItem.setAttribute("select","item_number,description,cost"); ) t7 _1 z2 K& T
qryItem.setID(myId);
/ q1 e& Q$ ~+ |( S) h
0 \- K7 Q8 P4 d$ D/ i! N// Add the BOM structure.
2 [3 p/ B) q, ]% k+ Z' Kvar bomItem = this.newItem("Part BOM","get"); 5 {. q, Y6 Q7 y6 q3 m
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");   Q0 [1 D0 m) B# k) i# A) I
qryItem.addRelationship(bomItem);
( E- Z1 M/ E7 b& O4 C. U
( b" {- e" }9 u, H  D6 o. l// Perform the query. $ i2 @8 r* c# p( i% c" ?, O
var results = qryItem.apply(); 4 n) R) i* b$ i% v# N
3 }) Y0 w7 j3 Z; L% F5 ]: `
// Test for an error.
* Z2 u& x: v$ V7 Yif (results.isError()) { % }0 G: U/ L) r( U  m9 l9 D
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); # U# Z' p; u5 V$ L4 b3 V
  return;
/ |: J2 N. T, X- ?} 3 X$ |& ^5 ^) h& i, e9 M4 c
# {  `8 H- A7 R2 F% X2 o
// Get a handle to the BOM Items.
  Q$ n- u1 f2 P) d: n5 R. {8 m& mvar bomItems = results.getRelationships(); & _6 X% U- E% C% p% s6 L  d% Z
var count = bomItems.getItemCount(); . V# O" Z% ^7 r& T4 V6 m* B4 V

- Z+ M( b, y# _: t" ~, F& \// Create the results content.
/ T- X3 j. p5 G6 ]9 S. [( z5 s  {1 m- O6 Xvar content = "<table border='1'>" + 3 ?5 n7 C2 H5 d9 [; u
  "<tr>" + 7 \7 }6 |& r4 I, u
    "<td>Part Number</td>" +
' i$ N9 w" b. _# v. I    "<td>Description</td>" + - W+ o% D: [/ n: ^
    "<td>Cost</td>" + + n  J, S  l& `, e+ \) s
    "<td>Quantity</td>" + $ T" a, @; }5 z) ^2 ~
  "</tr>"; , q- ~) r' o" Q7 _

6 t( X: q9 `4 o; X// Iterate over the BOM Items.
5 |: s6 x. L' u: A8 [for (var i=0; i<count; ++i) " X7 O5 R' L" x
{ 8 x6 C( A( V5 |4 z2 p
// Get a handle to the relationship Item by index. 3 Q; l& J4 i' y8 j" B. y  R
  var bom = bomItems.getItemByIndex(i); , M: z2 J& [4 M  z
// Get a handle to the related Item for this relationship Item.
  f+ Z7 u, M8 o! p3 p  var bomPart = bom.getRelatedItem(); - i% P! c5 x  Z+ u
& E( I4 U  L8 h, m
  content += "<tr>" + . H3 X9 @5 ~8 y" B/ K
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
" Q: x$ }6 N; `" f/ n      "<td>" + bomPart.getProperty("description") + "</td>" + 6 z6 \+ N! l6 a: d3 Z5 J6 H8 l
      "<td>" + bomPart.getProperty("cost") + "</td>" +
% W+ J) T8 v, N. O5 r. a8 u' U0 ]* |      "<td>" + bom.getProperty("quantity") + "</td>" + ! D# b+ l# ~0 ~3 y9 `# r3 q  i! X
    "</tr>";
: g: o. S& s7 m}
0 p, J/ Z- O6 z9 r- r( b  wreturn content + "</table>";
) h5 X4 Q% G2 A% s2 `: _0 ^( W
7 A: C) Q- I' q$ n" a- @+ R

* v& Q9 _7 r7 g' W" u
0 D" i3 L  R( |7 l8 n/ L7 G
8 p% _2 M% p& C" t
C#  2 Z6 ?0 h4 |2 h( g- u/ r# ^
Innovator innovator = this.newInnovator(); 0 B0 G9 I; G* X+ A

# b9 Q  ?4 O3 `" W- X// Set up the query Item.
$ d2 M, ?5 |' r* @8 nItem qryItem = this.newItem("Part","get");
( \9 v+ I0 j! Z8 C1 NqryItem.setAttribute("select","item_number,description,cost");
# S* x3 k+ a: z$ z1 V) ?. mqryItem.setID(myId);
4 a. b& a; ?! B* O: l 7 g* E+ z3 z! t- B% l
// Add the BOM structure.
8 f3 N- H/ H/ P: y* uItem bomItem = this.newItem("Part BOM","get"); , y7 A7 Q: ^) U5 \& o
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
9 f) c  B4 W8 s4 ]qryItem.addRelationship(bomItem); 9 ~* T- I, c) C3 t, o* X  G- ^
, @4 X9 ?: Z1 E' e5 K& f: w" Q% l
// Perform the query. * v% i1 W* @8 R8 T. {1 }8 y/ Q
Item results = qryItem.apply();
3 q+ c6 e! U) O, I
  Z  ~  |8 ]* N; y+ M2 h// Test for an error.
: v5 }* o+ h6 h- J9 m& P+ K+ f! t8 Mif (results.isError()) {
- T& U3 z3 a( ]0 i, f  return innovator.newError("Item not found: " + results.getErrorDetail());
( S9 m9 Q% l) K1 z1 Q9 ?$ |) q}
* O) f6 U+ j4 g9 P& O! P  A2 A * w: B/ n+ _, |4 O3 S: `8 [9 v, F3 K
// Get a handle to the BOM Items.
$ q& Q; c1 T/ Y7 N+ j' a, q5 [Item bomItems = results.getRelationships();
+ D% h; X* X) ?! u$ ]- Hint count = bomItems.getItemCount();
% w: e; D2 g/ L, b- Hint i; . y* X3 v9 n8 j; ?& l; q
3 I- k  g. ~! e' Y& Y0 e& ~
// Create the results content.
4 A: n5 v( S) s( S* |- `. gstring content = "<table border='1'>" + + d5 e: P( e& }) Q7 z* ~
  "<tr>" + ! s, y2 D4 C! h; |2 L3 @' j0 B6 y1 J
    "<td>Part Number</td>" +   `8 a* P- C8 B6 d% P
    "<td>Description</td>" +
4 D% F& H2 S) t- b    "<td>Cost</td>" +
6 u9 @. V- q, c: L' U- p" L9 {    "<td>Quantity</td>" +
1 q' @7 ^5 {% p2 |2 z( C  "</tr>";
: j/ w& v7 w# H7 G
1 u; s# }9 Y9 {3 j+ `// Iterate over the BOM Items.
. f" G; o" P" p% H3 Gfor (i=0; i<count; ++i) $ N- z) H6 S5 f5 u2 h7 {( o/ ~
{ & }% d0 p9 l: \4 w
// Get a handle to the relationship Item by index. 0 [6 j: k9 X- @. A: |+ M4 U
  Item bom = bomItems.getItemByIndex(i);
/ b6 Y( |% _0 S3 ?1 i' n// Get a handle to the related Item for this relationship Item. ) J0 y' ~; V* G1 s5 H0 s
  Item bomPart = bom.getRelatedItem();
) H* D2 ]9 ]0 r$ `. j, L; b. ^" \ * ^6 c% [. m* s# p+ e4 e9 d, [
  content += "" +
1 m3 j- O3 v+ v    "<tr>" +
1 k4 f3 L. _' \. H& U- v      "<td>" + bomPart.getProperty("item_number") + "</td>" +
( H8 L% d/ k# R3 u7 u- L' c      "<td>" + bomPart.getProperty("description") + "</td>" +
" x( y. W1 w1 a: U* C      "<td>" + bomPart.getProperty("cost") + "</td>" + - j5 n1 K8 _  s1 z* D9 K
      "<td>" + bom.getProperty("quantity") + "</td>" +
& |) |% H- }" z' R3 f1 d    "</tr>"; 5 y' ^; _2 j: i9 [* h
} . @/ K9 O- \7 g
content += "</table>";
/ T8 s& T9 l" L" M, I4 b6 O  G
* T& Y# N9 k( S3 J2 z' N" O2 K, Wreturn innovator.newResult(content);
; Q9 Y. _2 R% j0 `9 n. C0 y2 l3 [5 Q! B9 S: s8 U- ?
6 Y  }" U; J" U: j) r5 E
, Z! y  ?2 ~6 O; D- E0 G% j: e2 |

, X# a, @+ [2 K( Q) _
, _" r4 H4 r1 J( z1 J+ ]
: Q7 o8 S& ^+ m7 _
+ R9 s6 B. C- G' F+ I0 z/ M& N
    Page 46 : j$ j6 Y: I; z

2 i7 {! A8 N: K. k$ K- dCopyright   2007 ' ^5 b- a$ X  a+ Q$ Z4 i. A/ V( \
Aras Corporation.  $ R/ q' @+ z" V( e7 F# M, E
All Rights Reserved.
! }4 Z, F9 H0 c3 @VB.Net  
% o/ `4 u/ e$ ]& YDim innovator As Innovator = Me.newInnovator() & D: C  R3 M  M) a
+ l2 Z3 m1 [9 [5 w- D9 G$ a9 T
' Set up the query Item. 5 W2 r4 e) Z# t4 D
Dim qryItem As Item = Me.newItem("Part","get")
1 C; h( t9 @+ b: U/ k5 N4 R8 Z4 N4 wqryItem.setAttribute("select","item_number,description,cost") 9 {/ R. H! t$ z
qryItem.setID(myId)
, {) ?- |3 c# x2 J) ] 6 u- c$ x. b& F+ _% p
' Add the BOM structure.
  H7 r9 u( ]3 \- w: V% ]. ~Dim bomItem As Item = Me.newItem("Part BOM","get")
# [9 W7 C5 `- ]1 [0 mbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
+ x' R3 P3 s2 I, }* ^qryItem.addRelationship(bomItem) 4 p& h, T8 [! E# @+ O; W
5 ]8 l' v/ |1 j5 o0 K
' Perform the query.
# h: }7 L# x" J2 A' L' j; y; HDim results As Item = qryItem.apply()
: r8 p* j7 e% h5 F8 @$ z - j/ n! K2 n/ C# K) l% W
' Test for an error.
: U0 [6 \8 k- K( kIf results.isError() Then
9 x7 x: s' @1 i" G$ \  Return innovator.newError(results.getErrorDetail())
/ {( N5 s8 z, v2 ~End If 7 K3 X; r* q: R$ _9 O! ?. s! ]

0 F* V( T' _: [) ?' p( i' Get a handle to the BOM Items. 9 H' J" E. [7 _6 L
Dim bomItems As Item = results.getRelationships()
, q5 v, P& O* G$ b4 Z4 H# xDim count As Integer = bomItems.getItemCount()
" ]9 n+ q9 H8 u9 e' u  Y' ADim i As Integer & \$ O1 n% G2 W! _, T. G+ k0 V
4 |* }) J+ n! E  M( [
' Create the results content. + W" K0 r, K0 A* I. Z" q3 o& e
Dim content As String = "<table border='1'>" + _
2 j3 c# S. C0 X  A  "<tr>" + _ 0 b6 {: e0 L* G- k( R5 P
    "<td>Part Number</td>" + _ 6 V5 H4 r# S2 D. l1 ^$ \% |+ w9 v
    "<td>Description</td>" + _ % U, E. O! O4 p- Y$ W1 A. \3 `
    "<td>Cost</td>" + _
- q% q# g& h. H( \6 f7 M8 l    "<td>Quantity</td>" + _ 8 s0 R, Y6 {" n! F& a1 }8 x6 |
  "</tr>"
% B3 ]1 O  ~) T) I* A% b$ k
1 c9 @7 g' A! z8 c' m' Iterate over the BOM Items
1 z- R; J# ~9 J" J' [/ f0 P0 F" KFor i = 0 To count - 1 8 A) W# E# ^. b& t
' Get a handle to the relationship Item by index. 1 F2 r, f$ b* {+ n( u1 `: U/ i
  Dim bom As Item = bomItems.getItemByIndex(i)
3 E- {% A5 D# }, ]; U   e* ?7 b/ A+ r8 T, b2 F
' Get a handle to the related Item for this relationship Item.
' z1 t& m) O& s  U0 I  Dim bomPart As Item = bom.getRelatedItem() ' O6 Z& `1 M6 T% J9 J5 {6 N* n
" M/ j, i5 s1 ?# H4 Q! h
  content += _ : E! n3 ?# `7 @. }# u
    "<tr>" + _
* o0 T" _  ?& @+ t( W      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 M& I) |3 D2 Q
      "<td>" + bomPart.getProperty("description") + "</td>" + _
; J! t- N% o4 r  ?& A* z7 L, N      "<td>" + bomPart.getProperty("cost") + "</td>" + _
9 g! R# Q+ t" j& i* ?6 e0 \4 `' b      "<td>" + bom.getProperty("quantity") + "</td>" + _
; X1 z0 U$ G  v/ I$ ?. u5 q    "</tr>" 6 G8 q- s0 m7 e# O0 v- @7 e
Next
: b4 B! H3 y8 P* A. S3 Fcontent += "</table>" ! h' B" F; ]4 S
9 U* c; }% d9 G) r; c
Return innovator.newResult(content)
% i, W/ M% X6 X* z/ L, g# q
7 x' W" b- ?# g$ M' q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了