Skip to main content

FieldLogs

Adding a Script

Using Scripts, you can modify Template behavior when the Task is being run. A Script can be added to any Step in a Template.

Important

Only users with the Edit Template Scripts privilege can add or edit Scripts.

To add a Script to a Step, the following need to be set:

  • Script Triggers : The event on the Step which will trigger the Script.

  • Script Instructions: The instructions that comprise the Script. The Script is executed when the Script Trigger event occurs.

Any one of the following four events can trigger a Script associated with a Step.

In FieldLogs, Validation of a Step refers to the event of saving the Step value to the Task.

Event Trigger

Description

AfterValidate

Triggers the Script when the Step is validated by the user, after the value is saved in the Task.

BeforeValidate

Triggers the Script when the Step is validated by the user, before the value is saved in the Task.

OnLoad

Triggers the Script when the Task execution starts or restarts (after the application stops, for example) or when the Task is continued.

AfterAnyValidation

Triggers the Script each time any Step of the Task is validated by the user, after the value is saved in the Task.

A Script can be broken down into several simple Instructions. A Script Instruction performs a single action.

A Script Instruction can be of the following categories:

Category

Description

Basic

Basic operations like evaluation of expressions.

Step value

Reading and Setting the values and properties of Steps.

Global Value

Reading and Setting Global values and Template Variable values.

External call

Making external function calls.

Table

Manipulating values in a Table Step.

Identity

Accessing and evaluating Identity and Role related conditions

Logic

Conditional Execution of statements.

JS Execute

Enables Enhanced Scripting.

To create a Script:

  1. Open the Template to which the Script needs to be associated.

  2. Select the Step whose event needs to trigger the Script. Navigate to the Script Editor as shown below.

    AddingAScript1.png

    The Script Editor opens.

    AddingAScript3.png

    The Show Step ID button acts as a toggle button between the Step numbers and Step IDs.

    Step_numnbers.png
    StepID.png

    This button is accessible at every stage of the Template Lifecycle. It is also visible on Published Templates as shown below.

    step_iD.png
  3. Click Add New Script.

    AddingAScript4.png
  4. Enter the name of the Script. Choose the appropriate trigger for the Script.

    AddingAScript5.png
  5. Click the AddingScriptPlus.png to add a new Script instruction. Based on the type of Instruction selected, further options appear.

    AddingAScript6.png

    Add as many Instructions as required by clicking the AddingScriptPlus.png button. Delete any Instruction by clicking the AddingScriptMinus.png button.

    For more details, see Script Instructions.

  6. Save the Template.

    AddingAScriptSave.png

The Script is now associated with the Template.

Note

You can associate multiple Scripts to the same Step.

In the below example, all the Scripts are associated with the same Step. Note that in some cases the same event on the same Step can trigger multiple Scripts.

AddingScriptsmultipletriggers.png

Tip

You can use the Execution Preview to preview the Script execution.

AddingAScriptExecutionPreview.png