VBScript Activity
Sometimes it is necessary to perform operations in a Workflow model that cannot be accomplished by any existing activities (i.e., DB Operations, Variable Assignments, etc.). TheVBScript activity allows the user to write scripts that perform such functions within the model. When an activities action is defined as a VBScript, selected the "Settingsā¦" button brings up a dialog box, which is comprised of a text editor. The user can enter any valid VBScript code, including comments. When the Workflow activity is executed, the VBScript is executed. If it executes correctly, the activity is marked as successful and the Workflow model continues its execution. If an exception occurs, the activity is marked as an "Error" result and the error handler is called next.
Information regarding the current Workflow model instance is made available to the VBScript through the use of global variable objects. This allows the user to reference method calls, instance information, history information, and any data being stored with the current Workflow model instance being processed. This Workflow model instance information can include BusinessPlus record data, list information (SQL List Activity), variable values and Web Form data. The user also has access to the BusinessPlus error container in case errors are seen during the execution of various methods.
Global Variable Objects
As stated earlier, certain objects are automatically made available to the VBScript and can be referenced in the script. The following is a list and description of the Global Variable Objects that exist for the VBScript Activity.
History Records
Every Activity has a history record created prior to its execution. This record contains important information on the circumstances under which this activity was executed. The history record object is passed to the VBScript Activity as a global variable object called "History." Within the VBScript, its various properties can be accessed and used for a variety of purposes. The following is an example of a reference in which the history record's User ID is accessed for the purposes of assigning it into a local variable:
Dim UserId
UserId = History.UsId
Notice that the initial variable definition and assignment exists on two separate lines. The VBScript activity does not support two functions on the same line, so they must be split up. Also, notice that the local variable definition does not match the exact property name. VBScript is a very simple programming language and can get confused when the naming convention has duplicates.
Models Instance Objects
A Workflow model instance object is created for every Workflow model instance that is processed. This contains a multitude of information on the Workflow model instance. This information can be retrieved by the VBScript using various method calls supported by the Model Instance object. The model instance object is passed to the VBScript Activity as a global variable object called "Model." An example of the Model method call to retrieve the actual Workflow Instance:
Dim InstanceRec
Set InstanceRec = Model.GetInstanceRecord()
The user does not have the createObject command on the above assignment due to the fact that the Instance Record already exists as an object. The object has to be created first before being referenced.
At this point, the user can reference properties from the Instance record in the same manner as the user would the History record:
Dim NumberOfChanges
NumberOfChanges = InstanceRec.ChangeCount
Variable Data
Data elements that have been defined for a Workflow model are also available in the VBScript activity. A Variables Data Object which contains references to all of the Workflow model data elements is passed to the VBScript Activity as a global variable object called "Variables." An example of a reference to a variable called First time:
Dim FirstTimeInModel
FirstTimeInModel = Variables.FirstTime
Values can be retrieved from Workflow model Data Elements. They can also receive assignments from other sources, which makes the VBScript Activity a very valuable tool for setting Data Elements within a model. An example of an assignment:
Dim FirstTimeInModel
FirstTimeInModel = Variables.FirstTime
If FirstTimeInModel = 'Y' then
Variables.FirstTime = "N"
End If
There are no method calls defined for the Variable Object. It merely contains properties for each of the Data Elements defined in the Workflow Mode.