PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
% ]) {6 ?; y' S! f* k  A7 mTo query for an Item and retrieve its structure you build the query as the structure
6 C# t1 [0 B" A/ jyou want returned.  Use the IOM methods to add the relationships you want and 0 z' `# {2 N( N1 A' O- |+ h
build the structure in the Item.  The server will return the structure that follows the
$ m/ j) [4 U- b7 W5 Mrequest structure. " b3 {" U+ f! y2 t
This recipe illustrates several related concepts together, which are how to get a set
; K6 I# y! U2 M4 H9 D( K7 Uof Items from an Item and how to iterate over the set, plus how to get the related
( e2 L: p% J; @/ G2 H6 YItem from the relationship Item. 4 l' v; |# N" f- t* N
JavaScript  
( ?$ `+ p2 v5 L' v9 R3 lvar innovator = this.newInnovator();
% c3 |' W9 n7 i
' v2 i1 _( T9 ~1 L6 a6 q// Set up the query Item.
" X! k& F1 ^" L1 T" G. N2 `# X( H; Jvar qryItem = this.newItem("Part","get"); / ^3 H9 g8 M& X6 K& h1 V
qryItem.setAttribute("select","item_number,description,cost"); ( o5 e$ e" b) T: V' L3 a1 @2 f
qryItem.setID(myId);
$ X7 \8 ~" V  \
  o- [+ R; h1 s// Add the BOM structure. 5 d0 a5 {: z3 T+ ?
var bomItem = this.newItem("Part BOM","get");
2 c2 _  M! K8 H! ^bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
+ A: v) W$ Z9 w& O% J  C8 ~2 LqryItem.addRelationship(bomItem);
% Y+ q8 R5 u+ S) ?( g# S$ F; s
# S' v" [* J; |1 \// Perform the query. 7 \( |4 D) i$ i1 E" |
var results = qryItem.apply(); $ K2 A! ?( F) F9 n/ C/ j, _2 f
- n* J- s, s" q  }7 N
// Test for an error.
( d* b& N! |6 u4 B" J0 |, T( y/ W/ Mif (results.isError()) { 7 ~0 c, h. {, S: ^
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
1 h7 d$ c- D/ N( O  return; " u# v5 y: x9 w; |: p
} 0 @- v# i* u! H9 I) @
7 X6 ^+ n% F6 W
// Get a handle to the BOM Items.
' S. ^+ ?8 S" M2 k! M' Dvar bomItems = results.getRelationships();
: r* {. n, `+ K4 ?$ a: ovar count = bomItems.getItemCount();
1 f' ]6 _+ Y. U) b8 C, F; d2 @ - }1 @7 |6 E' j
// Create the results content.
1 Q0 E9 n, i3 F3 p" Zvar content = "<table border='1'>" +
5 j+ R' H, }$ Y3 B/ A7 Y  "<tr>" +
3 T- r; F" M3 m) W, f3 l    "<td>Part Number</td>" + 5 N# U& e- C$ K/ `  ~# j
    "<td>Description</td>" + 6 B( m! j7 L9 Q5 U
    "<td>Cost</td>" + - S1 `8 l* s3 v( o
    "<td>Quantity</td>" +
; ~# H: R3 V1 ~2 h" h7 Z  "</tr>";
% m) J! C4 L) l
4 e) X) z# Q3 S$ s3 I/ y// Iterate over the BOM Items.
/ w& C! a; i( n) w, ?( w+ jfor (var i=0; i<count; ++i)
' K5 c) Y/ l* l! p& o) Q{ 4 j  \  D! ]2 F) e5 k' X0 v
// Get a handle to the relationship Item by index. 7 m. J2 S" ]  j8 e
  var bom = bomItems.getItemByIndex(i);
9 y4 M9 U0 C' u# u// Get a handle to the related Item for this relationship Item.
; U' K  R2 [. I0 ]  var bomPart = bom.getRelatedItem(); # e4 V+ p( K% s* ]4 z; [2 B: n# N: T
8 @3 x& j6 D1 C
  content += "<tr>" +
9 c) I) [! |, K3 \! b+ ?2 W      "<td>" + bomPart.getProperty("item_number") + "</td>" +
$ ?5 q* b, j5 b1 ]' ^1 Z      "<td>" + bomPart.getProperty("description") + "</td>" +
- g; x5 T& x3 G' ^& h      "<td>" + bomPart.getProperty("cost") + "</td>" + 4 Z$ ?$ S, w" n8 a, m  K7 A
      "<td>" + bom.getProperty("quantity") + "</td>" + 9 e8 r: {; q6 q$ \3 I; Q0 l
    "</tr>"; + s+ P  Z1 D' d
}
+ ^7 o% ?* j0 u/ y6 E5 Ireturn content + "</table>";/ j1 j3 o1 h3 J: \
8 H# z9 N$ y( o; H

. c6 W7 O4 l% }7 ?/ w0 P- _+ `+ K* n9 v4 _" w2 t; `5 {% k
4 {  s: S8 @- r6 E4 Y8 I
C#  
! }& c4 R/ Q6 v! _. ?Innovator innovator = this.newInnovator(); ! M3 p+ K7 r& I* f
5 g4 v9 P, u7 S4 x
// Set up the query Item.
. z3 _7 q( [- a/ m- iItem qryItem = this.newItem("Part","get");
9 J5 z1 Z- D3 c$ }5 vqryItem.setAttribute("select","item_number,description,cost"); 6 d! H' {" A; {3 U5 w6 E
qryItem.setID(myId); 5 M6 s' ^. H% B6 S0 a7 a8 X) W- G

8 ^* j) N. b5 h2 {- @// Add the BOM structure.
; }/ f1 i$ k5 A9 y( ZItem bomItem = this.newItem("Part BOM","get"); 2 M1 K/ G. l- m7 C3 V: S
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 7 I3 Q) {* k$ R9 P0 h, U' M9 S
qryItem.addRelationship(bomItem);
6 ]& k# Y: U; Y( o, }& D
  {8 j2 W. S  H// Perform the query.
" |7 q% X# Y6 K+ f  w; JItem results = qryItem.apply(); & W% v) U  z/ g. `0 M0 J

5 ?/ k3 e# ^6 S9 _* D// Test for an error.
% Y1 Y! |. h% W/ I6 `& ^if (results.isError()) { " f2 z" l8 s3 h% U- _5 l+ X$ v
  return innovator.newError("Item not found: " + results.getErrorDetail());
. t' U  K! {- _( d& u1 m0 @}
7 u1 N5 [. d$ }9 G  U, b) c" E + T6 W3 X" ^- A: U3 K# K- M9 X
// Get a handle to the BOM Items. : X/ H. Q4 H. M% V5 w3 F! y  M
Item bomItems = results.getRelationships();
) N+ Z4 x6 j& a; |int count = bomItems.getItemCount(); / @6 y' E; P0 w* D  d# V
int i; 5 t* T" N" u0 c3 K$ \
, w% Z% t) s& s3 ^' u$ C
// Create the results content.
8 }: v; r" f4 `( q/ Vstring content = "<table border='1'>" + $ G1 U! r$ v3 q9 F$ R
  "<tr>" +
+ q  m$ h* c. H/ k# A8 P2 K    "<td>Part Number</td>" +
* T% ]8 c  W* V3 O, G% u    "<td>Description</td>" +   `$ Y- T2 H$ g- l& E; Y6 Z
    "<td>Cost</td>" + . S/ P. a. }; S% J4 y
    "<td>Quantity</td>" +
3 F0 t6 R* i. L6 L7 V. T# F, @  "</tr>"; ) f/ t, {+ ?1 H( x, \8 a

6 D3 z3 }2 q/ I# z2 T5 R5 {// Iterate over the BOM Items. 8 C6 L8 k2 U0 @7 J
for (i=0; i<count; ++i)
1 f; L& d# i' z; p9 N/ [* q{
% q" |3 M4 x6 a# q7 B$ t: t// Get a handle to the relationship Item by index. " b$ ~* ^* k. y/ S  U8 M) b1 l
  Item bom = bomItems.getItemByIndex(i); ' N7 P# @" x5 p! y+ `6 T2 C6 d' C
// Get a handle to the related Item for this relationship Item.
" I* M/ m- Y. \4 K# m! i4 k  Item bomPart = bom.getRelatedItem(); / R" M7 b1 H' M" Y5 `
0 [4 ^. F4 B5 D9 ?  U; r" m# w) C" i8 b
  content += "" +
" }4 c# _! n5 Y# I4 t5 a' Q( V    "<tr>" +
. M& d1 W9 I; I+ x3 d      "<td>" + bomPart.getProperty("item_number") + "</td>" +   J# h5 h& T8 q+ z  S) ]6 I# ~
      "<td>" + bomPart.getProperty("description") + "</td>" + " v# R7 @# Q: S2 z9 k2 N" l
      "<td>" + bomPart.getProperty("cost") + "</td>" +
" ~" U4 ]' F, ?4 z      "<td>" + bom.getProperty("quantity") + "</td>" +
- J, f2 v! ^) D  K: `1 u/ ~' C    "</tr>";
& I; J, U7 c* [. E7 ?9 q% m} 1 z6 M% r2 J( L0 }! y, a- E7 s
content += "</table>";
4 u3 D) S# ~) i$ a 1 F; m: f9 h2 r+ k1 \; z
return innovator.newResult(content);
( t' l0 ?- G0 @$ j, ?: H% ~- j6 s/ m2 H3 m- \- O
( R0 O! c+ w: w1 L' S6 i2 k

6 I8 N1 N  ?3 w; ]

3 K3 M# e* A8 A5 p- ^% b) B4 S* O& a* l  ]) J4 G4 x

, l7 H( W( k6 s$ J& D# F
% t# j, Q* T, e7 ]9 n8 K    Page 46
4 ?, E8 A) L  c5 v$ G4 F
* ?( H3 K$ v- TCopyright   2007
# F: L7 W( a1 C+ n# U2 xAras Corporation.  
. N2 T* a- h8 c; v- x( ^+ V( Z  ZAll Rights Reserved. ! Z# A  ^# K! E4 X/ o! i
VB.Net  
! v1 v1 V4 M, n# ]& H4 a( ^Dim innovator As Innovator = Me.newInnovator()
6 B$ u+ o' n" h# {' P! G6 W0 V 4 M+ p8 M' @& J+ Z  c
' Set up the query Item.
! Z8 E; Q8 j! }% P" U- tDim qryItem As Item = Me.newItem("Part","get")
9 E$ f: t( |7 C$ ~/ J5 }4 D* P# p0 X/ lqryItem.setAttribute("select","item_number,description,cost")
3 `  }. F; w, LqryItem.setID(myId) + {: f7 k; H6 W4 _
  i% }' W* s5 a. s; I
' Add the BOM structure.
3 |1 e# j; |  j2 S# d" QDim bomItem As Item = Me.newItem("Part BOM","get")
  Z6 l, _" d3 ]/ S: Z# k9 \bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ) |3 T9 X6 z) M. h0 m
qryItem.addRelationship(bomItem)
9 R( ~/ j) \+ H& H8 {
% Q4 l7 B) N( J! j* \2 x' Perform the query. , z8 D9 \5 L  f4 |5 z% Q
Dim results As Item = qryItem.apply()
& g$ M7 Q" O/ s2 d$ i ' ?) h. l' p! c/ _: z
' Test for an error.
% F% X) D8 \+ n9 Y: X6 |If results.isError() Then
4 x1 u& W9 t1 [) i2 N8 ~. I2 G9 X  Return innovator.newError(results.getErrorDetail()) * w- a1 ]" p# b
End If
! ]3 C1 r, X6 C. s
3 \8 I4 Y( H$ A: C/ f: ~1 a5 R' Get a handle to the BOM Items. % y" k. B  F. \
Dim bomItems As Item = results.getRelationships()
, K# l: }! M( M. u- D4 iDim count As Integer = bomItems.getItemCount() + J8 I  N6 j# G5 M
Dim i As Integer
9 ]9 K; c5 k2 H6 C: u# m0 n9 \ , L1 ?" \% Q  p2 Q) O' y* Z
' Create the results content. 0 H8 h2 K; f$ L5 D% h9 r9 p$ J: @
Dim content As String = "<table border='1'>" + _
3 v" N5 _# a+ d1 @  "<tr>" + _ # X, n0 L0 `* b4 Y- |4 m
    "<td>Part Number</td>" + _
% n7 W* |. K8 Q& P    "<td>Description</td>" + _
' R9 `# [# ]' E( g3 u' Z3 b/ C! E, O    "<td>Cost</td>" + _
: L3 o# ~8 ~' B9 A+ k    "<td>Quantity</td>" + _ " L4 }! n; |8 Q7 m8 S
  "</tr>" - C/ _4 |% X5 y2 y8 u! q) A: Y
, {! {9 V. w+ C# W9 h
' Iterate over the BOM Items
6 ^! D, j+ q. w' x- j+ vFor i = 0 To count - 1 ' J6 F7 j! }- x' u. |. E" }
' Get a handle to the relationship Item by index.
" w" b4 ^& r( I$ T0 T  Dim bom As Item = bomItems.getItemByIndex(i) & @0 t, P& e" w+ U) S! ~
/ G* L8 e" ~9 j) X8 y5 A
' Get a handle to the related Item for this relationship Item.
9 I: Z/ E$ w8 s" u9 n7 l  Dim bomPart As Item = bom.getRelatedItem()
/ f8 \6 M/ r4 L1 z
' o: m3 q/ r4 M9 ^# q, h  content += _
  A! N! {# k- b* r) L8 e3 a    "<tr>" + _
- N& C$ ~$ E* u( _" F8 [  T) G      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
# ~4 j$ ?: E  c3 F: m% i      "<td>" + bomPart.getProperty("description") + "</td>" + _
" R; N5 h5 J/ X/ v. T, Z" `/ |" L      "<td>" + bomPart.getProperty("cost") + "</td>" + _
% S6 Q6 F; r' ~2 o% r# a      "<td>" + bom.getProperty("quantity") + "</td>" + _ 2 S+ R+ ?( U8 A
    "</tr>"
; w1 _  t/ E! k7 A0 X. RNext 9 @# O  j9 x! Y0 U3 Q7 {) I- x
content += "</table>" ! b! X# Q7 J, I3 C; a7 e

' P" Y" }7 k$ o2 M4 ]6 WReturn innovator.newResult(content)
1 d1 |; l0 g1 V9 @2 o
; i7 z  n5 E8 O/ `
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了