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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  4 H& \0 b) g5 z; ~- Y, W: X
To query for an Item and retrieve its structure you build the query as the structure 3 a. I  n+ `, [0 b4 P! u
you want returned.  Use the IOM methods to add the relationships you want and
% b4 r/ ?) U6 S5 Ubuild the structure in the Item.  The server will return the structure that follows the
, `4 o+ R3 X  N6 i& Arequest structure. $ {9 q3 [+ h% R. Z; a. Z
This recipe illustrates several related concepts together, which are how to get a set / `5 V( h  @  o0 D6 x. E
of Items from an Item and how to iterate over the set, plus how to get the related
4 z1 v7 R& t6 TItem from the relationship Item. 9 K- a" O/ P, @/ n0 `
JavaScript  , m/ v& o3 F. g" m9 B0 R
var innovator = this.newInnovator(); ' v$ n0 M0 d8 Q

. I6 @. o6 `( [: z// Set up the query Item. - H( [8 c9 P/ E: `' q" |
var qryItem = this.newItem("Part","get"); ' n$ ^0 R9 i; G
qryItem.setAttribute("select","item_number,description,cost");
! \8 m0 ?! _0 J) v- RqryItem.setID(myId); , e0 k- y3 _2 [5 R$ [( y' a4 k
2 v- W( z4 I+ c: @
// Add the BOM structure. # y5 O8 V9 B+ L: I( h+ Z* o
var bomItem = this.newItem("Part BOM","get");
0 @5 A8 {0 i& h% v5 c! {bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
; ]+ F, }! ?* e8 l+ S5 i+ b" H/ yqryItem.addRelationship(bomItem);
0 \; Y/ y6 R8 { / k6 ~2 [% o  i* v" G
// Perform the query. 9 P  ?2 n' b) ?1 E- P( {# d
var results = qryItem.apply();
1 B! i( x- ]* t# T
" T7 ?9 [6 s$ f8 k) G// Test for an error.
0 e) _5 g& G/ a1 x1 dif (results.isError()) {
# Z6 U6 {% r) G8 {, i3 g/ ^  top.aras.AlertError("Item not found: " + results.getErrorDetail());
' @3 k' N5 G! O+ @6 v- s  return;
& ~9 c; P  v) G" ]} 0 D% h/ i7 w/ c2 \7 o$ C

$ Z8 B. |. K6 s  M: F// Get a handle to the BOM Items.
* m1 W0 I9 Z1 t; t" m1 yvar bomItems = results.getRelationships(); ; T2 ^$ i  b+ i; b0 \
var count = bomItems.getItemCount(); # C% C: y. o4 P* H
! w9 Z/ V4 x$ {; L
// Create the results content. 5 A1 q+ }  n" _: b8 q
var content = "<table border='1'>" +
9 c+ z& p' J: x' o+ L  "<tr>" + * N5 u! t$ ]0 o3 k; W0 m9 {
    "<td>Part Number</td>" +
: T+ S% B* \# F! w! G7 m: T  k* s    "<td>Description</td>" + ( T- G, ^8 W2 o
    "<td>Cost</td>" + & z5 V' f; ~) Q1 N5 G8 b1 C, o
    "<td>Quantity</td>" + # g$ f  o! x. M7 @0 y9 c
  "</tr>";
; a" f' n' h" P1 N4 M: [6 ?
0 v/ v: p7 t( B- F4 w// Iterate over the BOM Items.
0 {: w3 s2 Q3 {. \for (var i=0; i<count; ++i) 3 E9 {5 U. ]- `; y
{
" i1 K; e, T) [: n// Get a handle to the relationship Item by index. ) c' t7 L0 V3 q: E7 y' r0 R
  var bom = bomItems.getItemByIndex(i); ' a, r6 i0 W' A% `* E3 u
// Get a handle to the related Item for this relationship Item.
  n/ ?3 m& _' U+ F  b6 L  var bomPart = bom.getRelatedItem(); . u: @6 W% ^! B! |
7 z2 f7 C5 D. a- a9 p; z, t
  content += "<tr>" +
5 N0 {4 [  u" [; C" u" q# y      "<td>" + bomPart.getProperty("item_number") + "</td>" +
3 ^" e0 @- \: T/ [      "<td>" + bomPart.getProperty("description") + "</td>" + $ h/ y4 o6 j" P. S3 x. l
      "<td>" + bomPart.getProperty("cost") + "</td>" + 8 p+ P) N/ P" u' M7 |
      "<td>" + bom.getProperty("quantity") + "</td>" + ' e1 D( f2 l: `
    "</tr>"; ! [( q+ i; h8 s- c
}
. I5 E$ c3 F& T2 [. |return content + "</table>";. ^5 B) u) k: y0 q; F

; ^5 s; B+ \0 o& `4 q$ T& f2 n$ D

8 W  b1 t5 N" i
7 P% W% I: t/ F( d) A' Q

( i6 @) w8 j( j/ n  u/ A; ?4 ]C#  
' [7 t- [# I5 |( }Innovator innovator = this.newInnovator(); + ~7 X- Y) F+ O1 V. y* f$ q3 T4 E/ Y

1 Q  B5 T* W" P; O// Set up the query Item.
& Q4 Z+ ^8 H- Z2 Q4 GItem qryItem = this.newItem("Part","get");
  K) d1 }0 o$ I0 B* v) cqryItem.setAttribute("select","item_number,description,cost"); 5 ~+ k4 a9 P: a5 {" M
qryItem.setID(myId); $ j/ `: {' |. h* X* F- Q, Z
! \9 S4 h" s. W% c2 e) x
// Add the BOM structure.
! N  \5 a0 g: aItem bomItem = this.newItem("Part BOM","get"); ; w  N- K, L: ]7 {) j* |, I3 N
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
& z& @- `* I3 S0 v" q; f& zqryItem.addRelationship(bomItem); 1 g6 F6 g4 G, c. v

6 F. G6 |1 H# b  ~: g// Perform the query. 0 I# _- [2 f: Y+ j# y; L4 x
Item results = qryItem.apply(); . }: P# o: ?' `1 Y+ y9 M) s$ m
7 t+ M" T  O  N2 P. h  _% X
// Test for an error.
+ s* I& Y  b( Q) @5 J- Qif (results.isError()) { 1 K% ?) N1 z- |) T4 Q0 a& P
  return innovator.newError("Item not found: " + results.getErrorDetail());
) }6 ~5 F+ _* }}
4 C3 h4 [5 m6 F# H * K" N* o5 ?6 b2 r
// Get a handle to the BOM Items. " n; b9 q( B$ w( ?) R
Item bomItems = results.getRelationships();
: h0 w: Z6 ~* kint count = bomItems.getItemCount();
0 |# E& O2 A* H3 u9 d2 jint i; , r& R  M; D/ a# m$ W) g1 ~

& `+ _3 R" A  j9 a3 J. B" k// Create the results content.
: n1 [! B1 `* V. A3 p& ^string content = "<table border='1'>" + 5 ^& Z6 U  y& h# Q/ W1 S
  "<tr>" + . y8 X) K5 }4 T+ R; F$ j5 X0 T
    "<td>Part Number</td>" + * k" V0 R) f  ~
    "<td>Description</td>" +
/ Z+ o5 ]9 I/ @! L    "<td>Cost</td>" +
/ u: d/ \5 U4 E% f. s: e; w    "<td>Quantity</td>" +
6 ], ]% Q* R3 Q  _  I( A# X  "</tr>"; 1 M* j; H8 J5 H2 I( e9 |0 b
( A4 Z: D+ I! i# a8 K. U
// Iterate over the BOM Items. , C  G6 i3 N$ I% z$ S
for (i=0; i<count; ++i)
# w$ r! i6 d% V1 w2 V9 D{ + K: R, \7 r# Q$ a. C8 h: U( F5 `/ a3 n' Y
// Get a handle to the relationship Item by index.
( W+ U. f# R2 J3 @1 t8 x  Item bom = bomItems.getItemByIndex(i); 1 M/ Y' b2 z- S' n2 X% ^/ c1 N
// Get a handle to the related Item for this relationship Item. 1 \# g: n. F2 t( ]: ]; ^0 f
  Item bomPart = bom.getRelatedItem();
3 ]/ N6 A4 z' t
! {+ ~1 l' ^3 M7 Q2 p  content += "" + , ?, _7 C( O: y4 H0 |4 C" M+ i) z
    "<tr>" + 2 @* y' p, W: l- y, V- \  s
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ! `$ v. t7 z9 X
      "<td>" + bomPart.getProperty("description") + "</td>" + 4 ?7 M" W& B* {1 x& G6 E. c2 D% Z
      "<td>" + bomPart.getProperty("cost") + "</td>" +
% I5 i/ Z" ^5 e      "<td>" + bom.getProperty("quantity") + "</td>" + & f" c9 r1 J5 {8 n1 S0 d
    "</tr>"; + g, p' K+ Q' C( \" l, ^
}
+ M" @$ X9 ]0 s) lcontent += "</table>"; / j/ B) g: G) l* b

# E6 B: u9 Q: v# _- j& L! H# oreturn innovator.newResult(content); 1 h' {) @# B2 O

7 ~/ P1 D* E5 ~, \3 g" N

2 `* E0 [5 E3 x* x8 Y6 W( L" z# W! h( f0 ~! e

! x  s* M+ ~! b3 W. [0 C# j3 J: E; ^7 l  |1 R( h$ U" U

* E2 w0 _0 p+ ]& K ! j* E: ~! r& b; S
    Page 46 , E, l% ?; v, b6 ]) _- U; C1 h

$ _7 k$ A8 B. U! p- z: a4 `, vCopyright   2007 9 Z0 l$ [. V+ K2 v- c5 v4 _
Aras Corporation.  
) F+ ~3 {2 r" u/ H5 [7 E- pAll Rights Reserved.
& v9 V1 i% H: lVB.Net    D! E; f$ ^5 V
Dim innovator As Innovator = Me.newInnovator() $ ~+ A" l& s: j. Z. r

, D4 @8 k7 w" v9 Q) x' Set up the query Item.
! k: Q3 P; Z4 Y+ z9 R& FDim qryItem As Item = Me.newItem("Part","get") + t) e5 o5 Q1 @* d; @9 ^/ C
qryItem.setAttribute("select","item_number,description,cost") 0 D7 a) q. e* O/ I# u. @5 s
qryItem.setID(myId)
# k9 H* L) J+ I7 t   h* l) ]# ^5 x
' Add the BOM structure.
! |- i  x3 @( ^! a! N8 M; TDim bomItem As Item = Me.newItem("Part BOM","get")
" {; _+ M( x/ Q, u/ F9 ybomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") + N4 w2 k4 a! b' O7 ~
qryItem.addRelationship(bomItem) & ~- a0 r/ z3 `" H" L

4 N  l+ _- R% Y- l+ g' Perform the query. 7 R1 W2 R! e  w; V+ W2 p
Dim results As Item = qryItem.apply()
# e2 [) D$ V- O3 ?1 o 3 [: H$ J& [* C$ P( t  I$ y, i
' Test for an error. + t, E% {& m6 {$ }& s& D
If results.isError() Then
' K$ t" }2 Z) N4 a$ I/ K  Return innovator.newError(results.getErrorDetail())
: G% M6 |& S, h! mEnd If / S2 w# F8 S( q
, X( m# @. ]1 k( l6 q
' Get a handle to the BOM Items.
% p" P- B1 v. ~8 HDim bomItems As Item = results.getRelationships() ! ~9 Q! W4 f3 F: k: a
Dim count As Integer = bomItems.getItemCount() 8 v5 o9 S5 a8 E" l9 i; x( j' e
Dim i As Integer
8 m- s* S/ \7 ^# j4 ]) U1 d. V " I7 w0 x; x+ L& X. J6 _  ~3 ]
' Create the results content. 1 r6 R2 P( t; l6 U+ R% h
Dim content As String = "<table border='1'>" + _
" U7 @; A: z" ^. N/ ^' G  "<tr>" + _
& Y2 c. N0 t) g- A% `    "<td>Part Number</td>" + _ & s" _8 {# p7 h4 |! R) e
    "<td>Description</td>" + _
2 C1 C  y- U" G$ B( ^! I& {    "<td>Cost</td>" + _ 8 A& t4 X" {5 \3 y
    "<td>Quantity</td>" + _ ( i& r, w5 F, ^8 d
  "</tr>" * ?. u* h# _& w; l9 m9 u8 ~8 M

' w/ V8 @8 g0 u7 a$ _' Iterate over the BOM Items
) s1 S+ E5 t/ k. |* RFor i = 0 To count - 1
7 s3 N7 O6 h! B* a' Get a handle to the relationship Item by index.
" k- `* X, s3 Z# p. d0 |; @  Dim bom As Item = bomItems.getItemByIndex(i) ! j  T* O  c- e& |! X9 r$ l9 }4 _0 A$ Z

7 o" V0 h: f' j+ l8 t' Get a handle to the related Item for this relationship Item.
4 |6 o- E) i2 d  Dim bomPart As Item = bom.getRelatedItem()   v, s$ ~, M/ \1 {

  F) O; j' a# b6 F' t7 d  content += _
& {: p7 ]& C# K, j4 \" t- q0 u    "<tr>" + _ $ d0 G' U4 ^. G* w% w
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ % l6 E" S6 D% F' w
      "<td>" + bomPart.getProperty("description") + "</td>" + _ ( d* H; z, U! i- P
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
' H( t. T( _; {# m* c( U      "<td>" + bom.getProperty("quantity") + "</td>" + _
$ I/ \8 t8 J; g2 h1 W    "</tr>" & p2 P1 v/ W* H
Next
8 R& o3 `" S6 y  Q- d0 |! G/ Acontent += "</table>" 1 m8 K7 l- i: j( V0 p4 I

4 s( V7 R  \  CReturn innovator.newResult(content)
5 P: Q' d: ?' V1 S& ~0 S" J( L$ j6 v  y- u8 p& F" J: X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了