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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
8 l' b6 I0 l" E3 e% RTo query for an Item and retrieve its structure you build the query as the structure ' \) u% @# y' c
you want returned.  Use the IOM methods to add the relationships you want and
& ?- @, z( s6 T: p6 abuild the structure in the Item.  The server will return the structure that follows the & N) \( e, l, Z/ g* h0 F
request structure. : F3 C6 x! Q/ |# m
This recipe illustrates several related concepts together, which are how to get a set $ R$ {5 h7 q4 U2 e, X
of Items from an Item and how to iterate over the set, plus how to get the related 3 q( J1 V0 @! j% k5 B" l0 h1 i
Item from the relationship Item.
4 l4 [3 P4 g' HJavaScript  . b9 ]' N5 a4 a4 Z: |: l
var innovator = this.newInnovator();
( t" o: M  |9 C) r
9 A9 T6 a. _+ ?# R/ G3 r// Set up the query Item. . ~9 M3 v2 X+ h$ F- [
var qryItem = this.newItem("Part","get");
6 J4 p$ r* W- U4 `6 x: x* v1 _& ^qryItem.setAttribute("select","item_number,description,cost");
  n' Q- c3 c7 L3 n0 oqryItem.setID(myId);
+ m% r  I2 [- I; H) ]4 a , R" N# H& T, e& ?; u# d  I4 |
// Add the BOM structure. 2 H( L% \/ a8 s% h
var bomItem = this.newItem("Part BOM","get");
, ?" H0 O3 h% B  @2 }bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); : n6 q" s; S( c; C' `
qryItem.addRelationship(bomItem); - Y7 c3 ?9 R5 \- p3 w

4 S8 {8 u# Z; |; f// Perform the query. # L7 `7 T6 Y% o$ V0 `/ P% C1 T
var results = qryItem.apply(); 8 c5 _  _' J( K
1 o+ G  S, ?. n2 E  }$ x
// Test for an error.
) E5 Z5 N& H9 b7 ?if (results.isError()) {
. R2 c/ `: ?! l' S: y0 u) K  top.aras.AlertError("Item not found: " + results.getErrorDetail());   B1 k/ ]' C2 H) T3 q, R
  return; + v8 C) k+ q" m4 s9 p% p
} % k, Q: h* y! I2 ~# o+ M% P0 `( \

+ F/ ^+ q0 T' C# y6 Q// Get a handle to the BOM Items. 8 ?2 c, |) B. `' ?) I4 o  X
var bomItems = results.getRelationships(); 7 P, S) D5 ?4 i$ z3 Z5 E$ }% C  m0 G* S( K
var count = bomItems.getItemCount();
3 `/ \( j5 N& z
5 M+ p. L& p, Q6 P4 g1 ^// Create the results content. 1 R5 Q: R4 }& i  w. i. {5 h
var content = "<table border='1'>" + 1 \3 z# i0 t) L5 _5 E
  "<tr>" + 3 H" ^% K" P. s8 B( s. }
    "<td>Part Number</td>" + 2 }1 \7 k4 i, f: ?4 r
    "<td>Description</td>" +
: n' W4 {# ?# j2 c& i2 z' y2 \    "<td>Cost</td>" +
# q2 w: C% b, q1 d+ _1 z    "<td>Quantity</td>" + ! f4 v$ f! ]3 E
  "</tr>"; 6 B/ H5 ], P! q% _8 m1 l8 Y
& D2 }" X. u8 b- X1 `( f
// Iterate over the BOM Items.
' S4 z2 A2 P6 v$ @& @for (var i=0; i<count; ++i) 0 ~/ f( ^% D" v
{ / s9 s4 {* [3 T5 K+ W6 M
// Get a handle to the relationship Item by index.
8 m, G" ^/ Q) }  var bom = bomItems.getItemByIndex(i); & M8 }& e, n) W& I
// Get a handle to the related Item for this relationship Item.
+ y" \" I2 J" t# V" W! q9 P  var bomPart = bom.getRelatedItem(); 0 H  x* L6 B* ]# @# S
( w/ a& S! h5 _  n+ s
  content += "<tr>" +
1 s  W7 }0 Z5 O) s      "<td>" + bomPart.getProperty("item_number") + "</td>" + 3 T# A' x9 b* g, ^0 Y4 R
      "<td>" + bomPart.getProperty("description") + "</td>" + 7 N  E7 R1 G2 M
      "<td>" + bomPart.getProperty("cost") + "</td>" +
3 C* V" S" A3 a, t/ u      "<td>" + bom.getProperty("quantity") + "</td>" +
! A, x8 N/ P% F1 Z    "</tr>";
, m2 Q9 U6 h0 }! [8 z% |+ S$ x} 7 Z3 b# A6 {6 i$ ^6 s, k
return content + "</table>";
7 ]) y( C3 C4 p0 Y- B, l7 v' b8 @% ], x% k- T8 }' n  L
/ M# y+ t: X: t& T! z1 C" ^

% k: \2 L4 b; A% D( U3 Z

4 W% c, Y: E4 nC#  
0 d: k8 K0 w7 Q5 S  `0 }Innovator innovator = this.newInnovator(); ; U3 Q4 z0 Q7 L8 ^% i& l
( v7 H1 d. q& e. f8 O  W
// Set up the query Item. : _% U/ ]1 \5 l# {" x
Item qryItem = this.newItem("Part","get"); : q& n! ]+ ~7 X' a2 h- p
qryItem.setAttribute("select","item_number,description,cost"); 4 m% Q2 J! r0 U0 d* S6 D
qryItem.setID(myId);
0 j/ A) G7 [* Q7 w 4 t1 F' P0 ]- T) x
// Add the BOM structure.
, J1 @! X( {0 g+ z0 _4 U$ EItem bomItem = this.newItem("Part BOM","get"); 8 f# F: G+ q' U8 T& ]& E! Q
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
& g5 l( r) |0 w; V7 L  ?2 J  fqryItem.addRelationship(bomItem);
( n+ O( T" S9 p: Z 5 Z2 ]/ S; d( c" Y2 p$ |6 `0 N, e
// Perform the query.
9 d* o# f# S* MItem results = qryItem.apply(); / @3 j: A! ?7 P* O/ N- I
- f+ f+ A9 ~, \) C
// Test for an error. % X" \; G* A5 u
if (results.isError()) { 3 H, q! ~0 R, ^# s% {* M  n
  return innovator.newError("Item not found: " + results.getErrorDetail()); 5 K* c) G: V5 R5 z6 a: ?
}
$ _) g* s  O$ A7 k) f  Y
  Y) D3 v% l& L* l& X// Get a handle to the BOM Items.
0 d% y: q: M! {1 S( \! JItem bomItems = results.getRelationships(); / |, v2 a$ ?$ ~# ?8 A
int count = bomItems.getItemCount();
0 ?$ S$ t. M/ H3 y( ~int i; ; f( {3 ]: Y; p& ]. c
8 x2 \$ c5 f! Y
// Create the results content. 1 Z; Y9 f% w( e* F- Z+ |7 J7 o( C+ _
string content = "<table border='1'>" +
% ]8 `, P" K/ e/ b  "<tr>" +
) h5 F( k. A& h' g1 n/ ?8 u    "<td>Part Number</td>" +
( u& ^" h. U% e3 Q& Q; l    "<td>Description</td>" +
2 F4 b, d% X& M" `( j    "<td>Cost</td>" +   s& k" B& {/ P7 E2 E
    "<td>Quantity</td>" + 4 C" C; x9 ~) X+ k# v
  "</tr>";
* G9 l7 C" Z; Y: B7 C
+ l) A* G# T  Z8 Y0 ~// Iterate over the BOM Items.
) v. v; U) v+ Sfor (i=0; i<count; ++i)
: f2 d4 |4 v, f2 @9 C" ?, ~{ 6 w3 R) O$ S7 @1 h
// Get a handle to the relationship Item by index.
" W. ?: U8 L& @7 ^% y/ y4 j! C: G  Item bom = bomItems.getItemByIndex(i);
6 G  g9 @, C& E// Get a handle to the related Item for this relationship Item. ( `+ }3 X  `5 Y$ X% H& s
  Item bomPart = bom.getRelatedItem();
9 h0 P; m  o6 ~ + }+ {2 F8 b% P& j5 v
  content += "" + , f3 A7 F1 o' e2 |
    "<tr>" +
' T0 S0 M+ R, [, O/ w      "<td>" + bomPart.getProperty("item_number") + "</td>" +
9 M$ d6 P$ ?* p& ~1 [      "<td>" + bomPart.getProperty("description") + "</td>" +
# x2 Y$ s9 u% ]8 B, f9 Q2 F      "<td>" + bomPart.getProperty("cost") + "</td>" +
, G" h9 B! A, n2 y/ [: R' O      "<td>" + bom.getProperty("quantity") + "</td>" + 6 z# O, b8 A3 X3 S, ^  Q
    "</tr>";
9 @4 ^+ a5 e. a& }}
- J6 ~9 Q4 ~7 s: H0 econtent += "</table>";
) z9 V0 d" g/ R! S' D) |- w! q % D1 R5 C% |. k8 J# j
return innovator.newResult(content); , i1 @8 N" v$ {7 `( U4 ?
: {4 D) K3 ^1 t$ g
- n& e2 h, M6 S* x
+ Y- B4 g5 _" B4 e2 A+ c" h3 l

