PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
% C0 J* ~! X, G, s8 y$ X2 a9 a1 DTo query for an Item and retrieve its structure you build the query as the structure 0 x. y1 R( q# y# \7 [/ e* g
you want returned.  Use the IOM methods to add the relationships you want and
4 L6 e8 `7 Z' f0 {build the structure in the Item.  The server will return the structure that follows the 1 {0 }4 a! w% w5 H+ {
request structure. ) P5 Z* N: Y: M& W
This recipe illustrates several related concepts together, which are how to get a set   l" ~) j3 W; \
of Items from an Item and how to iterate over the set, plus how to get the related
/ v5 k, z& H3 c8 [* s5 _; t2 cItem from the relationship Item.
4 w! Y3 J  H% I# N6 [3 dJavaScript  
. N. z. j; u# J0 w) q( R5 ]$ n7 Fvar innovator = this.newInnovator();
: }7 I- u4 d1 R  w- K% }, u- m2 C
4 E8 B+ d5 z. Y// Set up the query Item.
7 `6 ]  k! c& Z; `  y' Tvar qryItem = this.newItem("Part","get"); 8 s7 H3 s1 s7 `5 L# [
qryItem.setAttribute("select","item_number,description,cost");
. d. n+ ^5 X% O) H2 rqryItem.setID(myId);   {! d. [1 m  d9 Z

) V& u' s# B8 A# W* S1 P9 G! C  G// Add the BOM structure.
, a' o- }8 W+ H; hvar bomItem = this.newItem("Part BOM","get"); # c1 Q6 R( S% l
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
7 }5 N: }: |% L' lqryItem.addRelationship(bomItem);
' K, U/ F( D' N0 ^3 b, M( X
9 N! n5 B3 u; }, S// Perform the query. * i( i; {- {3 q, R, Y
var results = qryItem.apply();
9 _3 k& x$ ?1 H- [. S
4 L( m' o1 A3 D// Test for an error.
6 F& ^7 I+ a) x: r$ p: nif (results.isError()) { - _. C* n) K) _+ B. V" d2 |
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
' h5 i+ n2 q9 I0 U! g, @; a  return;
. K5 D/ R0 i7 I; e} / D5 U8 d& x$ D6 ^

" R& [6 n1 h  K# L$ \// Get a handle to the BOM Items. 9 f* z& l" L- |
var bomItems = results.getRelationships();
5 D7 Z, O3 l5 _+ Q5 {$ Cvar count = bomItems.getItemCount(); $ i7 P& F6 K: d. M' B. [* g
- v6 j6 X. B7 p) h2 Q
// Create the results content. 8 \7 L( o2 Y: E  F1 T, C
var content = "<table border='1'>" +
& s! C& T- ^: g: G8 e  "<tr>" + ) ?5 y1 X$ X- ?9 z5 y4 c- z4 x3 O
    "<td>Part Number</td>" + 7 z" @7 P5 `! u1 [- N2 s
    "<td>Description</td>" +
