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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
+ \# R% A2 M/ X0 H4 ]To query for an Item and retrieve its structure you build the query as the structure ; o! M  B# i9 p6 k: D
you want returned.  Use the IOM methods to add the relationships you want and " ?' X' F3 t/ R1 y0 K
build the structure in the Item.  The server will return the structure that follows the
* L+ C/ z  b5 hrequest structure. ) S  ?5 w7 C% H( V+ p4 W4 a
This recipe illustrates several related concepts together, which are how to get a set
- |( r5 [+ @5 @" x7 g) U; bof Items from an Item and how to iterate over the set, plus how to get the related
5 R( ^& H/ b1 PItem from the relationship Item.
6 y. ~0 a: O, T& c8 zJavaScript  
7 |+ O' o! A& }; v( M( }var innovator = this.newInnovator();
) H  n2 O0 X% v- w2 Q' g% K/ W/ `
9 p, Q/ i+ U% s) v2 X" q// Set up the query Item. ' y7 i  D" j+ X  H( L/ r' s
var qryItem = this.newItem("Part","get");
" P; i2 P- _0 k. t8 zqryItem.setAttribute("select","item_number,description,cost");
  x/ S3 |5 B9 c, J$ C6 m# V! C: ZqryItem.setID(myId);   A7 ~' ^7 i5 [4 Q+ A; Y' F& `) p
+ S! e5 t) q7 k8 a$ x5 e
// Add the BOM structure. 8 N& H- k# C( e& M2 }2 _8 j. m$ I0 B- L
var bomItem = this.newItem("Part BOM","get"); 0 p- w# M( N2 b9 j' x( V
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
) p9 j* G) W3 H; _qryItem.addRelationship(bomItem); 4 X8 n& A3 _# ^, `0 _) [1 D
6 j* f; G" W- t( s5 j8 a% `
// Perform the query. 9 U6 i' d% v: `7 h* J2 q  X. H
var results = qryItem.apply();
( M# h: V$ h" b! t  S
1 p' X/ c- C( @- U// Test for an error. : s9 a* |5 f; c+ N2 ^7 D
if (results.isError()) { ' o" A# ?! ?4 `/ e- b, v
  top.aras.AlertError("Item not found: " + results.getErrorDetail());   S! L& c, L: h
  return;
. J) a) {' B/ E2 B! d9 y} * Y7 @8 S0 W/ J- y" i7 C
; t5 W2 Q( J. S, n
// Get a handle to the BOM Items.
8 t/ r# Y+ j/ k8 k* z+ k7 a5 mvar bomItems = results.getRelationships();
3 h4 ]; q2 v4 c* A1 Cvar count = bomItems.getItemCount(); " ?9 T/ f# @0 ?7 d" q- b

# Q- R& E2 m3 j, m// Create the results content. + i. D' G5 M! R2 r9 [8 m" u+ o& Q
var content = "<table border='1'>" + " |& H5 V9 S1 P/ q  H' _
  "<tr>" + + X6 ]. _" p$ O  w  q5 p3 M3 Y
    "<td>Part Number</td>" + # l1 J3 D: S5 d3 C/ P: m0 B
    "<td>Description</td>" + 7 s( _/ f5 N+ Z- W
    "<td>Cost</td>" +
. H+ {) r; x% P) G/ W9 U7 z    "<td>Quantity</td>" +
6 G! e9 l2 W+ @* F, W  "</tr>";
; x8 S* q2 q7 r: W) @# j8 r" I
3 w9 T4 M- b2 I0 E// Iterate over the BOM Items. : R2 v, S% }/ Q* j
for (var i=0; i<count; ++i)
, F+ X- g- M' Y1 j7 h( R{
# }1 x- C! t3 s+ J8 S. ?3 L. |: q// Get a handle to the relationship Item by index. ( j2 c7 A# r& z7 V8 z2 ?
  var bom = bomItems.getItemByIndex(i); ( q" Q+ D0 p* W9 g* z
// Get a handle to the related Item for this relationship Item. # a# P8 f$ O) j; A+ P# `
  var bomPart = bom.getRelatedItem(); . Q, x6 x, p/ E6 g' `; M/ L* t
" c1 _: i; x' v" W, V& o2 L
  content += "<tr>" + % e, X+ i) [* v$ _  ?, |
      "<td>" + bomPart.getProperty("item_number") + "</td>" + * e8 E- L7 W; g5 T) o
      "<td>" + bomPart.getProperty("description") + "</td>" +
8 v" D- [" v6 V      "<td>" + bomPart.getProperty("cost") + "</td>" + / G7 ~) t6 Z  J0 d: `
      "<td>" + bom.getProperty("quantity") + "</td>" +
1 g: F. g2 O6 A    "</tr>"; 4 I+ w" k9 x+ Y9 z- M
}
' @! K9 Y% u. q$ ^: qreturn content + "</table>";# ^/ ^; s( o* C& `3 R- k5 o
4 j* D6 k+ e1 b0 L. G) Y0 s  F
) z( ~/ b. a: N5 m9 d3 l

. L4 t: e: f4 G1 N- L+ Q/ x

) o5 B8 m6 _$ }" b0 f7 }C#  ( ?* |9 E, J1 @* T. F
Innovator innovator = this.newInnovator(); 8 n( _2 o2 S3 N5 X; h7 P5 h8 \) a

