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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
/ D5 A% b( E8 I, t* jTo query for an Item and retrieve its structure you build the query as the structure ' E6 [. C" z  f9 ]$ T
you want returned.  Use the IOM methods to add the relationships you want and + M% q8 Z! z8 \, R: e
build the structure in the Item.  The server will return the structure that follows the $ \. Z. c# P& q7 S/ Z8 _6 ~
request structure.
9 Q/ _8 X7 O$ YThis recipe illustrates several related concepts together, which are how to get a set
1 h8 u# t/ u- _: j  o% d% {8 Aof Items from an Item and how to iterate over the set, plus how to get the related , e9 U2 i; q: Y6 Z8 r
Item from the relationship Item.
( a* A) \/ J% A3 }9 }/ n, \5 W  UJavaScript  
9 S0 R1 f( q9 M/ f% Wvar innovator = this.newInnovator(); & @; o4 p1 e& d
  E$ _  E- \( J- R! A
// Set up the query Item. : l2 L3 W6 z! w8 b# c  l' }4 U
var qryItem = this.newItem("Part","get"); , a9 N2 z- M3 B* k% N
qryItem.setAttribute("select","item_number,description,cost");
7 L5 S/ N$ n  ~  h; n% OqryItem.setID(myId); 0 i4 G) _9 A- M: F- m. J" s* @

. o+ g" `- ~6 h2 ^5 n6 @) C// Add the BOM structure. * \7 N* @  y$ p- |$ H
var bomItem = this.newItem("Part BOM","get");
% z; _  Z) [( s8 E5 K( Y; G0 Y" ubomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 5 R( L1 Y6 m. X% E4 W
qryItem.addRelationship(bomItem);
: J) a7 X1 {3 R! N9 l0 \( I$ B; u " b9 V/ J6 V: ?9 z
// Perform the query. % _; {4 B5 x' B: R
var results = qryItem.apply(); ' Y' f( B7 v7 {' Q- \7 A+ V# d
) p5 x/ I6 c8 u/ V
// Test for an error.
. F/ W, E+ \/ Y; T8 q5 z0 `) H, Fif (results.isError()) {
' R3 G6 `0 d$ Q5 g  top.aras.AlertError("Item not found: " + results.getErrorDetail()); * M/ v' [: |  {3 p5 W
  return;
- Y4 c- F% W0 K$ T}
; a( B" {5 c5 ~: |( O 7 F2 P# E3 j) J; y( m1 H
// Get a handle to the BOM Items.
+ I% @+ t- l. [1 T$ }' v2 Zvar bomItems = results.getRelationships(); 8 d3 ~1 F% L: T5 z& @
var count = bomItems.getItemCount();
. p9 U3 Q8 K( |. R * b3 S: G) N' u0 M
// Create the results content. 2 e5 x' v" ]1 Z2 D, X7 X! b2 w! Y; }
var content = "<table border='1'>" +
6 m2 @. f* D$ M7 ]9 B  d3 O. j  "<tr>" + ! y1 g3 s' V, {. `  j" U, y; z7 T
    "<td>Part Number</td>" + 1 l+ V: k) k2 \  V) {
    "<td>Description</td>" + ; L. S; q. b0 ]3 j" ], R
    "<td>Cost</td>" +
0 ?$ G7 j8 }0 R0 z6 |    "<td>Quantity</td>" + & t# I! E; d2 m6 a; W4 @4 C2 T6 O
  "</tr>";
0 {  h( @0 a: }6 @
) I9 Z/ m- @0 ?& b2 A' q* W// Iterate over the BOM Items. 4 z% S8 I: h! |
for (var i=0; i<count; ++i) ' i/ k3 S* |2 A& A9 m5 y
{ + [$ b! g/ z) y% |9 [7 q6 U
// Get a handle to the relationship Item by index.
; j! s. b2 |$ j; A! j9 @  var bom = bomItems.getItemByIndex(i); 5 f3 o4 C# x" }; W0 t2 G
// Get a handle to the related Item for this relationship Item.
) V4 U# Z+ k2 G, S/ S  var bomPart = bom.getRelatedItem(); 5 _! b* s3 G6 i% u! J* t& \

$ h& e0 `$ f( Y" K  content += "<tr>" + ' _( v7 s) l. N  D3 e+ B5 L
      "<td>" + bomPart.getProperty("item_number") + "</td>" +   y. w4 f& |  F6 h: g2 b
      "<td>" + bomPart.getProperty("description") + "</td>" + , w' N$ P7 h0 D) u' G9 p
      "<td>" + bomPart.getProperty("cost") + "</td>" + # e, x' C) w3 b5 E0 _
      "<td>" + bom.getProperty("quantity") + "</td>" + - i7 J' e! P. k% e/ U
    "</tr>"; ; y+ X. O" ]6 j6 [8 s
}
- F0 \/ D5 Y% J, Dreturn content + "</table>";
3 y! G) V& S; u- G/ D& ]
3 g9 |) C8 V% m3 J* g9 S. c8 o

9 {; o5 P; C8 h* Q; J' J
0 k3 j3 H, `- u, f* p+ @: t. V
. h. _, L8 n. U3 W
C#  
) |: v# U3 e8 o. @! rInnovator innovator = this.newInnovator();
) F+ M; w  j0 N" ]. G7 f9 L: m
3 N4 p; [0 A; X8 Q// Set up the query Item. " X/ [  G1 V+ F4 c' y+ ]* ]) I$ w
Item qryItem = this.newItem("Part","get");
7 r' [. Q( Y# A. B& S( dqryItem.setAttribute("select","item_number,description,cost");
2 b3 X2 x0 W+ R6 BqryItem.setID(myId);
. P8 t7 E. Y% a1 c* m! V 0 |; v. ?- |) {
// Add the BOM structure. $ X$ s& I! }' P0 k' y+ c
Item bomItem = this.newItem("Part BOM","get"); ; J- B+ m/ y+ v8 R0 z+ x' i
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ' K& q- d( Q) R" z8 c4 ^7 V; V0 d
qryItem.addRelationship(bomItem); , C  \& }9 ~, w% q/ S+ {: q" ]

! h0 y9 _, K+ }7 a// Perform the query. % l, o+ x1 g4 W
Item results = qryItem.apply();
+ U$ T9 k) r8 M6 R- M6 }2 d# A ; k5 h" ~4 v' V( O
// Test for an error. * g4 T. {: X" b: w% M
if (results.isError()) {
* m' j8 }2 N, s3 r  return innovator.newError("Item not found: " + results.getErrorDetail());
# n  p* S1 w$ L. K1 u+ E# L9 Y} 4 j4 O3 y9 \7 @! S) ?& T% C
0 w+ K+ Y4 \/ _) O
// Get a handle to the BOM Items. / X5 x, s0 D4 A; ^3 v( Z! `
Item bomItems = results.getRelationships(); 8 o$ @3 O2 U4 m3 F+ U
int count = bomItems.getItemCount();
3 [% f% a2 z; F. D$ }int i;
- h# C: @$ e  I ( C4 N" e7 e2 w7 c5 x+ y" o
// Create the results content.
& z8 ?. ~/ t5 b7 ]/ j0 B5 p' istring content = "<table border='1'>" + . a  L; Z; `4 J( j4 i* J
  "<tr>" +