, f+ C+ v: L8 Y    "<td>Cost</td>" +
8 G4 V& G( P/ ^$ h' ~8 [6 O/ F    "<td>Quantity</td>" +
/ P- D+ V+ \6 A$ J/ }# o9 Y5 r  "</tr>"; ; g8 q( F1 U0 J% }1 H5 [; p
$ c) t  v0 r, Y0 k' p* r
// Iterate over the BOM Items. . s. t! s* o0 i. ~* x- G
for (var i=0; i<count; ++i) ; [! h& T/ s/ ]7 m1 Y3 W
{
- |! K1 _0 D0 R7 j; F8 g3 q// Get a handle to the relationship Item by index. 0 S+ w2 z8 _% t& L) e" T- k
  var bom = bomItems.getItemByIndex(i);
& \# f9 d3 b' R// Get a handle to the related Item for this relationship Item.
( M: e6 ~; S7 c1 r  var bomPart = bom.getRelatedItem();
* x) M! U; M& Z; s" a ' H, B3 `: E3 A; c5 i) U) @
  content += "<tr>" + % e5 \: O: k% m7 Y- U. [8 ^7 p
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
6 ?/ D! T% E4 x      "<td>" + bomPart.getProperty("description") + "</td>" + ; R3 K7 D  H. @1 P0 V
      "<td>" + bomPart.getProperty("cost") + "</td>" +
# e* ?& r, }# y6 \# P: ~      "<td>" + bom.getProperty("quantity") + "</td>" + * j( m: i/ r5 p1 N4 b( D% S6 T
    "</tr>";
3 G2 s1 H, F: f, A}   g$ @* Z$ u6 r
return content + "</table>";
( B/ Y- a: a' g) x
- T8 q, B6 p) n: c5 I3 h4 j
* @$ x: [1 \; D+ b# I9 C
; U; l" z. S$ e+ ?. q. b/ k

0 f6 H2 V* a! hC#  
9 F1 ^5 `, {8 t7 m* D3 bInnovator innovator = this.newInnovator(); . A1 e3 u5 [' M0 U! Q9 ^+ k  N4 u
5 @8 L4 G6 G. Q! R
// Set up the query Item.
8 g. u" x3 ]& t7 N; j) oItem qryItem = this.newItem("Part","get"); ) `/ r) h; e+ Z' t: Y9 U
qryItem.setAttribute("select","item_number,description,cost");
' ]' P: i+ ^& s; e, @! z$ _; wqryItem.setID(myId);
, `& U1 |" g! s  x4 b' ~! R+ V# d : ]: `7 m% o( b2 P8 \. _% s
// Add the BOM structure. : \: r  K- L, g& Y" L
Item bomItem = this.newItem("Part BOM","get"); $ f) [, ]' Y6 K% r$ Q1 x) S
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
  B& s3 F" k+ i& N. x9 dqryItem.addRelationship(bomItem); " r4 {( }$ Y; N  t/ {  f1 e) y

- {$ L) Z& m& ^0 a" D5 l  \. I// Perform the query. ; x; q# E0 W# Z, @) u1 \
Item results = qryItem.apply();
0 q  w" e. e+ ]4 K" n
7 r& \9 w0 Q# C; r7 B( v, H// Test for an error. - j& F  |4 d6 ^- y1 ~1 o/ r
if (results.isError()) { " b4 @$ _5 C# I& z
  return innovator.newError("Item not found: " + results.getErrorDetail()); / \% j' ?* U' H
}
: ~3 c' z; z, H2 K) d0 j 6 _0 R7 h# n  V7 E1 G
// Get a handle to the BOM Items. ; ?3 }" d% I! T; e$ \$ J' M9 ^+ M4 q
Item bomItems = results.getRelationships(); & L1 r8 a# I( l6 d0 l  M
int count = bomItems.getItemCount(); 9 P. u3 _. Z# m: Y+ W7 F% O( S- O) L
int i;
. j8 v$ Q6 c% Z4 _3 ]2 Q $ Z: r, E* o1 z5 w* r+ s# t
// Create the results content.
8 }. |  W" n. N2 Y0 sstring content = "<table border='1'>" +
9 a7 d2 p4 B* k  "<tr>" +
9 G/ Q9 c, s8 L8 c$ f    "<td>Part Number</td>" +
* }0 c8 `) R& _+ o    "<td>Description</td>" +
& y: N* @9 w" `4 {    "<td>Cost</td>" + . Q( G- r' {" i
    "<td>Quantity</td>" +
8 f3 `3 d0 o/ @* r) G  E% M0 @  "</tr>"; ! G) ?4 _3 b# @3 C5 E0 d0 x
/ h2 ]7 J. F: \- b" I; I
// Iterate over the BOM Items.
* U' }4 a  l9 rfor (i=0; i<count; ++i)
) L4 ?( ~! A) w1 L  }* l{ $ u5 }& ^# Q8 R
// Get a handle to the relationship Item by index.
6 {* S7 I3 @. M# n4 X: J; ?5 [% Y* k  Item bom = bomItems.getItemByIndex(i); 7 r8 F* I& p1 `* w' a: D2 X
// Get a handle to the related Item for this relationship Item. " v; h9 J9 g& m$ z- D. I
  Item bomPart = bom.getRelatedItem();
* C/ T( ?& C0 X1 r9 Q
/ R" L) D6 R% ^: u  content += "" +
- A5 i0 _7 x; j7 K# Y0 X2 T    "<tr>" + ( C# {. D5 k  s
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ( L' ~2 c) l6 M
      "<td>" + bomPart.getProperty("description") + "</td>" +
, y9 Q5 h- r4 ~# b      "<td>" + bomPart.getProperty("cost") + "</td>" + 8 I, j6 _+ E; I; ~
      "<td>" + bom.getProperty("quantity") + "</td>" + # j0 t6 k) ~% A8 @; X" `
    "</tr>";
. w0 e0 H0 K: j! I2 j8 b}
. |/ X) z6 h: C5 k# ]content += "</table>"; ! j1 @4 G- b: E, ~$ R

2 l7 x+ w( |  P/ B0 ^return innovator.newResult(content);
: _3 F: @" Q9 W3 S$ C; d2 d# E9 S* b$ J& ^  k/ Q4 M
9 \, U2 Q7 [+ j* _. a
/ C- z# Z* t' |3 p

, t) p/ G! ]* M2 Q8 N4 b. ]7 W
' R2 b/ K' \* y# G, L

; Q6 U' P  _- H" L9 e
4 D8 i, B7 f" N    Page 46
6 e4 M3 a/ l0 P  u $ Q, D8 o8 q* d$ I  R6 G: P$ p
Copyright   2007
; h! f2 n; ~% W! \Aras Corporation.  & }! `% z4 S; @' Y, S/ u; y( [% W6 W
All Rights Reserved.
; B* Y* ]( k" x: m5 g& Q9 K2 aVB.Net  
' [) d4 e. [' D* ?0 Z3 H0 rDim innovator As Innovator = Me.newInnovator() * z; p4 ]& F, c: m( }7 a( o
* t6 D/ X$ F3 O
' Set up the query Item.
, @; U5 S" O$ L* sDim qryItem As Item = Me.newItem("Part","get")
  i0 c" y) G" m1 rqryItem.setAttribute("select","item_number,description,cost") 7 B3 I& M$ e4 f% e
qryItem.setID(myId)
8 C7 }* L0 x' ?  o7 ?  D! I! F" R ( I- T. o  A6 e$ E2 Q/ o5 M
' Add the BOM structure.
9 d2 b2 c) y! f5 h$ L; ODim bomItem As Item = Me.newItem("Part BOM","get") 7 A& ~( @& B7 c; O; D3 a. T% ^! s
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") , S5 v* @9 |2 q3 a3 @# m
qryItem.addRelationship(bomItem) 0 L/ B$ x- \+ f7 z: D- _# T

8 v' l( m7 U" s( N( ~4 R1 e' Perform the query. + \: n; m# @/ d6 c
Dim results As Item = qryItem.apply()
: P1 v5 B/ w% ^, i2 Y9 ]4 _
! a; v. x1 v0 i8 O1 {6 U' Test for an error.
, y3 p& x4 o) @; R0 `If results.isError() Then 5 W1 y+ Z# w' k+ g
  Return innovator.newError(results.getErrorDetail()) * F" I: W9 a$ o4 m
