Skip to main content
Version: 1.23.3

Workflow Scripting

Use the server-side scripts in the workflow blocks to extend the workflow functionality. In addition to the Server-Side API classes, you can use the following global objects:

  • current
  • scratchpad
  • activity

The current object is the SimpleRecord instance, for which a workflow context is created. The property names of the current object are the same as the names of the record columns (Column name attribute).

The scratchpad object is an associative array (JSON), where you can place values to use them later in the context. The value of the object is stored in the Scratchpad field of the Workflow Context (wf_context) table.

The activity object is the SimpleRecord instance of the current block record. The properties of the activity object are the same as the names of record columns (Column name attribute) in the Workflow Executing Activity (wf_executing_activity) table. On the Task (task) and Approval (sys_approval) record forms, specify a reference to the related Executing Activity record in the Wf Executing Activity field.

Global objects in a workflow


The following example is the workflow for the Task (task) table.

At the beginning of the process, a child Task record is created through the Create Child Task block. Then the process stops at the Wait State block to wait for the In progress state.

After the state is changed to In progress, the process proceeds to the Update Child Task block, where the Task child record is updated:

The Record Generator block is used to create a Task record according to its settings. The ID of the current record is specified in its Parent field:

Parent record
new_task.parent_id = current.sys_id;

To update a record, you need to know its ID. However, the Record Generator block does not return the ID of the created record.

For a record that is created via the generator block, the Wf Executing Activity field is automatically populated with a reference to the executable block that created the Task record.

To search for the created record, filter the Task records by the Wf Executing Activity field.

Use the scratchpad object to record the ID value of the relevant block:

const curentExecActivityId = activity.sys_id;
scratchpad.recGeneratorActivityId = curentExecActivityId;

The Run Script block named Update Child Task searches for the Task record and updates it:

const task = new SimpleRecord('task');
task.get('wf_executing_activity', scratchpad.recGeneratorActivityId);
if (task.sys_id) {
task.state = '3'; // In Progress
task.update();
}