When you use Microsoft® ActiveX® script code in the workflow step for a task, the code is run before the task. This sequencing allows you to use an ActiveX script in a workflow to restart a workflow, turn off a step under certain conditions, initiate retries of connections and other operations, and implement loops. You can also use a step ActiveX script to initialize global variables.
The following example, written in Microsoft Visual Basic® Scripting Edition, uses an ActiveX script to turn a step on or off based on the existence of a file:
Function Main()
Dim fso 'File system object
Set fso = CreateObject("Scripting.FileSystemObject")
IF (fso.FileExists("C:\temp\download.tmp")) THEN
Main = DTSStepScriptResult_ExecuteTask
ELSE
Main = DTSStepScriptResult_DontExecuteTask
END IF
End Function
The following example, written in Microsoft Visual Basic Scripting Edition, checks for the presence of a file five times before terminating the step. The global variable retries stores the number of attempted file checks:
Function Main()
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
IF NOT(fso.FileExists("C:\MyFile.txt")) THEN
DTSGlobalVariables("retries").Value =
DTSGlobalVariables("retries").Value + 1
IF DTSGlobalVariables("retries").Value > 5 THEN
Main = DTSStepScriptResult_DontExecuteTask
ELSE
MsgBox "Retry #" & DTSGlobalVariables("retries").Value
Main = DTSStepScriptResult_RetryLater
END IF
ELSE
Main = DTSStepScriptResult_ExecuteTask
END IF
End Function
The following example of ActiveX Script step code, written in Microsoft® Visual Basic Scripting Edition, is assigned to the second task in a two-task workflow connected with a precedence constraint (ActiveX Script task 1 -> Unconditional precedence constraint -> ActiveX Script task 2).
The workflow step ActiveX script serves as a loop. The script displays these traits:
Function Main()
Dim oPkg
DTSGlobalVariables("counter").Value = DTSGlobalVariables("counter").Value + 1
IF DTSGlobalVariables("counter").Value < 5 THEN
Msgbox DTSGlobalVariables("counter").Value
Set oPkg = DTSGlobalVariables.Parent
oPkg.Steps("DTSStep_DTSActiveScriptTask_1").ExecutionStatus =
DTSStepExecStat_Waiting 'Set previous
task status to waiting.
Main = DTSStepScriptResult_ExecuteTask 'Execute
task two before restarting task 1 again.
ELSE
Main = DTSStepScriptResult_ExecuteTask
END IF
End Function
Workflow Properties | Global Variables |