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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  4 e  B: F* V- B
To query for an Item and retrieve its structure you build the query as the structure
) g: Q  Q" J  F. P2 ryou want returned.  Use the IOM methods to add the relationships you want and % n6 e0 t' n; M. a# I! O; i' ?
build the structure in the Item.  The server will return the structure that follows the
. G1 a- p4 l0 U0 M4 Orequest structure. 4 w( L% }1 x. S
This recipe illustrates several related concepts together, which are how to get a set ( Q  [4 H, M& s) t! t2 Z
of Items from an Item and how to iterate over the set, plus how to get the related # D4 R* k) E2 ~5 k" @
Item from the relationship Item.   v% F' n( o7 T( _- q1 j( G
JavaScript  
2 o7 H/ e* T$ ]7 r2 e) Pvar innovator = this.newInnovator();
3 [+ q, d. ]3 C7 t; p! n7 p ! R' O* G7 Q4 R, z% o
// Set up the query Item.
) c2 q- C' X6 ~var qryItem = this.newItem("Part","get");
7 C/ T  k+ j% ?4 QqryItem.setAttribute("select","item_number,description,cost");
1 m* d% g. o- K* \' \4 h& t% qqryItem.setID(myId); + _+ o: t, {, X- G, p
* f4 G7 l# |$ r$ k0 A6 m. E3 W
// Add the BOM structure. ' Q2 r- T, U0 a
var bomItem = this.newItem("Part BOM","get");
) c1 f+ ?' c$ D# k  V5 \$ p9 w2 KbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); + v9 ^% I6 I$ m  y
qryItem.addRelationship(bomItem);
0 m- @5 i6 r4 B& L+ E0 P# F, I0 ^
( i# C! G9 P9 `9 R/ v// Perform the query.
" j' m% C5 L8 Q. l6 ~. J% V2 dvar results = qryItem.apply();
4 X9 `/ p4 d& e ; u+ W% F$ K3 [) F) C
// Test for an error.
, [0 e) R. x4 yif (results.isError()) {
8 w2 Z0 t! W# z3 i7 K  top.aras.AlertError("Item not found: " + results.getErrorDetail());
3 H0 k8 @. S" c  ]" g! a8 Z  return; ' a! W. a" Z, x) Y
}
+ |- M# Z$ I9 @4 J7 W7 R* o
# F8 w! C  {. |/ ]( M/ [// Get a handle to the BOM Items.
0 F2 z+ H, E2 [3 r8 Y9 Lvar bomItems = results.getRelationships(); - n% j, w# p+ j$ T' M6 ^# t0 T
var count = bomItems.getItemCount(); $ G1 d# p# s* u

0 c, c! o5 l9 h" }5 e) B" F// Create the results content. 5 i& {9 i% {% a% T. J; W5 V' _
var content = "<table border='1'>" +
: u5 E% m9 s0 T  "<tr>" +
5 M$ N, P& Z6 \5 g) L    "<td>Part Number</td>" +
( U! u1 s+ Q% m% y! e    "<td>Description</td>" +
. u5 U% l, Q% j    "<td>Cost</td>" + " U8 D7 n' Q- j" G
    "<td>Quantity</td>" +
, ?9 X% I3 G% N. N" m! J  "</tr>";
' y4 I3 X7 T. x! J+ n
8 e3 C( I( n  B- O7 |// Iterate over the BOM Items.
+ A1 M) b9 @2 `$ O, Nfor (var i=0; i<count; ++i)
7 s" N1 J" B( e1 _$ V3 w- g{ ) C6 p9 ~" v3 T
// Get a handle to the relationship Item by index. 2 |9 `- j9 |% P; K1 E1 d
  var bom = bomItems.getItemByIndex(i); " I( k/ U  m+ \5 d* n
// Get a handle to the related Item for this relationship Item. ( |$ ^" t" f4 ?% b, f  U
  var bomPart = bom.getRelatedItem();   F+ H/ e/ t, U0 p/ H

4 F/ g. z! v' S9 r+ z7 _' K  content += "<tr>" +
6 R& E1 n0 x% S- d4 g      "<td>" + bomPart.getProperty("item_number") + "</td>" + . P  {8 Y) p7 q" d1 f- Y
      "<td>" + bomPart.getProperty("description") + "</td>" + 1 K; Z6 L$ d6 O: Z8 }0 h
      "<td>" + bomPart.getProperty("cost") + "</td>" + " F) [2 L/ P: e" \4 {% T6 R
      "<td>" + bom.getProperty("quantity") + "</td>" + : R( J* K  B( i& Y
    "</tr>"; 5 `+ j% e7 v8 o, l9 h
} : l' _, o. V1 y) E' Z
return content + "</table>";
# l# j; H; T- ~
' p2 S. o6 V8 U7 w! O

& j$ ~5 |3 u- l0 e" k2 A
; I9 [/ B1 J( |- h

: {- J' K$ l; `+ dC#  2 c( f9 V- z% R$ G, O
Innovator innovator = this.newInnovator();
6 Y7 V, Q+ X, b6 T( t
; c1 k! S  s1 ?8 v' v// Set up the query Item.
" X3 M4 L0 f3 |$ `& ~  Q2 p' Z( fItem qryItem = this.newItem("Part","get");
1 T5 `" j6 g* M& m2 W. ~qryItem.setAttribute("select","item_number,description,cost"); 4 Z- _. ^& o, i8 S9 Z4 Y
qryItem.setID(myId);
: X1 [+ l! @+ U: \ 8 `" K7 J; x. J! v8 S! |* w# X4 Z' z
// Add the BOM structure. 8 M$ w# H8 m: y% H, N! ^
Item bomItem = this.newItem("Part BOM","get");
3 i1 P7 p$ {3 K% o# w6 E; R2 q7 Q6 X$ QbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 8 c9 U; W5 V3 h0 U& n
qryItem.addRelationship(bomItem);
& T6 s5 V) j% e. ]$ X   e) a1 P2 H$ @  `
// Perform the query. " H$ p' T& G+ E# q. G
Item results = qryItem.apply(); . O; j7 i5 L( W3 \
& t9 I0 K5 _9 h" |9 r
// Test for an error.
( ]9 ~$ e# {5 |9 Pif (results.isError()) {
: U6 q, N. G5 c7 j& i1 e' \  return innovator.newError("Item not found: " + results.getErrorDetail());
$ V: B) _* t% ]; H}
7 [" Y; Y7 ~# r5 ?9 D; L. N0 g * [5 T5 S1 x4 R
// Get a handle to the BOM Items.
  P6 v4 Q" v! d4 EItem bomItems = results.getRelationships(); ! C4 n# S7 L5 l  M
int count = bomItems.getItemCount();
  a8 E  W& J% E5 pint i;
9 F9 k- k3 U+ p* f' k; z # G" ]* W. [# d/ D
// Create the results content.
& t$ X  _3 z( X( {string content = "<table border='1'>" + ; J6 b& S& {: c# M0 H! v
  "<tr>" +
! |7 A! N* F5 p- h( {+ Y3 H    "<td>Part Number</td>" + 9 W0 Q+ p) s# H" u; F
    "<td>Description</td>" +
, W* D  q* c- e, F    "<td>Cost</td>" + : E) P- {' i9 I& T
    "<td>Quantity</td>" +
3 Z( {3 g! s: L  "</tr>"; 1 l0 u/ o, l% T6 b  d: F2 q$ n6 o! {

% M0 Q( J7 r5 l$ t9 y! G// Iterate over the BOM Items.
9 F4 |6 n" o5 B7 e) E4 K# \for (i=0; i<count; ++i)
6 Z! I. i8 B! o1 r: r{ / K: V$ \+ W$ J+ V  K
// Get a handle to the relationship Item by index.
/ ?5 @* @6 l9 `" e4 B  Item bom = bomItems.getItemByIndex(i);
7 P& X' A( {, k7 j. O9 a// Get a handle to the related Item for this relationship Item.
% O' p+ A+ ]& H2 a! F1 ]& [. y  Item bomPart = bom.getRelatedItem();
  g4 u2 {! A3 Y+ t3 g5 t5 k * P- i, A  e- U# N8 O
  content += "" + 0 d8 O8 @6 U5 i. `! ]
    "<tr>" + / H7 z+ q, D2 A/ _0 L
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
) L( `) \( D* V4 H, p" \- S4 L' _      "<td>" + bomPart.getProperty("description") + "</td>" + ( Z/ k  E( l( Q
      "<td>" + bomPart.getProperty("cost") + "</td>" + 4 I/ C( }+ r+ @, M
      "<td>" + bom.getProperty("quantity") + "</td>" +
/ p( g1 O5 Y( @" h3 E  }- _7 `! J    "</tr>"; ! e% g! x3 u; u  \- R
}
! o( a) x7 [% x1 Wcontent += "</table>";
) h( O+ [7 C: A7 e ' R& k* d1 }( z7 q/ r% m# U. P
return innovator.newResult(content);
) F3 y8 Y9 d& W  c, ~% {7 D* w: I, t1 A
' H/ v- L# A  D; A% v+ K

  O. P3 r! h- I" s. e2 Y! h
1 u; [& e' P3 Q) z/ O, B

3 p* K* S0 U, f: d# v
. }9 p4 g, f& A
, i' H1 U2 U4 z) c1 i& \
    Page 46
. }# V* {* C0 w2 @8 p* ~- `: W4 q! `- K
1 n- W% e% H: f7 {  i2 tCopyright   2007 / |3 `$ N& N4 |6 h
Aras Corporation.  7 P4 V- @  S1 [/ Q5 S
All Rights Reserved.
1 L( ^, g; {) {VB.Net  & p1 k0 _: c+ C/ {4 D! o
Dim innovator As Innovator = Me.newInnovator() 0 |- n: F8 U6 c( u" X8 `4 l

5 B$ R5 @0 v1 i- p' Set up the query Item.
2 D4 x* T8 n7 O  c# Q7 lDim qryItem As Item = Me.newItem("Part","get") - r$ s/ @: T0 T3 X/ K+ g1 i3 I. _9 ^
qryItem.setAttribute("select","item_number,description,cost") 3 R( Q* r/ w4 q) e  f1 M0 a5 G
qryItem.setID(myId) 3 c# Z* [3 e& F' k

9 V4 K" q% `- P" S: c; P1 D' Add the BOM structure.
4 g% w) T; d) M) X( RDim bomItem As Item = Me.newItem("Part BOM","get") 9 S2 X" o4 K2 a, r5 e7 ?
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 8 h# a& ]. S" v# v9 u2 f' E
qryItem.addRelationship(bomItem) ; y. j9 o" R2 b; S* l9 U

: C& w$ K- `+ w& d' Perform the query.
* v' X' F8 s2 n/ @& A' KDim results As Item = qryItem.apply()   n2 d- q! J7 z( ]

/ V9 W# B; l+ `6 Y  ~5 E# _' Test for an error.
5 H" X" i* N  dIf results.isError() Then
1 u' R8 a3 K# C: B) z  Return innovator.newError(results.getErrorDetail())
$ c$ p# \( ]* lEnd If ' p5 O6 Z' o4 ~

; |. U5 p+ C* B/ p% D+ L' Get a handle to the BOM Items.
, z/ r; F4 Z. }5 I* GDim bomItems As Item = results.getRelationships() ) A* g& [5 k/ w
Dim count As Integer = bomItems.getItemCount()
3 e& [- \, U/ a7 V6 TDim i As Integer - [$ y. _/ Z6 l

% R. Y4 m6 p/ M4 s# f- [  }' Create the results content. & L  e/ X& Q. C7 u
Dim content As String = "<table border='1'>" + _ 7 \  }! M* W2 e; f! q
  "<tr>" + _ " V0 S: c% i4 E+ W, ]9 ]
    "<td>Part Number</td>" + _
# k) w/ f/ p, }  j( f; T' s) c. p    "<td>Description</td>" + _
4 f6 P, O" q1 B7 o8 H9 _    "<td>Cost</td>" + _
" w; P, y" h* j. v1 B    "<td>Quantity</td>" + _ / v. v6 r7 p  _" K
  "</tr>" : ~/ e6 W. d9 t

8 [0 }9 F; Q% ^7 \( \: k7 a- K' Iterate over the BOM Items
2 [% i1 L/ p9 e, yFor i = 0 To count - 1
0 l' e6 u5 e/ O. s; O' s' Get a handle to the relationship Item by index.
3 B  `* u. Y& W0 B  Dim bom As Item = bomItems.getItemByIndex(i) , Y3 b- b1 Y- T; |

/ C3 O9 r, s1 G: J% ?, N. ]' Get a handle to the related Item for this relationship Item.
0 j( w$ ^- e$ H! }  Dim bomPart As Item = bom.getRelatedItem()
/ ?- v  n9 X( L$ C; e0 k) N
* N# b+ R/ _% b/ ?  content += _ ! k5 q/ o  |4 D# C2 C1 V1 z
    "<tr>" + _
" H* G! p3 J8 p1 Q      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
. U4 N  k: Q& k% [      "<td>" + bomPart.getProperty("description") + "</td>" + _
- [/ i; j. j" G. m& E$ j      "<td>" + bomPart.getProperty("cost") + "</td>" + _
% O7 r; e/ @& L/ j! _      "<td>" + bom.getProperty("quantity") + "</td>" + _ % a4 M% g3 T5 s# S$ Y
    "</tr>"
+ G' W. ]2 F6 Q4 O) o! \Next # r  U1 O. z: Z5 z" J( x" h, z8 f
content += "</table>"
' b8 D/ X& |; t5 r, L7 Z
7 l: {' }- g) O# M* nReturn innovator.newResult(content) * O1 s: B1 i- k! m
+ h' z; w& r! U0 E
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了