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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  * h5 @, D/ H' _( a9 f/ [
To query for an Item and retrieve its structure you build the query as the structure
' B$ C. t2 U2 C. v" c! byou want returned.  Use the IOM methods to add the relationships you want and . x6 d! p0 J& j* j% L/ c! p
build the structure in the Item.  The server will return the structure that follows the
2 d+ r. O0 i8 [" K/ @3 _request structure.
* [; \) I3 J) l! K; dThis recipe illustrates several related concepts together, which are how to get a set
$ K1 b# q& a( r0 z1 Eof Items from an Item and how to iterate over the set, plus how to get the related 3 _+ ?2 v2 m- k+ v1 A+ H' G/ l
Item from the relationship Item. . }' f) v9 x/ E1 w- h  S* _' s5 t
JavaScript  8 Y  G; i  C6 N+ d
var innovator = this.newInnovator(); 1 G' t- P, A) a) H; m

1 M8 o2 s8 v3 U8 K5 K' p+ m- k// Set up the query Item. ( ^3 `. ~1 E0 D0 H0 b
var qryItem = this.newItem("Part","get"); 6 D4 E! o. P9 W1 O2 \8 g4 X
qryItem.setAttribute("select","item_number,description,cost");
: i+ h# b; T) ~4 DqryItem.setID(myId);
+ s0 D5 _, L- o+ ]# K. T" ^8 O
) @7 s( M* j! E$ h// Add the BOM structure. # D* G& U% @. r/ H
var bomItem = this.newItem("Part BOM","get");
3 e& N- |3 E3 QbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
2 X6 @. S( M, \8 o4 c% ~5 r( yqryItem.addRelationship(bomItem); $ N5 @' b8 S2 f) U3 H

& A3 e1 O$ A& _* g2 k  l, M$ I// Perform the query.
( ~) ~5 e* J1 d& `; kvar results = qryItem.apply(); 8 u$ ^% C1 D/ T) z

& a- x3 ^4 c0 p5 A6 \// Test for an error. # B' L# u7 B2 @+ ?6 h& o& A: Z
if (results.isError()) {
0 t1 L8 i) C" ]3 J1 R# m  top.aras.AlertError("Item not found: " + results.getErrorDetail());
7 u' B$ o7 O# B* ]: R+ _  N  return;
- u0 |& M2 }0 j5 d5 g: C} ! ~4 v. y3 B, n' r

% b- J# t$ I! q, {// Get a handle to the BOM Items.
6 m0 D2 E$ s( @& B+ l1 m2 Wvar bomItems = results.getRelationships(); ! K  h) {/ G$ N
var count = bomItems.getItemCount(); ( a: m" C3 z+ r6 Q4 b5 `8 G1 M
' v4 q2 \0 r) s
// Create the results content.
* W' u2 }* b- @2 h1 Ovar content = "<table border='1'>" + ) h, z0 m: P2 q
  "<tr>" + 6 ?! Y2 S& ^. o7 M
    "<td>Part Number</td>" +
! m- z7 O  m- h7 u- b    "<td>Description</td>" + - }% @2 \( F& ^, K
    "<td>Cost</td>" +
* r/ E0 ~- h- {    "<td>Quantity</td>" +
* c% z7 T. d2 G6 R8 e9 _8 \+ j  "</tr>"; 1 \4 @1 x8 P# \5 o, v$ V
" ?! F6 I2 S# q5 B& i
// Iterate over the BOM Items.
& U. p5 t0 s! S1 rfor (var i=0; i<count; ++i) 5 [2 V4 w0 y0 x. E0 ?
{
$ f8 s4 r  g% A# c8 \# g// Get a handle to the relationship Item by index. 2 I+ |: z. m. F7 W
  var bom = bomItems.getItemByIndex(i); 2 [3 O, l& G7 V
// Get a handle to the related Item for this relationship Item.
$ B9 }0 F0 Q! e& r9 C  var bomPart = bom.getRelatedItem(); 3 m3 C% w5 D" T
. n3 P8 h5 m- G& D6 _9 C
  content += "<tr>" +
* x) Q6 {4 P5 }5 K% }. {      "<td>" + bomPart.getProperty("item_number") + "</td>" + 6 e/ W  _5 h9 ?5 ~- w$ x/ }
      "<td>" + bomPart.getProperty("description") + "</td>" +
) `  t- s; q* g5 I* R      "<td>" + bomPart.getProperty("cost") + "</td>" + : D# n- F8 x4 q) g2 V0 F; P
      "<td>" + bom.getProperty("quantity") + "</td>" +
! y& E' b  L( `# @9 M% m    "</tr>"; 0 I% j, `. N8 h1 J4 X
} # ^: V9 @( n; i6 ]8 k5 F
return content + "</table>";
1 z8 n8 Z" m( A
) G$ ?' o/ C! I3 C$ y2 e

" R0 B$ L9 o) Z0 s2 J+ n- C& o# x  }& M/ K# F% [

' E! ^# `% }- }  x( \C#  1 b! u0 N: T& I4 W, R/ ^& o1 b5 l
Innovator innovator = this.newInnovator();
! C3 v! n- X3 `- d8 h9 k+ t
$ q( u9 _* c+ @// Set up the query Item. , O2 F# U7 k/ Z9 r* [9 u- G) [
Item qryItem = this.newItem("Part","get");
* |! ]0 T- Z0 \7 n3 SqryItem.setAttribute("select","item_number,description,cost"); $ S7 G6 K$ L: n6 Q8 h% J6 j0 L4 v
qryItem.setID(myId);   R8 p7 A  c6 e" i

" J: f6 \5 N- }// Add the BOM structure. - x" [& r1 [9 R. L# p4 A, V9 P
Item bomItem = this.newItem("Part BOM","get"); 9 [4 q" \# p; g
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
0 b& ~* l/ Y6 i. s. XqryItem.addRelationship(bomItem);
* d- v: [1 |9 [) z
& d" A& ^7 C. M// Perform the query.
) f5 F$ J6 l! e+ b6 }6 q8 v  k! R5 AItem results = qryItem.apply(); & K8 X  ^4 N/ |3 r. }
8 l4 S% h( @" a
// Test for an error. 5 f- ~) {6 [: v
if (results.isError()) {
" I9 h, Q7 f9 Y. C, M1 L2 @* n  return innovator.newError("Item not found: " + results.getErrorDetail());
, G; B6 \: S% \8 ?. z) ~8 D! @* d* n; U}
5 \4 m# q7 K% V9 b0 h8 t( X2 T
9 B9 t7 d9 f% Q3 f' }1 l' U& |// Get a handle to the BOM Items.
7 w3 o" R9 U, F8 X7 cItem bomItems = results.getRelationships();
+ k4 g# P2 ?& N4 m' Y& q& a, jint count = bomItems.getItemCount(); 1 K" [- p8 y2 N, l: p  ?+ N# n- ~2 \9 e
int i; & d1 s9 M# f3 a, n; f
$ V. t- q9 G1 x7 Q
// Create the results content.
- n2 o# e7 E  V+ l& Tstring content = "<table border='1'>" + * O" k' e& c( x% G$ A) r/ |  [6 K
  "<tr>" + 1 S) ^* a7 x4 R
    "<td>Part Number</td>" +
8 D; ]* _6 U9 }, ]6 V    "<td>Description</td>" +
. O7 A2 l2 ^. c4 }' ~    "<td>Cost</td>" + 9 _# j0 H2 a' W& ^! A! D' ]8 q
    "<td>Quantity</td>" + 8 j2 A* j* n% b# R0 `1 R
  "</tr>"; " b9 k1 C4 g, v' X) E( p) s1 n

# z6 W5 [0 ^2 @3 T. j// Iterate over the BOM Items.
1 t* c7 R" q: u" @5 _6 pfor (i=0; i<count; ++i) : x. `5 x* G  e+ [' }
{ * {4 z: o! i$ @
// Get a handle to the relationship Item by index.
: u5 [4 U- }1 F, @: J- ~8 `  Item bom = bomItems.getItemByIndex(i);
8 Q8 \* k/ e5 O7 a// Get a handle to the related Item for this relationship Item.
% D/ n  Q+ |9 Z. P* a5 }& L  Item bomPart = bom.getRelatedItem(); 9 f1 }6 M* [. Z6 Y( Y5 Q% Z
' v& J6 [; U: W" l: y& m0 Q# z
  content += "" + , ~$ V! ~- g% a/ h" ?6 x' Z- Q6 a
    "<tr>" +
$ \6 h" e+ f. X6 |      "<td>" + bomPart.getProperty("item_number") + "</td>" +
9 N6 u3 s! _. |      "<td>" + bomPart.getProperty("description") + "</td>" + 4 r* j8 Y6 Q: e$ c4 v) e0 ~
      "<td>" + bomPart.getProperty("cost") + "</td>" + 8 |! }6 |. I2 b) x
      "<td>" + bom.getProperty("quantity") + "</td>" + # ~8 [7 R3 E  K( W8 A' b" V
    "</tr>";
