Workflow
Methods of the Workflow object, which performs and forces workflow transitions, moves records between activities and answers approvals from server scripts.
Workflow is the global that drives a record’s workflow from a server script: a trigger, a job, a script library or the server script page. It performs transitions, forces a record to an activity and approves or rejects approval tasks.
Get an instance
Workflow is ready to use. Pass it the record whose workflow you want to move, and the transition code or activity name from the workflow.
Workflow.performTransition("<transition code>", current, true);
In these methods, explicitUpdate true saves the record after the move, as current.update() does. enableTriggers true runs the table’s triggers on that save.
Transitions
| Method | Returns | Description | Since |
|---|---|---|---|
performTransition(code, record, explicitUpdate) |
Nothing | Performs the transition with triggers off. The transition’s condition script is not evaluated. | 1.11 |
performTransition(code, record, explicitUpdate, enableTriggers) |
Nothing | The same, with triggers on or off. It raises an error when record is null. |
1.11 |
performTransition(code, record) |
Nothing | Deprecated. The same as explicitUpdate false with triggers off, and it writes a warning to the log. |
1.11 |
performTransitionIfValid(code, record, explicitUpdate) |
Boolean | Performs the transition with triggers off when it is valid from the current activity, and returns whether it did. | 1.11 |
performTransitionIfValid(code, record, explicitUpdate, enableTriggers) |
Boolean | The same, with triggers on or off. | 1.11 |
isTransitionValid(code, record, evaluateCondition) |
Boolean | True when the transition is available from the record’s current activity. Permissions are checked. | 1.11 |
isTransitionValid(code, record, evaluateCondition, evaluatePermissions) |
Boolean | The same, with the permission check on or off. | 1.11 |
getValidTransitionCodes(record, evaluateCondition) |
Array | The codes of the transitions available from the current activity. Permissions are checked. | 1.11 |
getValidTransitionCodes(record, evaluateCondition, evaluatePermissions) |
Array | The same, with the permission check on or off. | 1.11 |
forceTransition(code, record) |
Nothing | Performs the transition if it is valid. Otherwise it forces the record to the transition’s target activity. It raises an error when the workflow has no such transition. | 1.11 |
forceTransition(code, record, options) |
Nothing | The same with options. See Options below. | 1.11 |
Activities
| Method | Returns | Description | Since |
|---|---|---|---|
forceToActivity(activityName, record, explicitUpdate) |
Boolean | Moves the workflow straight to the named activity with triggers off, whatever the transitions allow. Use it to abort a workflow. | 1.11 |
forceToActivity(activityName, record, explicitUpdate, enableTriggers) |
Boolean | The same, with triggers on or off. | 1.11 |
forceToActivity(options) |
Boolean | The same with options. See Options below. | 1.11 |
evaluateSuspendedActivity(record, options) |
Nothing | Evaluates the record’s current activity again for the signed-in user, for example after the data an approval waits on has changed. | 1.11 |
evaluateSuspendedActivity(record, options, userID) |
Nothing | The same for another user. | 1.11 |
Approvals
| Method | Returns | Description | Since |
|---|---|---|---|
approve(task, userID) |
Nothing | Approves an approval task on behalf of userID. task is the task record or its ID. |
1.11 |
approve(task, userID, comment) |
Nothing | The same with a comment. | 1.11 |
reject(task, userID) |
Nothing | Rejects an approval task on behalf of userID. |
1.11 |
reject(task, userID, comment) |
Nothing | The same with a comment. | 1.11 |
canApprove(record, userID) |
Boolean | True when record is an approval task assigned to userID or to a user who has made userID their delegate. |
1.11 |
getApprovalDelegateIDs() |
Array | The signed-in user’s ID and the IDs of users who have made them their delegate. | 1.11 |
getCurrentWorkflowTasksForWorkflowInstance(instance, taskTable) |
Array | The current tasks of a workflow instance, from the named task table. | 1.11 |
getCurrentWorkflowTasksForUserByWorkflowInstance(instance, userID, taskTable) |
Array | The same, limited to tasks assigned to userID or to users who delegate to them. |
1.11 |
approve() and reject() run with the system user’s roles, so the script does not need approval permissions.
Options
forceToActivity(options) and forceTransition(code, record, options) take an object.
| Method | Returns | Description | Since |
|---|---|---|---|
activityName |
String | forceToActivity only, and required. The activity to move to. |
1.11 |
record |
TableRecord | forceToActivity only, and required. The record whose workflow moves. |
1.11 |
explicitUpdate |
Boolean | Saves the record after the move. Default true. | 1.11 |
enableTriggers |
Boolean | Runs triggers on that save. Default true. | 1.11 |
cancelPreviousTransition |
Boolean | forceToActivity only. Cancels the transition in progress. Default false. |
1.11 |
evaluateCondition |
Boolean | forceTransition only. Evaluates the transition’s condition script. Default false. |
1.11 |
evaluatePermissions |
Boolean | forceTransition only. Checks transition permissions. Default false. |
1.11 |
Examples
Perform a transition only when it is valid
Servicely Script
let codes = Workflow.getValidTransitionCodes(current, false);
let moved = Workflow.performTransitionIfValid("<transition code>", current, true);
[codes, moved];
Response
[["<transition code>", "<transition code>"], true]
Abort a workflow
Workflow.forceToActivity({
activityName: "<activity name>",
record: current,
explicitUpdate: true,
enableTriggers: false
});
Approve on behalf of a user
Workflow.approve("<record id>", user.getID(), "Approved from the integration.");