Run Script

Run Script tasks are used to run scripts that typically perform some kind of processing on the job file received by the task. Scripts are often simpler to write than programs added with the External Program action (see External Program). However, they can be slower to execute.

The Run Script task can be used either as an Action or a Condition. When dragging and dropping a Run Script task on a given process, you select whether to use this task as an Action or a Condition from a contextual menu. (See also: About branches and conditions.)

When using the Run Script task as a condition, you need a way to tell your process whether the result is true or false. The condition result is returned by the Script.ReturnValue variable. If the return value is zero (the default), the condition is false. Otherwise, it is true.

When using the Run Script as an action task, the job file going out of the Run Script action task will be the same as the one coming in, unless you have specifically changed it within your script by writing to the file that is the target of the Watch.GetJobFileName function. The same goes for any Job Info, local or global variables, unless you use the Watch.SetJobInfo or Watch.SetVariable functions to modify them.

There are four scripting languages available through the Run Script task: JavaScript (JScript and Enhanced JScript), VBScript, Python and Perl. Each language has its own strengths and weaknesses which we will not cover in this documentation.

For more information on APIs, please see the related chapter, Using Scripts.

Note:

  • The JScript engine is Microsoft’s JScript 5.8, which is the equivalent of JavaScript 1.5 (ECMA-262 3rd edition + ECMA-327 (ES-CP) + JSON).

    Enhanced JScript allows the use of more recent JavaScript syntax. Many methods - basic methods like Date.now(), String.trim(), btoa()/atob() and more advanced methods like Array.forEach() - are added to the JScript engine via the polyfill.js library.

    Object methods (such as valueOf and toString) cannot be used in a JSON string in Workflow scripts. This is due to Microsoft’s implementation of the JScript library used in Workflow.

  • While JavaScript and VBScript are natively available on Windows operating systems, Python and Perl require third-party tools to be functional.
    For Perl, ActivePerl can be installed and for Python ActivePython can be installed.3.


    These links are provided for convenience only, and Upland Software does not offer support for their use.
  • To work with Python in Workflow, the Python engine needs to be installed and registered. For instructions see Installing the Python engine.

Tip: If you find yourself frequently copying and pasting your own JavaScript code into scripting tasks, consider storing your code in JavaScript files and including them in the Workflow scripting engine. See Reusing your code with JavaScript include files.

Input

Any data file, in any format.

Processing

The script is executed. The script can modify anything such as the data file, Job Info variables, Metadata, or even other files on the operating system.

Output

Whatever file the Run Script action generates, Metadata it modifies or creates, etc.

Note: When using Run Script as a Condition, the output of the task can be within the branch or on the main trunk. To control the output, use the Script.ReturnValue variable in your script.

Properties

The Script Editor menu options are as follows.

  • File
    • Import: Lets you open an existing script from an external file. This can be a .vbs, .js, .pl or .py file for language-specific scripts, or .txt for any of them.
    • Export: Lets you save the current script as a file.
    • Print: Prints the current script.
  • Edit
    • Undo: Undo the last edit.
    • Cut: Cut the current selection (only available if there is selected text in the editor).
    • Copy: Copy the current selection (only available if there is selected text in the editor).
    • Paste: Paste the last selection that was cut or copied in the location of the cursor in the text editor.
    • Delete: Delete the current selection (only available if there is selected text in the editor).
    • Select All: Select all of the contents of the editor.
  • Search
    • Find: Brings up the Find dialog.
    • Find Again: Repeats the previous search and finds the next occurrence.
    • Replace: Brings up the Replace dialog.
    • Go To Line: Brings up the Go To Line dialog where you can enter a line number and jump directly to that line.
  • Language: Select the language in which your script is written. Choices are VBScript, JavaScript, Perl or Python.
  • Tools
  • Help
    • Contents and Indexes: Opens the Editor Help (this page)

The other options of the window are:

  • The script editor text box: This is where you enter your script that will be used. If you use an external script file, this will display the content of the file (note however that modifying the script in this case does not modify the external file and changes are not saved).
  • Script running from: Choose if the script should be run from the editor text box, or from an external script file.
  • Script filename and path: Either the full path of the script, or click the Browse button to navigate to the file. This option is only available if you choose external script file in the Script running from option.

Caution: With the Run Script action, the On Error tab is accessible by right-clicking on the action in your process and clicking Advanced Properties.
The On Error tab will be triggered if your script has an execution error (such as syntax error, etc) as well as when raising an error from within your script.

Advanced properties

To get access to the following properties tabs, right-click the plugin in the process and select Advanced Properties.

On Error Tab

For a description of the options on the On Error tab see Using the On Error tab.

Miscellaneous Tab

The Miscellaneous tab is common to all tasks.

It contains a text area (Task comments) that lets you write comments about the task. These comments are saved when the dialog is closed with the OK button and are displayed in The Task Comments Pane.

Check the option Use as step description to display the text next to the icon of the plugin in the Process area.

The tab also provides an option to highlight the task in The Process area with the default color, set in the Preferences (see Colors), or the color selected or defined under Highlight color on this tab.
To revert the selected highlight color to the default color, open this tab, turn the Highlight option off and close the dialog with the OK button; then turn highlighting back on.
Highlighting can also be turned on and off via the task's contextual menu and with the Highlight button on the View ribbon.