Navigation:  Actions > System >

Run Script Action

Previous pageReturn to chapter overviewNext page

This action creates a step to execute script code from a project step.  The language can be selected from the list, or the ProgId of any registered script engine can be specified.  The script code is edited in the main dialog text box.  The script code can also call any script code for that language defined in the Script Editor.  Script code in the Code field should not be enclosed in brackets (script expressions in other fields must be enclosed in brackets to indicate script code).


When the step is built, Visual Build will instantiate the script engine, add all the script for that language from the Script Editor into the engine, and execute the code in the Code field.  The script code can access the Visual Build automation objects via the Application, Project, Step, and Builder global items, any global script code defined for that language, create other COM objects, etc.  Any output or errors will be logged to the Output pane and log file (if enabled).  The step's BuildStatus property can be set to vbldStepStatFailed in the script code to signal failure of the step.



Like other step fields, the Code field can also reference macros which will be expanded when building.  However, unlike other fields that contain macros, a tool tip is not displayed to show the expanded value unless some text is selected.  To view an expanded value, select the text containing the macro(s), move the mouse cursor out of the field and back in, and the expanded tool tip will be displayed.
Macro references (i.e., %MACRO_NAME%) are expanded before the script is fed to the script engine (unless Ignore special characters is checked), so script code that creates or updates a macro's value should not also reference that macro via %MACRO_NAME%; instead, use the macro variable directly (i.e., objMacro.Value) or expand the macro using Application.ExpandMacrosAndScript("%%MACRO_NAME%%"), which delays evaluation of the macro value to that point in the code rather than before the script code is executed.
To create a temporary macro in script code (VBScript), use
Set objMacro = vbld_TempMacros.Add("MACRO_NAME", "macro value")
Set objMacro = Application.Macros(vbldMacroTemporary).Add("MACRO_NAME", "macro value")
The Step.BuildStatus property can be updated to change the success/failure status of the step.  If the step is marked to continue on failure, throwing or raising an error from script code will not ignore the failure (providing a way to abort the build even when the step is marked to continue on failure).

Note: The Script.bld sample demonstrates creating or incrementing a macro value.