Skip to content

Isolated

Runs a callback in a new, independent database transaction.

1
myScript.Isolated(fn: () => T):T

Parameters

() => T fn
    The synchronous callback to execute.

Returns

The value returned by fn.

Remarks

Server workflow scripts only. The new transaction uses read-committed isolation and commits when the callback completes successfully. It is independent of the ambient transaction: a later rollback of the outer transaction does not undo this work. If this callback throws, its own transaction is rolled back; the error then propagates to the caller.

Examples

Keep an audit record even when the script fails later

1
2
3
4
5
6
7
8
Script.Isolated(function () {
    $Database.AddData('Audit', 'Events', {
        Event : 'ApprovalAttempt',
        WorkItemId : $WorkItem.Id
    });
});

// a later rollback of the outer transaction does not remove the audit record