5 B6 M$ b) B- b# i}
$ W: h& J7 c+ s. scontent += "</table>";
' W' a5 m8 i, N5 L0 |
9 o  x. X5 o3 {, c5 Y; k) Jreturn innovator.newResult(content);
: \4 {- R2 X: S$ x6 s" {6 @
  z0 e9 Z% d; E: Q! L
: W! J2 h! \9 {) C, |; f+ m2 P
# Y/ `5 f! l' B: R' S, K0 `0 v7 L- o

+ X9 d& p, i1 g6 p
" o5 \8 b! M% V
6 U8 n9 W" @9 v* B
0 {/ z. ?* u' `6 y
    Page 46
% \/ u- P% @5 l3 b. y ( A: T" p; U; g1 p* j; u
Copyright   2007 - e. Z, u. K0 o6 Y7 q7 c3 G
Aras Corporation.  
# `: V' n7 R- a" ?: pAll Rights Reserved.
, [$ X/ r, V& e8 b. Z- QVB.Net  ! W! |( h3 p) c) ]* m
Dim innovator As Innovator = Me.newInnovator() 7 @& r; ]% O5 u6 B* Z

# _8 K4 P! w9 j4 C! R* B  H7 j' Set up the query Item. 1 g7 a+ K2 _! [2 p
Dim qryItem As Item = Me.newItem("Part","get")
, }$ i9 d. N, x/ n4 U* r: D5 T6 O$ t( eqryItem.setAttribute("select","item_number,description,cost")
, _" Z( h1 z) @  V4 V- q4 oqryItem.setID(myId) ; k& B* @( }* D* D/ I  ~& j7 @6 H
% Q. l" o7 Q% J; C3 @* M
' Add the BOM structure. ; U& G; a' s6 \/ n7 {5 J5 x
Dim bomItem As Item = Me.newItem("Part BOM","get") $ q  b. r+ E% b: U) s" G9 \3 n
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
6 k+ w, c3 h5 i8 `, z7 `qryItem.addRelationship(bomItem)   D  Q4 ^9 R& E4 e& m3 N1 D# \
8 v2 J3 x% B& ~8 J( ?6 _
' Perform the query. ; z. _8 {& _6 q3 ?  n$ n4 _$ S7 n
Dim results As Item = qryItem.apply() 2 }& Z! ~) J* w" h* l
( Q# K% ]9 g7 R8 z
' Test for an error.
2 u4 m$ c1 d4 \' v. VIf results.isError() Then ) v1 u' ~1 Q6 {7 O  a
  Return innovator.newError(results.getErrorDetail()) 8 o" d9 K% @* o, j1 c# z
End If
8 X2 L; H$ i8 o5 }
4 n% G. C3 S+ H1 U+ f2 Z' Get a handle to the BOM Items. - L0 B; E! C. D4 V' Z7 g( u) O# }
Dim bomItems As Item = results.getRelationships() 8 k. D' n  G: e; o: l
Dim count As Integer = bomItems.getItemCount() 8 p9 |' z: ]5 R* r7 r( ^
Dim i As Integer - P5 N, c5 t7 s

+ ~/ _  i) c1 t6 ?" a' Create the results content. 6 w' Q4 y. z6 K1 }& i: ~2 ^
Dim content As String = "<table border='1'>" + _
: Y  ?* R5 ?! @& Z, r  "<tr>" + _ + a1 e* h" M1 U& I% n
    "<td>Part Number</td>" + _
