Scripting EA is a powerful feature. So it is possible to define VBScript, JScript, JavaScript within EA to use the EA capabilities or any other combination of your interest. Scripts are available as Search, Project Browser, Diagram or Workflow Scripts – meaning that they are startable within a short cut in that context.
I just wanted to show a result of a database query from an account-oriented datasource from the administration of Connecting Software – so i implemented a Search Script.
The result is as expected:
and here is the source code:
1: option explicit
2:
3: !INC Local Scripts.EAConstants-VBScript
4:
5: '
6: ' Script Name: SearchAccounts
7: ' Author: Peter Lieber
8: ' Purpose: Demonstration of database access to Connecting Software Administration
9: ' Date: 24-04-2013
10: '
11:
12: dim SEARCH_SPECIFICATION
13: SEARCH_SPECIFICATION = "<ReportViewData>" &_
14: "<Fields>" &_
15: "<Field name=""CLASSGUID""/>" &_
16: "<Field name=""CLASSTYPE"" />" &_
17: "<Field name=""ID"" />" &_
18: "<Field name=""AccountName"" />" &_
19: "</Fields>" &_
20: "<Rows/>" &_
21: "</ReportViewData>"
22:
23: '
24: ' Search Script main function
25: '
26: sub OnSearchAccounts()
27:
28: ' Create a DOM object to represent the search tree
29: dim xmlDOM
30: set xmlDOM = CreateObject( "MSXML2.DOMDocument.4.0" )
31: xmlDOM.validateOnParse = false
32: xmlDOM.async = false
33:
34:
35: ' Load the search template
36: if xmlDOM.loadXML( SEARCH_SPECIFICATION ) = true then
37:
38: dim rowsNode
39: set rowsNode = xmlDOM.selectSingleNode( "//ReportViewData//Rows" )
40:
41: dim myConn
42: Set MyConn = CreateObject("ADODB.Connection")
43: dim MdbFilePath
44: MdbFilePath = "c:\\temp\\test.mdb"
45: MyConn.Open "DRIVER={Media Gateway ODBC Driver};” &_
UID=administrator;ACC=ACCOUNT_ADMINISTRATION;” &_
IMPL=CORBA;PORT=8087;HOST=localhost;PWD=whatasecret;"
46:
47: dim SQL_query
48: SQL_query = "select * from Accounts"
49:
50: dim RS
51: Set RS = MyConn.Execute(SQL_query)
52: WHILE NOT RS.EOF
53:
54: AddRow xmlDOM, rowsNode, "", RS("ID"), _
55: RS("AccountName")
56: RS.MoveNext
57: WEND
58:
59: ' Fill the Model Search window with the results
60: Repository.RunModelSearch "", "", "", xmlDOM.xml
61:
62: else
63: Session.Prompt "Failed to load search xml", promptOK
64: end if
65: end sub
66:
67: '
71: ' Adds an entry to the xml row node 'rowsNode'
72: '
73: sub AddRow( xmlDOM, rowsNode, elementGUID, elementName, comments )
74:
75: ' Create a Row node
76: dim row
77: set row = xmlDOM.createElement( "Row" )
78:
79: ' Add the Model Search row data to the DOM
80: AddField xmlDOM, row, "CLASSGUID", elementGUID
81: AddField xmlDOM, row, "CLASSTYPE", "Class"
82: AddField xmlDOM, row, "Name", elementName
83: AddField xmlDOM, row, "Comments", comments
84:
85: ' Append the newly created row node to the rows node
86: rowsNode.appendChild( row )
87:
88: end sub
89:
90: '
91: ' Adds an Element to the DOM called Field which makes up the Row data for the Model Search window.
92: ' <Field name "" value ""/>
93: '
94: sub AddField( xmlDOM, row, name, value )
95:
96: dim fieldNode
97: set fieldNode = xmlDOM.createElement( "Field" )
98:
99: ' Create first attribute for the name
100: dim nameAttribute
101: set nameAttribute = xmlDOM.createAttribute( "name" )
102: nameAttribute.value = name
103: fieldNode.attributes.setNamedItem( nameAttribute )
104:
105: ' Create second attribute for the value
106: dim valueAttribute
107: set valueAttribute = xmlDOM.createAttribute( "value" )
108: valueAttribute.value = value
109: fieldNode.attributes.setNamedItem( valueAttribute )
110:
111: ' Append the fieldNode
112: row.appendChild( fieldNode )
113:
114: end sub
115:
116: OnSearchAccounts()
Scripting is a powerful feature. I use it for little nice tasks like glue code to call EA searches with parameters.
In case of searches I usually prefer to call an EA Search and fill in the Search string with the selection (ID, GUID) or so. EA searches also support concepts like wildcard (#WC#), selected Packages (#BRANCH#,#PACKAGE#), usage of different DBMS and more.
The problems with scripts are:
– Complexity and reuse
– Debug, Test
– Assign them to Groups (Browser, Search, Diagram, ..)
The pros are:
– Easy
– Good performance
Thank you for your comment and complementary information. The only thing why not only scripts is: the missing possibility to attach scripts to any events within EA.