---
title: "Workflow"
site: api
version: 1.11
versions: "all"
url: https://docs-new.servicely.ai/api/1.11/scripting/workflow/
type: reference
application: platform
last_updated: 2026-12-02
commit: f6d7027b3395
---


`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.

```javascript
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

<CodeTabs>
  Servicely Script

  ```javascript
  let codes = Workflow.getValidTransitionCodes(current, false);

  let moved = Workflow.performTransitionIfValid("<transition code>", current, true);

  [codes, moved];
  ```
</CodeTabs>

<CodeTabs>
  Response

  ```javascript
  [["<transition code>", "<transition code>"], true]
  ```
</CodeTabs>

### Abort a workflow

```javascript
Workflow.forceToActivity({
    activityName: "<activity name>",
    record: current,
    explicitUpdate: true,
    enableTriggers: false
});
```

### Approve on behalf of a user

```javascript
Workflow.approve("<record id>", user.getID(), "Approved from the integration.");
```

## Related

- [Workflow concepts](page:admin/automation/workflow)
- [Workflow activity reference](page:admin/automation/workflow-activities)
- [TableRecord](page:scripting/table-record)