( L2 v( c; @# A# S8 x    "<td>Part Number</td>" +
, A; T, K% S% e: I' Z" }8 w0 [+ _    "<td>Description</td>" +
! k& z# `4 v2 O: T    "<td>Cost</td>" + 1 H, G( H" I3 }8 ^+ w
    "<td>Quantity</td>" + . u6 x$ R7 p6 z7 \
  "</tr>";
7 s! D5 R: ]' C! D- J, I" D3 G
7 A& z, o+ U7 H# g5 m// Iterate over the BOM Items. + _" c- X  B/ |2 L  v
for (i=0; i<count; ++i)
% C3 y# v& T4 ~" x% k# c5 W' [$ ~{
# q  U7 A4 H' K2 }& y// Get a handle to the relationship Item by index.
5 @* D; o* n+ K  Item bom = bomItems.getItemByIndex(i);
( U5 i, V5 n+ r8 i/ J// Get a handle to the related Item for this relationship Item. # g) {* `3 K& l
  Item bomPart = bom.getRelatedItem(); % _2 X5 g% L; }  h0 s2 `) p# c

- O6 k8 w0 Y* ^2 S9 y  content += "" +
: }$ G/ T. H8 m( c: g# @    "<tr>" + . i0 R3 P* Z" ]: z. X, r
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
% D8 t# R2 J# G- z/ X      "<td>" + bomPart.getProperty("description") + "</td>" +
1 `2 u0 Q; W* _" L5 Z  m      "<td>" + bomPart.getProperty("cost") + "</td>" + 2 \( f% r4 X% Z" r' Z
      "<td>" + bom.getProperty("quantity") + "</td>" + & o  {5 H4 A* @+ l! \/ w
    "</tr>"; " m0 n; @  g" |1 N, U3 V
} 5 w9 |% Q5 |5 s, W
content += "</table>";   s6 d  [+ R# [9 |$ U( y, Y9 _  j
9 H( X& `" ^  J: [$ h
return innovator.newResult(content); 2 l- Q0 I4 |2 a
" q- o/ a, _9 ~8 e$ L  [; _% W% D3 [. N
; O0 ?% o6 }" Y4 s/ a* x' O

# T' k4 R2 }- Y( o! U
" D; o9 l0 P- S9 [$ d* A

; _) @* _7 m  m. E+ u7 s
9 X/ {8 }) `0 L) c

/ a. \" \  U; t- z    Page 46 3 H! j" q0 q9 Q% [7 M- f

- F. l1 k; }5 C* LCopyright   2007 9 n) Q* Z, Z! I
Aras Corporation.  0 P6 P4 w/ @% _5 v
All Rights Reserved.
+ m% k" z4 A  {# s4 P0 SVB.Net  
- G; G, {- G5 u' ~- g+ \8 ODim innovator As Innovator = Me.newInnovator()
3 g& [, O' B/ i( Y" a ' R1 G* b" i" L6 i
' Set up the query Item. 2 H. s% U3 ^* Y! W: V! Z- ^. r
Dim qryItem As Item = Me.newItem("Part","get")
) }) g, y1 Z8 F0 S- O) R7 `# K/ HqryItem.setAttribute("select","item_number,description,cost") % w' B, Z; N3 I( w: @- B2 ^% X5 x
qryItem.setID(myId) 7 O$ ?) ~- [7 j' u; m

( }' r& T0 x" d" h. Z' Add the BOM structure. , P; r8 h" q/ D2 l
Dim bomItem As Item = Me.newItem("Part BOM","get") 2 H# e9 P3 B$ W9 h" c
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") * p6 X3 `0 m5 `  w' Z* q, ?$ a
qryItem.addRelationship(bomItem)
) m! e9 W+ i! a9 u4 m# ~ / l# n- f& U/ T) ~, t
' Perform the query. 9 T4 S# Z- a; l8 v
Dim results As Item = qryItem.apply() ; d  _) x4 X0 u5 u; m+ {1 Z, I# s

* O7 V5 W2 d& h2 l& M& j' Test for an error. ! O5 ?3 d) H7 r; d% o0 [
If results.isError() Then
, e" ?2 L. Z+ C; y  Return innovator.newError(results.getErrorDetail()) 0 X' x* e9 D% q$ A$ Z
End If   Q: w) G5 {: @7 a# ~

6 l9 s4 V4 J. \! O3 ^' Get a handle to the BOM Items. % Z! A$ b, o5 P1 z* g1 J- i0 i1 Q1 N
Dim bomItems As Item = results.getRelationships()
4 b. N& {+ m4 U9 o+ cDim count As Integer = bomItems.getItemCount() % O: w$ k7 d/ ~& d
Dim i As Integer 1 }7 N$ s" b3 \
# t, J+ R  {0 k
' Create the results content.
2 m# G- V% ?  h$ `7 `0 _Dim content As String = "<table border='1'>" + _ . U: j: l: `, B
  "<tr>" + _ 6 a+ G# r- u+ i% {
    "<td>Part Number</td>" + _ : o2 J( B1 t- r: f/ L
    "<td>Description</td>" + _
3 x- O1 N/ R/ W0 @9 f/ t    "<td>Cost</td>" + _
1 q; S& L/ v" F/ {# b" v    "<td>Quantity</td>" + _ # N4 I" E5 _  [; ~
  "</tr>"
! ^. T, }9 @# K: D
3 M" q8 }. F" W' Iterate over the BOM Items
& F+ h* t- K5 a- y3 K  BFor i = 0 To count - 1
' t0 y: V7 A  w" \% K: ?' Get a handle to the relationship Item by index. 4 c* M* U1 x* w
  Dim bom As Item = bomItems.getItemByIndex(i) ) \1 n) H0 T2 D2 d' s
1 C$ y2 ^5 `: t
' Get a handle to the related Item for this relationship Item.
5 R* U0 K) P9 ]. @8 _$ W: I  Dim bomPart As Item = bom.getRelatedItem()
* d, U' Y- b9 d" N5 z! p/ _1 m2 h" `5 q
8 V8 N0 O5 G& `; d  content += _ / b! _, d$ [( c
    "<tr>" + _ & J! h  M3 K) W0 b1 Q0 I
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
8 P" C) A& ^% R2 \3 i. Y& i! v$ ]      "<td>" + bomPart.getProperty("description") + "</td>" + _ & |/ D5 V# ~% `2 e* D8 s
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 8 f& ~0 f* w! p$ Q' X- B0 Q
      "<td>" + bom.getProperty("quantity") + "</td>" + _ * A, X# l% ^. m6 w
    "</tr>"
+ ?) a' K1 l  t0 \" m3 Y1 aNext
) w# u! W: ^( Q: {+ Fcontent += "</table>" 7 G3 N1 M  k% J- B" ~

6 L: S) M; M% z' f* BReturn innovator.newResult(content)
# l/ S; |2 I. E. F) [# M; V/ }! i2 ~% Q( c* |) U0 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二次开发专题模块培训报名开始啦

    我知道了