; B# h, b5 Q/ J# _* w0 }' G% B
- D4 ]9 M) y; ?+ {; x/ I
7 ^' X! F$ A5 w& {3 W

" `& N. ^# f: p+ L8 e2 j8 w    Page 46
" r0 \0 T" M. K; i# v1 Z , e+ ~! {" Y" }* k8 x- I8 t
Copyright   2007
+ y; L7 ?/ Z5 i0 |! gAras Corporation.  
- f+ _& x9 I0 P; t* E6 v( o- GAll Rights Reserved.
6 t$ j5 m. }( C: G: C+ ]1 DVB.Net  ( `+ c# f5 `( r8 ~2 M9 A
Dim innovator As Innovator = Me.newInnovator() : z, |: ^* N) M

. n& \7 w5 c  M8 ^8 i. I+ P' Set up the query Item.
( b# B( T; W2 L) [, DDim qryItem As Item = Me.newItem("Part","get")
. v7 r" l& L" L9 _% x: w8 P8 P/ X  x& HqryItem.setAttribute("select","item_number,description,cost") " n7 [) i' q# r, L. l
qryItem.setID(myId)
& p& R" l3 B1 h& i3 l4 z% ?3 N
- q) E$ R' S7 C0 j' r6 j' Add the BOM structure. 7 F2 [' y2 ]0 Z4 }# p; D! G; P
Dim bomItem As Item = Me.newItem("Part BOM","get") / x/ O3 ]1 \: O" s# u
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 3 Y  m! g* X" b' y( G; K
qryItem.addRelationship(bomItem)
9 G) ]+ e! [8 L% f & w- e! O% o8 c7 s: g1 K
' Perform the query.
& o& C6 X; o$ w; Q5 QDim results As Item = qryItem.apply() 3 ]/ i3 r' ]# ]; }  ^9 N

) l) @$ D& s  d6 E3 {* A* x7 Y/ `' Test for an error. - H4 R$ L! i$ C/ {: U9 m
If results.isError() Then ) e$ v, C9 Y7 H6 @  T
  Return innovator.newError(results.getErrorDetail())
0 _5 x9 F. I) [" X4 ]' \End If
: V- u( t) K, |8 {/ Y + T4 \2 v0 f0 [' C  Z
' Get a handle to the BOM Items. * j% Q, G+ E0 b# W- J( f
Dim bomItems As Item = results.getRelationships()
! c5 z& O0 n7 y. ODim count As Integer = bomItems.getItemCount()
  s1 t. o( L% V. ?; mDim i As Integer
. @, \8 h3 o" I8 Z+ J* @4 A 9 [( E" P4 k1 W) _3 X
' Create the results content.
% Q1 T" ^/ n8 h; Z% g( o) N! S' nDim content As String = "<table border='1'>" + _
. P- v! h6 w" A$ G  "<tr>" + _
' B7 S6 f0 k7 G# Y  [' t& @6 K    "<td>Part Number</td>" + _
! u3 `% f1 g8 v- {; @" Z    "<td>Description</td>" + _
1 ^8 _2 v, s! f% B7 g) G6 B/ L' ~+ R    "<td>Cost</td>" + _ , K2 \4 a4 `( i# m. B: d6 n8 j' ^
    "<td>Quantity</td>" + _ + n" V! x: _, I" L' [, f
  "</tr>" 5 l: u7 Y" H( |6 W5 z, n

6 v% W) O9 V" A& ?7 _! ?3 U' Iterate over the BOM Items
/ l4 a3 d: c9 _: q4 RFor i = 0 To count - 1 " j2 a5 S  |2 P3 n  C0 M- w! |
' Get a handle to the relationship Item by index.
2 P: C$ v, `. x  Dim bom As Item = bomItems.getItemByIndex(i)
% t% G# S  s: b, o: f
3 B& |% t2 j; x% A, _% S' Get a handle to the related Item for this relationship Item. / o! P: G5 {4 H* m1 K6 R
  Dim bomPart As Item = bom.getRelatedItem()
* D& F% Q. E( X/ x; k 3 ]3 Y2 C; g3 r' E" G. \
  content += _
9 O1 q  S5 K6 i; w    "<tr>" + _
+ f9 V9 R: m7 L5 K/ N      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
8 W& e) B/ ~  N8 B) I# _0 V, n9 W* W      "<td>" + bomPart.getProperty("description") + "</td>" + _ 0 d# I2 E' z/ `/ |/ K; R9 r- [
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ + K; y; @7 w# [, d0 ^1 K6 k% d
      "<td>" + bom.getProperty("quantity") + "</td>" + _
% e" @2 J: y" d; u) m0 O: J! \    "</tr>"
- }$ P1 p( t, \7 b+ A7 d0 l. v6 VNext ' \9 p3 Y) M( v0 V" d$ E" t# ]+ h
content += "</table>"
, P. u( s7 ~7 h# ?/ z. e
/ L/ i. \2 ~1 |& N& C5 ~Return innovator.newResult(content)
$ M: b2 a2 ~- c3 t6 }: P
7 {- f: }) D$ r- o0 x9 K
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了