Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
You can define To enhance basic workflow functionality, server-side scripts can be used in workflow blocks. In addition to the Server-Side API classes, the following three global objects can be used in the 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 where you can place values to later use them within the context later. 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 On the Task [ (task] ) and Approval [sys_approval] records in the Wf Executing Activity field a reference to the linked Executing Activity record is specified. (sys_approval) record forms, specify a reference to the linked Executing Activity record in the Wf Executing Activity field.
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 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:
Image Added
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
new_task.parent_id = current.sys_id; |
Image Added
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, which created the Task record.
To search for the created record, use sampling from the Task table by Wf Executing Activity field.
Use the scratchpad object to record the ID value of the relevant block:
Code 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:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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 | ||||
---|---|---|---|---|
|