Using Scripts

Scripts can be used to perform various operations, such as to manipulate data, for example. OL Connect Workflow can perform scripts written in four different scripting languages and also provides an interface for editing scripts.

Note: While this chapter provides some very useful and detailed information about scripting within OL Connect Workflow, its focus is to inform you about the features, variables and functions unique to this environment. This chapter assumes that you have a working knowledge of the scripting language you wish to use and does not purport to teaching you anything about this language that you don't already know. Learning any of these language is beyond the scope of this documentation.

Run Script task

Scripts are incorporated in a process via the Run Script task (see Run Script).

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.

Scripting languages

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. The examples provided in this chapter are presented in all supported languages.

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.
    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.

APIs

Multiple APIs (methods of communicating with OL Connect Workflow scripting tools) are available through the scripting engine, in all languages.

  • The Watch object is used to communicate with your current process and configuration. See The Watch Object.
  • The Connect REST API consists of many services that expose access to a number of areas including Workflow, data entity management and file store operations. See the Connect REST API Cookbook.
  • You can manipulate PDF files using the Alambic API. See AlambicEdit API reference. Note that in PlanetPress Suite, the Alambic API is part of the PDF Tools.
  • You can manipulate the Metadata in your process using the Metadata API. See the Metadata API.
  • You can communicate with a SOAP server using the SOAP API. See SOAP Server API Reference.
  • You can communicate the with the Data Repository using the Data Repository API. See: Data Repository API.