1 i4 m1 [0 K) \, g! V  h3 A    "<td>Description</td>" + _ % j% V9 ]3 W, e1 V5 E: [* s( [
    "<td>Cost</td>" + _
2 g! _5 D8 e3 R+ v6 V    "<td>Quantity</td>" + _
: w6 N8 R. \' V7 `5 C# r  "</tr>" + ?2 B) _1 T; N& w- B

+ W' l7 p4 ~% k' Iterate over the BOM Items 3 U, I7 T+ D  O2 `/ B; R) b
For i = 0 To count - 1 9 J9 o7 Z1 ]/ q" P! i$ c2 A2 |* b
' Get a handle to the relationship Item by index. 6 O9 g1 E/ u8 W
  Dim bom As Item = bomItems.getItemByIndex(i) 5 T4 s# u" r. r, T0 y
3 S% E' V% [8 Q$ `
' Get a handle to the related Item for this relationship Item.
8 |7 P7 |: L% b4 k( d3 W9 c  Dim bomPart As Item = bom.getRelatedItem() ' w# Z1 g4 ~' W: f- d

2 w1 @6 W& l: r5 Z  content += _   r4 e% {$ P: J) U  D. b9 h
    "<tr>" + _
  e) L5 s5 B0 E, I6 z      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ V" S6 Y" o' E9 L  z. w
      "<td>" + bomPart.getProperty("description") + "</td>" + _ - X+ |- r, l# n: M) x. v; l
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
8 D+ U, o& x5 i& A' r% K% T; Z( }      "<td>" + bom.getProperty("quantity") + "</td>" + _ 5 S/ }0 ?# Y# w/ K/ v; {( Z
    "</tr>"
. _% c* W4 x- UNext
9 q" u" t4 z- {4 ?8 e# S9 Econtent += "</table>"
. {( z* M2 `' ~6 E ) a! h1 k8 w) C2 `
Return innovator.newResult(content) 2 C7 Q- b& E6 j

$ e  O8 i6 D& y1 M/ [  f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了