7 s  ~3 l# r. y# B$ Q4 J$ l# V1 c// Set up the query Item.
* }9 p# g6 J: T; B( |Item qryItem = this.newItem("Part","get"); 1 Q! a6 P) R- @& c
qryItem.setAttribute("select","item_number,description,cost"); 4 _9 l4 t2 @- }4 D, q" f
qryItem.setID(myId); ! F5 u! `4 j+ q0 H" W6 ~& D
6 w6 k8 j. H& Z% O9 b3 U9 A# C
// Add the BOM structure.
4 @. ]1 v' w( W% ~$ |5 m& J! b4 \Item bomItem = this.newItem("Part BOM","get"); 7 `$ G0 Q  H3 w5 P& a
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 7 Z- T7 \+ W8 w6 l% j, y
qryItem.addRelationship(bomItem); * j7 l: q! b8 q2 W: ~

5 m! j9 ]2 G9 E- L& C( h// Perform the query. ' e  v# F  U$ N8 i7 i7 R, B4 [
Item results = qryItem.apply(); - X8 s8 u0 B1 y/ Y1 [
8 t0 P0 p5 I2 K
// Test for an error.   C. D$ F; H- v( U+ c9 N
if (results.isError()) { 3 P$ M8 n7 u$ h2 s8 m9 G4 E3 {4 F4 f
  return innovator.newError("Item not found: " + results.getErrorDetail());
8 J( Y. n  A( A9 d; D3 e! [8 E} ( r( _3 L( L( O+ L  _
+ q% V% ^# E/ j: H5 ]" {( ~- i) o
// Get a handle to the BOM Items. 9 P! M& h+ k4 y- e5 ^+ o* Y
Item bomItems = results.getRelationships(); 1 W& h+ [+ ~6 k  B
int count = bomItems.getItemCount();
: G2 t% E* j! H6 e  B7 zint i; + I  a: E) J1 _/ f
& n6 x% i' V& R' N
// Create the results content.
) g$ U0 E* n0 y, gstring content = "<table border='1'>" + 9 t9 Y% b% ?& E- t2 l( H
  "<tr>" + & y" o, B  `0 a/ u) `6 T$ o
    "<td>Part Number</td>" + - t; B5 [, ^+ q2 @; o. D8 s  z" Z
    "<td>Description</td>" + 0 Q9 J' f4 k: _& a6 _" l
    "<td>Cost</td>" +
  Z* W+ ^2 {% l( D% S! w5 q    "<td>Quantity</td>" +
$ D2 n2 l1 j. e3 v2 W% E* N9 u5 e  "</tr>";
3 i. I) b: r* \( z6 M
% `1 A* W( D$ k8 F' d$ i// Iterate over the BOM Items.
( b! ?6 |$ l4 x8 S  Z5 Afor (i=0; i<count; ++i) / J& Y# d1 \! K& Z; p; i; _
{ 5 r" r" {& ^5 G" u  |- V9 ]
// Get a handle to the relationship Item by index. + k! o; j1 e* F! `( A
  Item bom = bomItems.getItemByIndex(i); - R& v/ f8 T( C: G5 a! @" j
// Get a handle to the related Item for this relationship Item.
: }, z1 L. ^$ t  Item bomPart = bom.getRelatedItem();
' q6 ^% U; @+ n5 u7 E $ Z! D5 j, B9 C+ k' U' Y5 C
  content += "" +
, ^. N7 z; O+ G8 T+ T; _+ v, Z: s9 y4 j$ I    "<tr>" +
3 Z9 f  o; h! i7 i( C. j      "<td>" + bomPart.getProperty("item_number") + "</td>" +
, p7 y4 a& Z+ Z% D+ |0 t5 L: ]8 j      "<td>" + bomPart.getProperty("description") + "</td>" + + S: O! ?, t* m, I9 {
      "<td>" + bomPart.getProperty("cost") + "</td>" + 8 s% [* y) t( c: p* F
      "<td>" + bom.getProperty("quantity") + "</td>" + # `, Q5 L" J6 T- r
    "</tr>";
" ]3 Z0 W1 t( }0 v}
7 g9 ]2 w: H1 N8 w+ \$ [) _content += "</table>";
6 b; P/ J) f5 B! \# N2 g% H1 i
7 k5 `5 o4 a9 p/ v( V$ k7 E- m4 Mreturn innovator.newResult(content);
" G1 ^5 O% p+ U7 S7 P" ^" x$ ]7 t: K& Y

, Z: m0 V; Z" R- K/ `( s& |; }
' J9 ]  A5 c  n) k
4 C2 v6 i7 A' l! H5 ]

4 a5 ~& ]: O  C: t

# w/ t, g0 a  `% t 8 \8 ~' S' f% r- `' `/ x! R1 q& _
    Page 46 . E2 R/ [3 T' B% ?8 l/ |
6 B, [5 @4 v$ S% Z
Copyright   2007
: I: ?. h8 X: G  g5 f6 HAras Corporation.  2 Z, o) \# `/ R' s. p, A
All Rights Reserved.   [( W! e4 F  d  _1 A" U3 U* Y0 c
VB.Net  & t7 v4 N- u# L5 t
Dim innovator As Innovator = Me.newInnovator()
. S) [- Z# m+ a! y, z3 `6 P6 ?
# ~' U, l7 R9 u; H' _: K' Set up the query Item.
) \, N5 I) {: n4 J, X( ~Dim qryItem As Item = Me.newItem("Part","get") ! f0 p( o; g: ]% s8 g
qryItem.setAttribute("select","item_number,description,cost") / C5 h5 Q6 l+ l8 Z, _
qryItem.setID(myId)
, p! F: L/ {  n5 ?3 o0 I
" M3 o7 Q) A! O# D: h: N) p7 z& X' Add the BOM structure.
, S- l4 |3 r1 `Dim bomItem As Item = Me.newItem("Part BOM","get") : v7 M! _+ k# q8 a' B
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
) n; F8 D0 `/ ]! A" f/ U% V2 JqryItem.addRelationship(bomItem)
1 L. }; R# G; i4 O : D# q( e8 ~1 V
' Perform the query.
0 C* {. M& z2 P( m0 VDim results As Item = qryItem.apply()
2 ]9 H! a% ]" k8 G7 i! s
1 W9 ]( e( e% H% K+ O/ N& X! N, W' Test for an error.
) s) P+ q/ o8 k8 dIf results.isError() Then
! A& m. W  @0 @! P6 v) V  Return innovator.newError(results.getErrorDetail()) ' P6 s' A4 x8 l' {
End If
) K5 S8 {) `5 P0 c7 B8 m
. `  }  u# g, w' Get a handle to the BOM Items.
0 P- I- m+ E7 a6 B: l$ j  UDim bomItems As Item = results.getRelationships()
1 e& G$ D9 J, ]5 ^+ C& q: MDim count As Integer = bomItems.getItemCount() 1 h( p/ |6 v: X8 m! w2 i5 d9 C
Dim i As Integer 7 Q0 a  l3 A) S2 R6 r+ a, k

& K+ ?" E3 P/ Y" y' Create the results content.
! D% u' ~% t6 S5 e0 S1 B- EDim content As String = "<table border='1'>" + _ # d( x, o2 x, c
  "<tr>" + _ & X& m( g: y+ M: Y
    "<td>Part Number</td>" + _ 5 g4 a2 ?* I6 @4 a2 [  K
    "<td>Description</td>" + _
$ Q& M% O, c* c& D/ x5 J3 W  E    "<td>Cost</td>" + _ ! H' q6 w7 o% P
    "<td>Quantity</td>" + _ * L7 G2 Q( {) z! P9 D% k
  "</tr>"
" W# j( r- }4 t* B5 k
. H) g- R. l  b! R: r5 H' Iterate over the BOM Items
: Q: S) |- H- `' yFor i = 0 To count - 1 2 }' a  Y% d" `0 U# w
' Get a handle to the relationship Item by index.
, X& \# W( T% o) I- M  Dim bom As Item = bomItems.getItemByIndex(i) 2 k4 l3 k6 K  Z  @! ^7 `* X

0 }1 j. Y  K0 I& b( _' }) d. }8 s8 Q' Get a handle to the related Item for this relationship Item. 2 ?0 W, @0 }6 G2 L0 P
  Dim bomPart As Item = bom.getRelatedItem() 0 ^7 X3 A3 G( C4 S  M

0 d  E9 N- t6 x1 T% c  content += _
+ A# l* K/ B4 D/ H' A    "<tr>" + _
! Z, T1 Z1 E' F; |! n! x" H      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 E) g- O! F9 T  p! p
      "<td>" + bomPart.getProperty("description") + "</td>" + _
; o$ m" I, v! s/ Z6 W3 n0 r      "<td>" + bomPart.getProperty("cost") + "</td>" + _
! W6 c  j: L8 j+ v- Y5 t      "<td>" + bom.getProperty("quantity") + "</td>" + _ 9 T+ l: b4 {) o0 a. l9 M
    "</tr>" 6 g) p* v: e: l: r  b2 x9 {" Q
Next / Y/ }! r" N7 @+ h
content += "</table>"
* L2 Y% e" D  `1 ]1 I) E 8 ~. Z4 _. i) }, L' W  U3 |  V$ q
Return innovator.newResult(content)
0 ]3 P& z2 J; Y+ W
0 Y( K. h$ s3 m% S
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了