The UMRA Automation software can be used to execute a script on the UMRA Service. This topic describes the main procedure to setup this configuration.
Create form project
With the UMRA Console application, create a form
project and setup the script. It is recommended to use a descriptive
name for the project, for example: AutomationCreateUserAccount. The form
project does not need to have a form, e.g. no form fields are required.
Setup access rights of form project
Setup the delegation access rights
for the form project so that the application that accesses the form project
is allowed to executed the script.
Setup the UMRA Automation script
The form project is accessed using the name of the form project, and a
list with variables (name-value) that are passed to the form project.
The syntax that must be used to access UMRA Automation COM objects depends
on the script-programming environment. The principle is the same for each
environment. In this example, the Microsoft Visual Basic 6 syntax is used.
The script is a subroutine executed when a button in a Microsoft Word
document is pressed. The complete project is available from the UMRA Console
subdirectory Example projects\Automation\CreateUserAccount
- MS Office Word 2003 - Visual Basic 6.
The next section describes in detail how to this script works and
how to setup such a script. In this example, the following environment
is used:
Windows 2000 Server or Windows XP system with UMRA installed.
Microsoft Office Word 2003. For the macro that is used for the UMRA Automation script, Visual Basic 6.3 is used, part of the Office installation. Microsoft Office Word 2003 is configured to support Visual Basic macro's.
To enable accessing the UMRA COM object, the UMRA Type library must be referenced in Visual Basic. In Visual Basic 6, this is accomplished with menu option Tools, References. In the references project window, scroll to UMRAcom 1.x Type Library. Select the library and press OK.
The script is listed below.
Private
Sub CreateAccount_Click()
Dim UmraSvc As New Umra
Dim AccountUserName As Variant
Dim AccountPassword As Variant
Dim LogMessage As Variant
Dim RetVal As Integer
RetVal
= UmraSvc.Connect("SPRING", 56814)
If (RetVal <> 0) Then
GoTo UmraError
End If
UmraSvc.SetVariableText
"%FirstName%", FirstName
UmraSvc.SetVariableText "%MiddleName%", MiddleName
UmraSvc.SetVariableText "%LastName%", LastName
RetVal
= UmraSvc.ExecuteProjectScript("AutomationCreateUser")
If (RetVal <> 0) Then
GoTo UmraError
End If
RetVal
= UmraSvc.GetVariableText("%UserName%", AccountUserName)
RetVal = UmraSvc.GetVariableText("%Password%", AccountPassword)
UserName.Text
= AccountUserName
PasswordField.Text = AccountPassword
GoTo Ready
UmraError:
UmraSvc.GetLogMsg LogMessage
MsgBox LogMessage
Ready:
End Sub
In the same script listed below, comments are added in bold to explain the script:
Private Sub CreateAccount_Click()
The UmraSvc object is created as an Umra COM object
Dim UmraSvc As New Umra
Dim
AccountUserName As Variant
Dim AccountPassword As Variant
Dim LogMessage As Variant
Dim RetVal As Integer
The Umra COM object connects to the computer SPRING, port 56814, to initialize the communication with the UMRA Service. The service must be running on the computer. Port 56814 is the default port. The computer name must be changed to the actual environment.
RetVal
= UmraSvc.Connect("SPRING", 56814)
If (RetVal <> 0) Then
GoTo UmraError
End If
The interface contains a list with variables. Each variable has a name and a value. Before the project is executed, the variables that are used in the script of the project must be initialized. In this example, a user account is created by specifying the first, middle and last name. The variables are called %FirstName%, %MiddleName% and %LastName%. These name are copied from the Word document that contains some Visual Basic edit boxes: FirstName, MiddleName and LastName.
UmraSvc.SetVariableText
"%FirstName%", FirstName
UmraSvc.SetVariableText "%MiddleName%", MiddleName
UmraSvc.SetVariableText "%LastName%", LastName
All variables are now initialized. The object is connected to the UMRA Service and the variable list is initialized. The project can now be executed. The project is called AutomationCreateUser.
RetVal
= UmraSvc.ExecuteProjectScript("AutomationCreateUser")
If (RetVal <> 0) Then
GoTo UmraError
End If
The script is successfully executed. According to the script project, variables are returned that can be displayed in the Word document. In this example, the %UserName% and %Password% variable are filled with the user name of the created user account (as determined by the name generation algorithm) and the password. The values of these variables are shown in the text boxes UserName and PasswordField of the Word document.
RetVal
= UmraSvc.GetVariableText("%UserName%", AccountUserName)
RetVal = UmraSvc.GetVariableText("%Password%", AccountPassword)
UserName.Text
= AccountUserName
PasswordField.Text = AccountPassword
GoTo Ready
UmraError:
If something goes wrong, a message box is shown describing the errors.
UmraSvc.GetLogMsg
LogMessage
MsgBox LogMessage
Ready:
End Sub
See also:
UMRA forms - Introduction
UMRA Automation - Principle
UMRA console - Command line options
UMRA Automation - COM object
UMRA Automation - COM interface
UMRA service - Introduction
UMRA Automation - Command Line Interface