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

【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  
5 X( u  F7 X  ]To query for an Item and retrieve its structure you build the query as the structure
8 p. V( l7 x. m' m% T. N9 [! Q, _you want returned.  Use the IOM methods to add the relationships you want and ' O8 ]! e* t8 g8 K
build the structure in the Item.  The server will return the structure that follows the
% `; H7 S( G$ ^request structure. # [" k$ N* T6 e
This recipe illustrates several related concepts together, which are how to get a set
0 d8 J, B# E, }4 S4 u2 K! `; Bof Items from an Item and how to iterate over the set, plus how to get the related
+ ?& T1 I, r, s; g$ fItem from the relationship Item.
) r9 @& G* R1 f  pJavaScript    o! q- T5 I" ]& B6 q* g
var innovator = this.newInnovator(); 6 U: U7 |1 ^8 v) e+ V3 R$ u
' {, p  M+ ]+ ~- a9 c' |
// Set up the query Item.
6 k, {8 R7 Q8 m0 F8 tvar qryItem = this.newItem("Part","get"); # F/ g1 w  a+ w. N6 E
qryItem.setAttribute("select","item_number,description,cost"); ; ^6 M+ k& P* m( ?( ]6 ^
qryItem.setID(myId);
+ C: L$ _- ~# K9 q: D4 I
$ a5 G4 u- Y7 R  f; o1 }" \// Add the BOM structure. + x- I6 ~2 j1 F# X
var bomItem = this.newItem("Part BOM","get");
8 [/ f8 t0 j4 n2 XbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
9 O" b" b: @- E" \qryItem.addRelationship(bomItem); 5 K5 ?2 B; A: X2 F8 Y
) D; h  Y* E: M. O9 `) y
// Perform the query.
; ^7 V$ o9 }; W5 |" W7 Q9 b/ ivar results = qryItem.apply();
( L; j: ^; E9 H. g, C1 u, w 9 l7 m% o' v/ ]7 d& e
// Test for an error.
8 M, M9 I$ x2 {- z: ?) B3 Lif (results.isError()) {
7 ~( f8 |/ l. `% s% V8 q, P1 a/ K  top.aras.AlertError("Item not found: " + results.getErrorDetail());
3 W7 q3 J% [- n0 j0 T. U- {- `3 Z4 L  return;
& r6 T. `3 ~# \2 b! B}
9 m: l. Z. M6 [8 u) [
5 @6 l, ~0 z" [% f// Get a handle to the BOM Items.
" Q' e( f% W' H7 y  N6 _* j, cvar bomItems = results.getRelationships();
3 ^% p* ?: r5 zvar count = bomItems.getItemCount(); ( E# R0 _: ^( H4 m! ?
# s+ m/ ^5 O# R
// Create the results content.   q% d% @4 C; N- u
var content = "<table border='1'>" +
+ |: E" y- F1 j1 b! ^! o. U  "<tr>" +
( z5 P, w$ S* d+ E# B    "<td>Part Number</td>" +
+ W1 q; W1 v3 g( u7 ?% p0 d& c. u    "<td>Description</td>" +
" U! c  ~2 I8 E' }    "<td>Cost</td>" + ; p$ y/ p! ]% L) W. f- B2 [4 t- x2 ]
    "<td>Quantity</td>" +
# R# Z# P$ O1 T  "</tr>"; ; O6 H0 ?' Z9 |+ i& j
4 c* |$ B; }1 b- I
// Iterate over the BOM Items.
& C% v: u, J9 S: p6 C' Tfor (var i=0; i<count; ++i) 9 @4 F9 `4 e) ~5 `" S
{ " r( R( V7 a0 j9 f0 c
// Get a handle to the relationship Item by index.
$ [1 o2 {. a+ `% b: G4 }  var bom = bomItems.getItemByIndex(i);
3 D8 z' |! f+ @5 W2 g4 M& Q// Get a handle to the related Item for this relationship Item. - X  _& j- }* [0 ^2 n( U
  var bomPart = bom.getRelatedItem(); ( M5 P% W1 x( W4 ^
3 w& f& I- z9 v  Z( w, N, H
  content += "<tr>" +
9 O! N, _: S5 K" ]      "<td>" + bomPart.getProperty("item_number") + "</td>" +
7 r; [3 v0 f. a. @4 r3 |5 r      "<td>" + bomPart.getProperty("description") + "</td>" +
6 W' ~3 ?' x+ }1 O1 W9 ?! S      "<td>" + bomPart.getProperty("cost") + "</td>" +
6 L( l& J" ^. b5 \7 Q' N      "<td>" + bom.getProperty("quantity") + "</td>" +
$ J& @) {# C# U/ l5 }    "</tr>";
2 Z) u6 r1 a6 Y3 W+ n}
8 [" }# f( M& l5 Vreturn content + "</table>";" i4 n5 i/ |, ^! E9 W9 |* E
0 m/ G! a' v( P4 \( l1 d2 S* X$ N

4 U" _  o' x1 w. V
  O7 a7 |& @' M! u8 N

8 G0 ^+ p0 H2 D! P$ L  k. bC#  
/ h$ e4 c* T7 C: J/ XInnovator innovator = this.newInnovator();
6 E. f' j4 N: b. @9 G 7 W( Y/ ?3 V3 O  q
// Set up the query Item.
6 ^  S9 G0 I* Y9 s7 LItem qryItem = this.newItem("Part","get");
1 M+ ~+ m6 M2 x& DqryItem.setAttribute("select","item_number,description,cost"); . x( a% J% o1 u1 H
qryItem.setID(myId); " a: _7 ~  w# I! R- t1 M8 `
% I0 Y3 U9 w7 M2 Y4 {9 w
// Add the BOM structure. , }( p- e& P% {+ Y: I: z
Item bomItem = this.newItem("Part BOM","get"); ( m  ?# H- b2 a/ [3 H
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
) C" V* o- d1 a/ a; K/ J! mqryItem.addRelationship(bomItem); # w, E. q5 f# f& o/ K5 N

1 n2 S" ?, f; [; Y& {' _6 [// Perform the query.
  D/ e( `' R* PItem results = qryItem.apply(); 1 X$ ?) I  C9 @: v0 M8 X

& p1 s$ \. p! x4 Z: X// Test for an error. - u. J) ?( @5 q" A% Z+ b
if (results.isError()) {
7 H/ L! f. f2 M/ n4 |  return innovator.newError("Item not found: " + results.getErrorDetail()); 6 e3 u7 e  X  T7 l9 m* W
}
$ |$ ^# x5 C  ^! b9 B/ \
* t3 g* \9 [+ x- S* V6 q// Get a handle to the BOM Items. 7 y2 |9 `# `4 e5 V, l9 r
Item bomItems = results.getRelationships(); ! @- ^+ l; i5 t
int count = bomItems.getItemCount();
( |1 g) |% [7 b+ Jint i; / }( _4 g% C/ ?' R

/ O# m, d9 I; x8 \8 @// Create the results content. 8 F, P; N7 h! I8 H$ _" O' N
string content = "<table border='1'>" + : X( k) O6 u) r6 q
  "<tr>" + ) Y+ {+ t$ M0 s6 m0 G, H
    "<td>Part Number</td>" + 5 \9 W5 {5 A" h2 p7 Y' ]4 n
    "<td>Description</td>" + 0 n( h! o: R$ J, Q( O* }" K3 g5 L
    "<td>Cost</td>" +
/ [) @8 z8 Q6 z1 A0 O( ?    "<td>Quantity</td>" + " y% z" a$ K2 R6 N# a
  "</tr>";
0 t, S7 o% c5 v5 c7 B! }2 A 2 {* }$ _, d6 ~. L; T4 s2 ?0 c" u) q# v
// Iterate over the BOM Items.
, Q1 G  ?2 T9 ~3 F4 Jfor (i=0; i<count; ++i) 1 \; ?3 r7 Y- ]! d' ?
{
' O) g. I. M" }! i8 B// Get a handle to the relationship Item by index.
7 }3 i, I+ p6 V$ C" E  Item bom = bomItems.getItemByIndex(i);
0 b# i. ]1 S* {, d( t// Get a handle to the related Item for this relationship Item.
  P: t( I# l& `3 i  Item bomPart = bom.getRelatedItem(); 0 Q) V/ |! }$ o& A4 X7 n1 z

5 a( t! P2 t! f; M" K; b  content += "" +
! W9 C! y% ~% z: [. d    "<tr>" + 4 b0 J  h& z& G2 ^
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
' B; O, w# ?% F1 K4 V      "<td>" + bomPart.getProperty("description") + "</td>" + $ m" b8 T* r9 q- T7 t) s- k
      "<td>" + bomPart.getProperty("cost") + "</td>" +
3 e" B, P9 \5 L3 R: H9 c; M- g      "<td>" + bom.getProperty("quantity") + "</td>" + * L0 M0 T3 v8 d0 t  [
    "</tr>";
' ^( L& J% K# q4 ]; Z7 i8 f1 ^$ k} * R: P9 b4 F  w
content += "</table>";
% t) Y% |: o  |& ?  D
* L$ e+ G. l9 S# r, ~2 |return innovator.newResult(content); " M* c6 ?: F: J2 H9 {8 D
$ K' ^: P% n! O% N5 O1 ?

) i  V+ p* F( u$ e& A' ]  A% l- _
2 |# X, M+ J4 a1 z1 J' N

# E; W$ o2 J( q6 {: q
! P% g$ H7 d3 p
- G1 R# p' T/ w: f/ c  v8 p0 w" U# A

! y0 Y& J2 n5 g    Page 46
6 m3 C$ U0 d+ T* ^# b
. s! ^% B7 r* j. _* @$ r3 b# MCopyright   2007 & Z3 [+ _6 z) z
Aras Corporation.  
/ a+ i' n! T$ c  I( m# w$ C* VAll Rights Reserved. 3 V. _8 u* ^$ y5 \5 a( S
VB.Net  2 E0 N; N" d/ Z4 r! N1 q  t
Dim innovator As Innovator = Me.newInnovator()
. H! h5 ~' w, T& p
+ V1 G. }. f$ z5 B# X) Z; `' Set up the query Item. ' J' n/ q: ]& c, N5 ?/ ~* ]. z
Dim qryItem As Item = Me.newItem("Part","get")
9 X6 F5 ~$ K, H! Q0 ], ]qryItem.setAttribute("select","item_number,description,cost") ; N" i2 S5 d# s9 w  T3 `4 y
qryItem.setID(myId)
" |8 L5 h, D! Y 4 Z- U+ h4 }. H: r
' Add the BOM structure.
; O, v+ r" y3 _; Y+ K# @" IDim bomItem As Item = Me.newItem("Part BOM","get")
% N, \, e# [- G; ]bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
1 o% I; y' k! JqryItem.addRelationship(bomItem) 5 O! F$ r8 M' [/ n9 _4 o- p! I
1 M: h; n6 j# p0 I# `/ [) {
' Perform the query. 7 ?6 M5 ?( q9 S# P
Dim results As Item = qryItem.apply()   ^8 X; ]. K, h+ v

/ ~8 _. U. K1 }- O8 P; \/ n' Test for an error.
) ]* u7 w- I- _+ O2 k- l3 b' QIf results.isError() Then 5 n+ a0 v: }! {3 O. C7 X1 |8 p
  Return innovator.newError(results.getErrorDetail())
( g( M+ E4 l7 h7 C, {End If / O% W! L; M$ g, h; C! Y) z! d! L
6 M4 F$ F) P) E# c' G* ?
' Get a handle to the BOM Items.
( K& l1 d7 G: ?Dim bomItems As Item = results.getRelationships()
0 B; w/ g( ~. {, Z* m* K8 S8 RDim count As Integer = bomItems.getItemCount() 5 w7 r% Z6 X0 }* [  m, b  z8 T
Dim i As Integer
1 }' q3 g2 O( Y+ b/ [' f
$ b3 H/ u" {" C4 n' Create the results content. 1 m5 R7 k( B1 E. T6 u8 |) Q
Dim content As String = "<table border='1'>" + _
5 H# q2 x8 y9 O4 J1 t  "<tr>" + _
- B2 A8 Y" b" F    "<td>Part Number</td>" + _
8 ?! z0 d$ h4 O+ ?$ J1 r  ]" S    "<td>Description</td>" + _
$ ?. x$ B+ h" `* C    "<td>Cost</td>" + _ ' ?' D2 b& n; g; d' L
    "<td>Quantity</td>" + _
, f( }4 Z. w) J4 l) p  "</tr>" . X! Q5 m5 w% Q, K" E3 s

* ]$ `; k, I$ p3 n) q' Iterate over the BOM Items 5 d+ Z5 W  m  G; V9 C
For i = 0 To count - 1 & {& M0 }; @+ Y$ H! ]$ w
' Get a handle to the relationship Item by index. 8 k0 }+ k( h6 m4 m
  Dim bom As Item = bomItems.getItemByIndex(i)
! U/ s7 C9 s. D# m$ u& i5 ?, p
9 W9 ^- c. r6 B! Q5 G' Get a handle to the related Item for this relationship Item. & C* p( Z( X9 S) [& X: ]1 @
  Dim bomPart As Item = bom.getRelatedItem()
  `! ^4 m0 G" ]4 \- W
. m: o: _# ~# t9 V  |6 N  content += _ 1 e* p1 t6 U0 H: d& w: j/ l
    "<tr>" + _ 5 z5 E  d. f7 m' h8 \: o/ T( v7 h% g
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
6 U+ @5 u4 c% o      "<td>" + bomPart.getProperty("description") + "</td>" + _ / u% H! q" o, @, L) H* t% E
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 5 ]" s+ t" ^5 N, Z* l' f* M. \8 z5 q1 n
      "<td>" + bom.getProperty("quantity") + "</td>" + _ ) p) S0 p7 F' z: D6 W3 I5 f
    "</tr>"
6 Y- d6 J' Q5 r3 DNext & N0 E5 M  N! ?. I
content += "</table>" + E  y/ x  J* m6 M% h  k

7 L: ?. P0 e* w; s. V% dReturn innovator.newResult(content) 6 R/ S9 W- v1 b  J8 T; j3 x& g
1 P$ @) R8 s) V3 w4 n/ H: 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二次开发专题模块培训报名开始啦

    我知道了