End If 3 U* |7 X4 F- x  G% l3 ?& j$ k

5 P- p% c% `9 T4 q' Get a handle to the BOM Items.
0 w3 g1 m3 }5 z8 r8 `Dim bomItems As Item = results.getRelationships() % V" g( U& X9 _0 D
Dim count As Integer = bomItems.getItemCount() 7 {, R2 q$ N1 h3 _& w8 }
Dim i As Integer $ x5 s9 R0 k% z6 y) \

2 k& ^# L  S# T' x6 n9 q  n' Create the results content. : S! d, i) J; L- p5 I4 }
Dim content As String = "<table border='1'>" + _
( @( w4 F2 i1 H! H  "<tr>" + _ ' w5 X3 u' ~. g& R9 P* _
    "<td>Part Number</td>" + _ : c. }# I. a$ r7 U% k
    "<td>Description</td>" + _ 7 l6 V( W6 h9 T$ u4 q" ^+ P
    "<td>Cost</td>" + _
3 S8 g: E9 m. N! ?/ l8 G    "<td>Quantity</td>" + _ : _% d8 k' P8 U
  "</tr>" 6 t4 N* z5 \% o& Z6 j9 S+ y1 J5 g
- }' E: f* C* m8 X, q  X- }1 V
' Iterate over the BOM Items ( T/ M+ n: t( }  a  Y" }1 J' ^
For i = 0 To count - 1 ) e& [$ i( c* ~7 Y$ V
' Get a handle to the relationship Item by index. - j1 Q' ^8 h1 Q* u& O9 r$ S
  Dim bom As Item = bomItems.getItemByIndex(i) - h  V5 i+ E! m. W: w& B* Z
# F/ i2 Q( p2 \( z$ D
' Get a handle to the related Item for this relationship Item. ; Q' o9 i# {, ?9 R  ~* A6 I' ?* m
  Dim bomPart As Item = bom.getRelatedItem()
0 ]1 W& j( t6 h 8 ~9 r( l* t4 C( r+ [  u
  content += _
$ }& y9 x) h- g6 u; a    "<tr>" + _
" F- i; g& P2 ?      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ . ]! O( J/ B. E8 m. \8 e
      "<td>" + bomPart.getProperty("description") + "</td>" + _
" R- {% g7 Q& R9 g# @      "<td>" + bomPart.getProperty("cost") + "</td>" + _ $ O& J# `7 k3 O$ m  f
      "<td>" + bom.getProperty("quantity") + "</td>" + _
- W0 \5 b4 @& q' |+ d' a( a    "</tr>" ; a7 X9 j; }* Q: V) V
Next
/ a! l& p$ K- N) mcontent += "</table>" ) w& Q& A' q0 l7 C8 `' x

8 P5 U6 G3 b5 q; c9 l/ uReturn innovator.newResult(content)
  N1 y; z2 l+ Y0 k8 n% r
, ~  G2 s; k( O) J5 I" M
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了