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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
QQ
发表于 2018-8-1 13:41:14 | 显示全部楼层 |阅读模式

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

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

x
Technique  : F7 I& z, F' v5 T; R
To query for an Item and retrieve its structure you build the query as the structure
) s5 f# g0 C7 u3 D, K( Jyou want returned.  Use the IOM methods to add the relationships you want and # R7 ^% @, L. @" O$ v2 l6 G9 m
build the structure in the Item.  The server will return the structure that follows the
" D0 J4 w( s# f7 ?request structure.
5 P4 \) t4 U9 `* R/ S& t' }This recipe illustrates several related concepts together, which are how to get a set
; k6 A9 \: V- T/ i  z9 A% qof Items from an Item and how to iterate over the set, plus how to get the related
2 H5 v4 s. v2 r" S' |- EItem from the relationship Item.
7 [3 z' y- h1 dJavaScript  5 |1 f. S! q6 \, d: A
var innovator = this.newInnovator(); ; }% J% Q1 U! c7 W' C) l, q5 z4 J, K" R

" C) }8 [  n6 y// Set up the query Item. & Z% Y5 {- R, l! i- e
var qryItem = this.newItem("Part","get"); ' }; H6 P0 ]4 R9 W& _
qryItem.setAttribute("select","item_number,description,cost"); ) A6 F' \/ {- f# E: o0 a/ J0 V
qryItem.setID(myId); + |  n* E+ H$ E* B4 `# r
& u1 {, d) @' ^+ ~/ G
// Add the BOM structure. # A0 e3 O1 n- ~6 B: D$ o& o) F3 ^" q
var bomItem = this.newItem("Part BOM","get"); 8 u5 H' G7 ?' ~. q$ Q
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
$ t2 |2 L! M/ y1 X% K# P; K$ oqryItem.addRelationship(bomItem); & E7 o" ?# P. u. {8 F8 [

