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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  & e* J' N( H/ A/ Z& \( Q; ?
To query for an Item and retrieve its structure you build the query as the structure
" l+ Z! c, f! D' F1 h2 l; Yyou want returned.  Use the IOM methods to add the relationships you want and
- D- C  r6 P9 S; Q2 `5 s0 mbuild the structure in the Item.  The server will return the structure that follows the
* L" H& C# n8 Irequest structure.
( A- w+ K6 j$ D0 s) R# J. g1 gThis recipe illustrates several related concepts together, which are how to get a set
6 \0 ~1 i. G' U  U; Lof Items from an Item and how to iterate over the set, plus how to get the related 6 @2 w6 i2 ^2 X7 ?
Item from the relationship Item.
$ y8 k' R( Y3 C7 A1 v' j6 HJavaScript  
5 r) p$ ?9 N9 h' [var innovator = this.newInnovator();
! t" D0 e$ e4 O& i( `( w2 q - Y$ @5 l* P) n* T
// Set up the query Item.
% f2 V9 x5 G9 u. Fvar qryItem = this.newItem("Part","get");
/ m0 c3 h2 D$ M  UqryItem.setAttribute("select","item_number,description,cost");
) U0 d+ a: F' Y, DqryItem.setID(myId);
% m( ^) P6 L& o( C# v1 U # `2 V: _: R1 o& P1 U1 h
// Add the BOM structure.
  E3 U; O7 l" L( L! l3 Ovar bomItem = this.newItem("Part BOM","get");
+ n! @+ C9 q( \4 V' A( c% LbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
% w! H4 f2 @' z0 \1 y5 \$ A$ BqryItem.addRelationship(bomItem); ( q6 B% F/ q' D7 y

" d, U* D% w$ j/ S8 A// Perform the query. $ Q8 C, C: O- _  Y4 ~5 {
var results = qryItem.apply();
3 W; }" S" f0 }3 V# P! R7 p, I ; H5 a( o! W( m) `
// Test for an error.
. n& s; f' Q* nif (results.isError()) { ( p9 f# _) q1 g2 S( U0 A/ U. [
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); - m' ^$ h, T7 ^! e1 K
  return; ( ~9 a9 T& y) e- r
}
7 x3 `, r$ t0 h7 l  y: Q: ^& q   r. _7 ~& @$ V" V
// Get a handle to the BOM Items.
! ^% L" Y0 ?# i6 }: t* Tvar bomItems = results.getRelationships();
7 G  }  Y; Q4 S: Zvar count = bomItems.getItemCount();
5 f2 D7 Y2 n* K' y
. H8 _! n8 W- V# e! Q  s// Create the results content. - T# o1 Y! ~+ K% \
var content = "<table border='1'>" + 7 o8 k1 _' K: @# ?5 a; G
  "<tr>" +
$ w! T0 `, N8 ?    "<td>Part Number</td>" +
" c: L3 e- E. O  A8 \5 c/ U: Z" U    "<td>Description</td>" +
0 n) Y( y6 F, _; ~6 M' k! J  |    "<td>Cost</td>" +
1 W; G! O! F- }$ p    "<td>Quantity</td>" + ! C, B0 e% r* a6 c: V# A2 G
  "</tr>";
