ActiveX Scripts and Workflow Steps

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.

Turning a Step On and Off

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

Retries

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

  

Implementing Loop Conditions

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:

See Also
Workflow Properties Global Variables

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.