( R9 \: \3 r1 G7 h& [9 [! B// Perform the query.
% V3 y' a7 R1 x* O. nvar results = qryItem.apply(); 1 e/ E' z9 x# ^! I8 @
, m# v; S4 ~8 y
// Test for an error. . f7 R) U: w: D" k7 `" g
if (results.isError()) { % F  A: K! ^5 |0 |
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); : |; \' `4 P- h6 A' |! k, y
  return;
: B. P  U6 q0 `# x% x}
/ i, B& L  U3 ?+ V3 C" S, R& J/ K * q1 y8 {) [- [  c- X% p
// Get a handle to the BOM Items.
( ~7 }' ?7 a1 I  M) a% |var bomItems = results.getRelationships(); 2 Y( b7 V5 }% @3 q# a
var count = bomItems.getItemCount();
9 c9 d9 r* R# ?% x: n
+ U) I, ^+ r, ]9 @9 I# Q// Create the results content.
9 x9 a* ^, g8 L& C1 |6 @& W8 Rvar content = "<table border='1'>" + ! z# V) c* r& O! a" ]1 O4 E
  "<tr>" + ) u. X  U# `, f! \# ]
    "<td>Part Number</td>" +
/ E: b, R; K" Y% f$ [4 S2 U- y$ v    "<td>Description</td>" +
- @6 S* v7 k. @! N1 S    "<td>Cost</td>" + $ r, |+ G; L6 ^0 c
    "<td>Quantity</td>" + ; C! {( D/ u6 d* G: P' ]
  "</tr>";
  g9 {; z2 o/ | ; X8 j* A8 P$ f  Q% A5 R4 S7 A
// Iterate over the BOM Items.
8 k& a( M3 _* ]7 K8 hfor (var i=0; i<count; ++i)
  f1 h$ g5 [. t2 h{
1 ~9 F9 k  N# F8 {// Get a handle to the relationship Item by index. : T# k# q+ k6 H# i
  var bom = bomItems.getItemByIndex(i); 9 F. t  ~9 F3 ~7 W. `5 o( R9 y* Z# S
// Get a handle to the related Item for this relationship Item. 2 g  J& N- h; ^6 F4 n
  var bomPart = bom.getRelatedItem();
: X; w: a) F1 q0 S% w; v
' B. G" b- ?3 l# Q' ?1 D  content += "<tr>" +
+ c3 u: X' k( @8 r      "<td>" + bomPart.getProperty("item_number") + "</td>" + ! e9 \  r7 p! h. l
      "<td>" + bomPart.getProperty("description") + "</td>" +
1 W7 g% P% C+ l) O7 O* _      "<td>" + bomPart.getProperty("cost") + "</td>" +
* p- ^) e# F* ^. ]" ^      "<td>" + bom.getProperty("quantity") + "</td>" +
4 Y+ {# G: {5 |9 B' e    "</tr>";
% r  h0 g- g6 _. @$ S} & J0 m; g+ R1 ]3 `$ o* ~. ?
return content + "</table>";
6 E1 m- V9 N7 ?2 ^1 r% c9 T* m1 k6 m* {; q3 N* E

( v  }  _# z- D. Y" _- k
$ d7 v& W, S( Q

. n3 n) p" `: k( T! ?/ ~C#  
" L0 z( ]* h  c7 CInnovator innovator = this.newInnovator();
% j+ p; R8 i* T: x, M 5 a# w' [% |1 }, ?1 Q2 r1 F
// Set up the query Item.
) _3 w# }& ~/ }! o% S$ f' l: vItem qryItem = this.newItem("Part","get");
( K) P+ Y' g' c: yqryItem.setAttribute("select","item_number,description,cost"); 3 r  n0 e, H0 \9 A& o0 i" t2 M" t
qryItem.setID(myId);
- e* m1 F- y9 ]% T! f, g$ n* k; e
; x+ L8 R, k3 q! N  A// Add the BOM structure.
. o7 E8 {4 z7 g& F3 jItem bomItem = this.newItem("Part BOM","get"); ! k0 n1 w2 Q5 Y3 W" a
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");   n( b4 e' ~9 W# o
qryItem.addRelationship(bomItem);
: S1 L9 T; `+ h6 m' F- F) m9 t+ B) p/ ^ . D0 d9 E0 N  R# G
// Perform the query.
3 N( _6 L. Q# K9 y# S! TItem results = qryItem.apply();
. L1 X$ a5 Y) ` % g3 {5 F- F& P% l1 R6 ?
// Test for an error. ; }8 c; e5 E# a. V* G+ r( {
if (results.isError()) { 8 B2 B: u& o8 c2 k/ D* D+ u1 P% j/ K
  return innovator.newError("Item not found: " + results.getErrorDetail()); ! ~3 {: Q9 E8 E7 G9 @) w; q
}
8 f% x4 [, u3 ` # l) G  e! `/ W+ S8 m5 @% k0 ]+ F
// Get a handle to the BOM Items.
* M$ E5 H+ H: x4 M& xItem bomItems = results.getRelationships(); 9 t" ^( ?! E8 u9 o0 q3 ]
int count = bomItems.getItemCount(); 1 Z' {4 j7 R5 p2 W' P
int i; 2 {! N8 p3 Z$ I. j9 B+ ~% s
8 X! G# D3 j! }5 v; m+ N) e
// Create the results content. 9 A; B. R2 X* |( X/ `1 M% V8 E, \
string content = "<table border='1'>" +
! e7 x# i; w6 ~7 j) B5 K; W# w, T  "<tr>" + 0 ~  `" L3 `* A3 W
    "<td>Part Number</td>" + $ q# T) R, u+ Q. C
    "<td>Description</td>" +
- D6 ?- W: n% D8 ~6 k/ [    "<td>Cost</td>" + 7 g4 T; \" ?( ~
    "<td>Quantity</td>" +
( S3 m( F* a' i- |1 C' e1 D' _  "</tr>";
7 V& [, a6 h6 Z  |) |! z7 ?. z 6 E7 Y- Z9 J7 z
// Iterate over the BOM Items. 5 F! |9 `+ L5 w; l$ t
for (i=0; i<count; ++i) 6 z2 r: N1 ^3 u
{ $ H; Z- q' x7 [6 ^  D' z+ e, v* f! ~
// Get a handle to the relationship Item by index.
& \; C! Y( i2 s; j7 w' F/ r  Item bom = bomItems.getItemByIndex(i); 2 x8 g# K( K, K* ?# j& j! |) j
// Get a handle to the related Item for this relationship Item.
" M6 O# k; r5 [+ }( F9 ?( f1 K. c  Item bomPart = bom.getRelatedItem(); 7 O5 @: `1 A3 S: z/ o

, z# _" _4 W8 t" K; H8 A  content += "" + % j' e0 r& z. ~1 p" w) b
    "<tr>" +
! \& Y( a' P  c      "<td>" + bomPart.getProperty("item_number") + "</td>" +
- }# Q5 C" z( a& v      "<td>" + bomPart.getProperty("description") + "</td>" + 2 _& \  e" T* h$ k. `, [
      "<td>" + bomPart.getProperty("cost") + "</td>" +
) T, B0 f; n) {+ x      "<td>" + bom.getProperty("quantity") + "</td>" +
8 f$ T7 G6 w# g8 d/ i3 n    "</tr>"; ; g- N  `+ S; X  Q
}
6 P1 D$ s: |3 G) y7 L  acontent += "</table>";
; y; j( |* C7 V) e' t& \7 Y , k9 ?9 x3 V, ]3 n* L2 o* `9 k
return innovator.newResult(content);
6 G8 y; _+ k  p2 A1 F9 c  p+ }5 \% `# ]) I9 A2 Y
, q4 L2 g0 l1 U- k% Q: g  f

9 ?3 |, H  Y- l
$ g# b# H7 o: @* w! p4 J

3 I$ V$ _5 _' h, }4 t0 L" ^

4 N; |6 o1 J5 E0 |9 n
1 v% o; z3 r. L$ u. ?* ?    Page 46   e% }, Z$ i- H1 F" V: r

( C+ Z4 t6 T! v  iCopyright   2007
: u, t  ]& u5 ~' h5 d0 r: U: k/ OAras Corporation.  
) @- i: q1 h7 h) TAll Rights Reserved. 2 u" {. T, y# m6 f
VB.Net    P! `0 f) k- m- k& V  v
Dim innovator As Innovator = Me.newInnovator()
7 i2 Z# S% y# B # s; L4 l$ g6 f; C- O/ K& D
' Set up the query Item.
2 \0 ^9 l$ h4 ~; S/ v7 S; vDim qryItem As Item = Me.newItem("Part","get")
7 V$ a  r$ P1 D% s& SqryItem.setAttribute("select","item_number,description,cost") * n9 i) W0 g: ]! i* q* M8 C
qryItem.setID(myId)
9 Q0 H( }$ c; H4 W! j. b
0 U, u/ `4 Q/ t5 f: [- d% C' Add the BOM structure. ; q" X& A) N4 y0 t
Dim bomItem As Item = Me.newItem("Part BOM","get")
4 g" Y0 |1 w) ~  C; ]9 G5 wbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
, p$ U7 [$ \0 V4 b# HqryItem.addRelationship(bomItem) $ S1 D* M/ |- m4 Q) m* Q# g
  L7 G/ y0 C, \: |
' Perform the query.
. {6 G  @  ]; U9 }Dim results As Item = qryItem.apply() . ~: `: k, u) u+ ~* A# x1 m

% z$ ~8 z  o, {' e/ y2 W% R' Test for an error. " O8 V/ f( H8 b9 A/ p/ p
If results.isError() Then
4 V8 @* ?, o/ N) i& V. ^  Return innovator.newError(results.getErrorDetail())
2 s8 }; F, K" E6 c2 r0 \- J. lEnd If - N3 x- n- ]6 o# n- f% a) F
5 e/ H7 {* k5 G* l/ u
' Get a handle to the BOM Items.
; K- y% c) g+ N. u; w9 q" z% w& b' Q: uDim bomItems As Item = results.getRelationships()
0 E. }$ T% z( A+ U9 i/ ?Dim count As Integer = bomItems.getItemCount() 7 h5 z; S! ?7 `* Y8 H
Dim i As Integer
) z' d8 u" E9 G" f8 A. I 6 x2 _+ W; G$ r# t
' Create the results content. + S8 }: X9 C. ]* e) G& a6 ]# z
Dim content As String = "<table border='1'>" + _ & x0 D" I: p; g: ~! @" m
  "<tr>" + _ * t0 G- }! |. `/ i( u
    "<td>Part Number</td>" + _ ! {. a- s7 C* z! ^" o
    "<td>Description</td>" + _
# X6 A( \/ e1 B    "<td>Cost</td>" + _ 8 V; e  g' H3 K! ]* r8 ~' ~
    "<td>Quantity</td>" + _
% `* L. e  O3 ], _5 e6 @  "</tr>"
+ B% m: V, x1 }/ f
1 L4 j' [; Q& P  U& D. @' Iterate over the BOM Items 1 |" s$ j. v5 S0 U+ Z, t; K0 g
For i = 0 To count - 1
! B7 t' |4 r1 n' Get a handle to the relationship Item by index.
. I9 v1 k: W! |. t, i0 ]9 B  Dim bom As Item = bomItems.getItemByIndex(i)
$ d6 y+ s8 q& M( L2 [" m
/ S' b8 ]! m& _' Get a handle to the related Item for this relationship Item.
5 q9 L" r' K# {6 ?  Dim bomPart As Item = bom.getRelatedItem()
6 i7 Y+ j4 r" w. ?$ X% z* @ : {1 s1 F" ?( C' V9 y  H% ?$ ~
  content += _ / I: S, Z8 _; [
    "<tr>" + _ - f2 a; S0 d  T/ l- u$ [5 ?0 m
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ , D0 o& F! _/ r1 u- P. v6 C: ^; T
      "<td>" + bomPart.getProperty("description") + "</td>" + _
4 p+ ?4 q& V1 [! K- H      "<td>" + bomPart.getProperty("cost") + "</td>" + _
4 d! q' w( b; p8 s: N# W      "<td>" + bom.getProperty("quantity") + "</td>" + _
+ j; V( {' U) x    "</tr>"
8 A. F* Q$ n0 W) I) E( |Next
* @/ Y9 t! i, P" W- Ucontent += "</table>"
3 |- X( S0 p6 i; Y" g . H6 J! d' B, t' ?
Return innovator.newResult(content)
0 e8 o: m, ^0 ]9 p/ Z5 H9 y( ]9 o% p
2 H$ ^, r- y7 Q" m( A
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了