# V! x6 {4 }/ k. R( ~
4 T- T0 U0 S; g. K! V0 |" p// Iterate over the BOM Items.
& c; ^4 ?" ~! m& x3 t% Ofor (var i=0; i<count; ++i)
" \4 n4 T3 K( P: E{
* t3 b; S4 D  y+ @1 }" t! g// Get a handle to the relationship Item by index.
; j( |4 y0 N. i  var bom = bomItems.getItemByIndex(i); $ ^7 s3 m# W; t, U( B+ |! d
// Get a handle to the related Item for this relationship Item.
1 i: \. w% t* x- D0 |  var bomPart = bom.getRelatedItem();
' I' I! V* Y7 m- L - ~& ?( T% ~: d5 U/ u% L- s3 O
  content += "<tr>" + , I1 i% Q1 w$ I/ U  t, T+ ~
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
; i/ D5 M% d, J0 t      "<td>" + bomPart.getProperty("description") + "</td>" +
7 y, I2 Z7 _  e0 h+ l% Y# a% |      "<td>" + bomPart.getProperty("cost") + "</td>" +
2 r( I  K  B6 T/ I2 `3 b      "<td>" + bom.getProperty("quantity") + "</td>" + 0 g4 ^2 u! d- n8 o3 i5 o
    "</tr>";   E5 O8 n. t- |: R' a6 x/ p
} ) d6 E) h8 ]+ ~
return content + "</table>";$ {2 ]! }6 R% m* n9 k4 \
4 t; P  ?5 R) r+ I" K1 U" t

$ N# y3 n4 f/ r9 u6 z& J5 h) {* K( Q4 |& h1 ~# _

, ?9 D" c* K0 ]. UC#  
1 G# K+ ]- I/ n1 t, C! {7 e3 w& RInnovator innovator = this.newInnovator(); 1 z$ |- O4 c. b" Q/ V# w
! w1 R7 k+ o0 t  h; w
// Set up the query Item. * r7 {) D* L5 L4 ?5 @# Q3 q: d
Item qryItem = this.newItem("Part","get");
4 g' B# ^7 l/ m; ]6 H. Q( Y0 eqryItem.setAttribute("select","item_number,description,cost");   x. g3 g) v9 J! g1 y; [% n. O
qryItem.setID(myId);
4 ~' ~" k( N* k4 m
5 G# ~0 w; O" x) F// Add the BOM structure.
2 i$ k: q+ f2 Q9 J: IItem bomItem = this.newItem("Part BOM","get");
2 u- H0 h- ~( E3 S% \  {2 @9 d, \/ ~bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
1 U4 |$ j, l# {; |3 S" QqryItem.addRelationship(bomItem); . s. V5 j% j" H7 P

( U1 k3 f1 C2 M// Perform the query.
( |+ |; r7 p+ }, zItem results = qryItem.apply(); $ B: ?4 k0 Z4 L3 H& T8 U4 C' z

5 w4 N  d" g3 W& Y0 ^! m// Test for an error.
% n# C( D: B: D0 c! ~7 nif (results.isError()) { 7 Q9 n8 O6 ~, Z5 L6 |" D# h3 c1 |
  return innovator.newError("Item not found: " + results.getErrorDetail());
" T" M$ ~/ J3 {) E  C}
/ Q1 p3 `( H  e
! u# B/ f5 U) ?; P$ R  Y+ O// Get a handle to the BOM Items.
6 `# m$ y0 J) {+ \: c8 VItem bomItems = results.getRelationships(); " `5 \1 h4 a6 [5 n5 V$ d
int count = bomItems.getItemCount(); # D( w4 u0 D1 z; h3 N3 C; N
int i;
$ U: W1 C+ T& W7 k. j - S( c. V6 W6 J0 ]3 i$ Z
// Create the results content.
) ^: f$ o; m$ Q  f( w% F( Z$ \string content = "<table border='1'>" + 7 B' A+ n& g" Y" q( @
  "<tr>" + 1 \+ [% O9 {; ~5 X" @
    "<td>Part Number</td>" +
, \; j3 O, }6 ]6 B4 e' \$ K2 V    "<td>Description</td>" +
3 T- I! p9 P. e( f    "<td>Cost</td>" +
" S- d. t( i0 D' P4 q/ I# l8 G    "<td>Quantity</td>" + : H" K2 P5 }* L9 [) [  d( V
  "</tr>";
3 v5 G% o2 N9 E, F) E0 c2 Y/ m
: T# q9 w5 S$ U7 L! ~// Iterate over the BOM Items. 8 K& b; p5 h' c9 A  U
for (i=0; i<count; ++i) . N( W7 D2 A; G
{
% W6 X' f0 \: A, q) J& Y// Get a handle to the relationship Item by index. " E0 J& \. p" b& c$ `0 T# b* e5 A3 T
  Item bom = bomItems.getItemByIndex(i);
, ?- a( L7 |. Q5 v/ m2 M. o) w// Get a handle to the related Item for this relationship Item. 1 A8 x! ?* X$ K% {( ^8 m: Z# h
  Item bomPart = bom.getRelatedItem();
6 T+ K, @% q$ Z" s0 z* [: C
; ]/ m; ~' K! G' j. ?5 X  content += "" +
; e1 j8 M# k% v! N9 _    "<tr>" + 8 R) i& o5 W7 ^! `
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ' H: T* ~7 x* L
      "<td>" + bomPart.getProperty("description") + "</td>" +
* N  F2 I0 C8 T/ e5 e  A+ O0 q      "<td>" + bomPart.getProperty("cost") + "</td>" +
$ P! b  E. l. _) T) c* p      "<td>" + bom.getProperty("quantity") + "</td>" +
/ l7 l# j4 N' d' w4 u    "</tr>";
* X6 E# @. X: c2 ~1 W} , n2 k4 i/ Y% g+ V4 ?  C
content += "</table>";
7 ]( b6 V# h! @9 J. ?* h3 U
8 z( p1 \0 N4 m# Xreturn innovator.newResult(content); ) l7 b/ M0 d0 r9 c
, i' v4 R% m' ^3 {
0 n) `8 L2 L; f5 N! Y
. x; N8 ^3 g# r

0 m+ \2 }: N8 ]1 h
) O4 O/ p0 H. d: l, |; L  _
, X  {9 r1 M* r6 G: r
9 O( B% y5 \' {; u
    Page 46 , C" K4 x+ S; o
# r2 l8 p2 m# N9 z3 H. g2 ?) q6 j! w# J
Copyright   2007 ) s8 [  h- D2 N% g* |% S
Aras Corporation.    R1 d0 V# x$ U( u
All Rights Reserved.
- Z. Z2 Z/ _5 {) `VB.Net  
8 J% P$ ]0 ^5 x; F6 fDim innovator As Innovator = Me.newInnovator() ) a; g7 H4 p5 w! Y$ y

8 S4 @1 q' w% O: o, [* \' Set up the query Item. ' E- ?# v3 i/ ?5 H
Dim qryItem As Item = Me.newItem("Part","get")
( u# A' C/ {5 _qryItem.setAttribute("select","item_number,description,cost")
1 c3 r( v9 v; s% V* b5 SqryItem.setID(myId) ; N  B/ h8 J# ~; e" m
: Z) L9 `5 Q. Q! F( K2 `7 j, _! g. B
' Add the BOM structure.
' O% T2 i0 a0 z- e, `0 GDim bomItem As Item = Me.newItem("Part BOM","get")
- k5 T: j9 m! Q( ]. n/ X' a  u! \, RbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 7 M- N. v5 N1 E3 Z
qryItem.addRelationship(bomItem) . S5 D' a: J! W/ F7 s
  o7 L1 Y$ x' r1 T, e( ~
' Perform the query. 5 X3 G2 g# d* W/ C
Dim results As Item = qryItem.apply()
7 m1 ?, |& e# h& W& k
3 O- ~5 }6 u& }3 ^% A9 Y' Test for an error.
/ f: h$ A0 h& U' D1 f1 h5 r2 fIf results.isError() Then
" e4 ~& s( v; v2 y1 u4 L  Return innovator.newError(results.getErrorDetail())
" d7 p* b* M# H/ T3 Q2 y0 kEnd If + n- l" R" ~/ J) d7 t, u, Y9 X
, ~2 ]! p) |, b5 q8 @' U. C. v; e
' Get a handle to the BOM Items.
3 u' ~  K2 Z' y% G( X- `Dim bomItems As Item = results.getRelationships()
/ i- L: h! j' z' Z8 c! ^. XDim count As Integer = bomItems.getItemCount()
9 T- `* n& l/ t. V* L- iDim i As Integer
  r# l0 k) p* f+ Y( S # l0 v  B; e  C# Z7 y. \* l+ M1 B2 c
' Create the results content.
6 `/ ^/ S' a- V) JDim content As String = "<table border='1'>" + _ . E2 v+ E0 f" L* o3 i- g6 H
  "<tr>" + _ : d, I7 i. B% v: C$ L- H
    "<td>Part Number</td>" + _ 1 b: [, M  m* e0 B, T0 J
    "<td>Description</td>" + _
6 k. r4 m$ [! o! }    "<td>Cost</td>" + _
# `5 {, ]2 D4 U) M7 {    "<td>Quantity</td>" + _ , W& @! v7 ~% _3 v$ ^0 ^/ f
  "</tr>" : B. ]2 H( x; N. M6 f
7 a: @" X( Y2 g. }4 ?, m
' Iterate over the BOM Items
8 w3 q7 U' o+ M% V% CFor i = 0 To count - 1 4 k5 A5 f. k6 W+ F: Q7 n& n
' Get a handle to the relationship Item by index. / W+ J) G; y2 N* W7 C  `; T, \
  Dim bom As Item = bomItems.getItemByIndex(i)
$ T. Q7 C) M% |2 ^8 B " y; P6 v% I4 T* K
' Get a handle to the related Item for this relationship Item.
) D2 X9 @) f' z. u3 I  Dim bomPart As Item = bom.getRelatedItem()
, i( m9 Y) j3 F! R + r* \% C2 U, P: M) j
  content += _ / P" _/ i5 b. W" e6 X
    "<tr>" + _
' }) A* B* C4 z      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ ' m4 F9 b  T9 b( w: W) S8 U9 Y9 S
      "<td>" + bomPart.getProperty("description") + "</td>" + _
3 x: ?/ R% |/ |+ ~% X: c% L      "<td>" + bomPart.getProperty("cost") + "</td>" + _ * \* O. Y+ o7 k
      "<td>" + bom.getProperty("quantity") + "</td>" + _ & R/ J" b0 q  n8 R
    "</tr>" ( U  ]2 l) C; d3 e" G. B& ?
Next + d2 x1 ?" A5 b7 ]
content += "</table>"
# l8 D. k; X# G# p3 O3 Z- G$ C' g
. F& O; _  K  UReturn innovator.newResult(content)
' Y; r0 l2 o7 V- {% A" J
* f% _" S! l4 _, N+ N+ o+ g5 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二次开发专题模块培训报名开始啦

    我知道了