Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To enhance basic workflow functionality, server-side scripts can be used in workflow blocks. In addition to Server-Side API classes, the following three global objects can be used in workflow scripts:

  • Current
    current
  • Scratchpad
    scratchpad
  • Activity
    activity

The Currentcurrent object is a SimpleRecord instance, for which a workflow context has been created. The property names of the Currentcurrent object match the names of the record columns (Column Name attribute). The full list of SimpleRecord class methods is described in this article.

The Scratchpadscratchpad object is an associative array (JSON), into which you can place values to later use them within the context. The value of the object is stored in the Scratchpadscratchpad field of the Workflow Context.

The Activityactivity object is a SimpleRecord instance of the current block record. The Activityactivity object properties match the names of record columns (Column Name attribute) in the Workflow Executing Activity [wf_executing_activity] table. For the Task [task] and Approval [sys_approval] records in the Wf Executing Activity field a reference to the linked Executing Activity record is specified.

Global objects in a workflow

Below is a workflow example for the Task [task] table.

In the beginning of the process a Task [task] child record is created through the Create Child Task block. Then the process is stopped on the Wait State block to wait for In Progress state.

After the state is changed to In Progress, the process proceeds to the Update Child Task block, in which 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:

Code Block
linenumbers
languagejs
themeConfluencetrue
new_task.parent_id = current.sys_id;

To update a record its ID must be known. 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 filled in. In this field a link to the executable block, within which the Task record was created, is specified.

To search for the created record it is possible to use sampling from the Task table by Wf Executing Activity field. 

Scratchpad is used to record the ID value of the current relevant block:

Code Block
languagejs
themeConfluencelinenumberstrue
const curentExecActivityId = activity.sys_id;
scratchpad.recGeneratorActivityId = curentExecActivityId;

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

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


Table of Contents
absoluteUrltrue
classfixedPosition