To enhance basic workflow functionality, server-side scripts can be used in workflow blocks. In addition to theServer-Side API classes, the following three global objects can be used in the workflow scripts:
current
scratchpad
activity
The current object is aSimpleRecord instance, for which a workflow context has been created. The property names of the current object match 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 within the context later. The value of the object is stored in the scratchpad field of the Workflow Context.
The activity object is aSimpleRecord instance of the current block record. The activity object propertiesmatch 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 linkedExecuting 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 stoppedon 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, 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: