---
sourceDocument: Brazil ServiceNow AI Platform Capabilities
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/servicenow-platform

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil ServiceNow AI Platform Capabilities

ft:clusterId :

    - platcap

bundleId :

    - platcap

workflow :

    - Platform


---

# Lock workflow activity

# Lock workflow
activity {#r_LockActivity__izw_3ks_3x}

Release version: Brazil  
Updated September 10, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Lock workflow activity

The Lock activity in ServiceNow workflows ensures that only one instance of a workflow proceeds past a certain point at a time by obtaining a lock identified by a unique key.
This is crucial when multiple instances of the same workflow run concurrently, such as when triggered by multiple record insertions in a table.
The lock prevents other workflow instances from continuing past the Lock activity until the lock is released, either explicitly by an Unlock activity or automatically when a specified maximum duration is reached.
Show full answer Show less  

## How It Works

* When a workflow instance reaches the Lock activity, it attempts to obtain a lock using a specified key.
* If another instance holds the lock, the current instance retries until it either obtains the lock or exhausts the maximum number of attempts.
* Recommended practice: place a one-second Timer activity before the Lock activity to avoid rare conflicts caused by thread execution context.
* Avoid adding wait activities (e.g., Approval, Task, Timer, Wait for Condition) between Lock and Unlock activities to prevent delays in releasing the lock.

## Input Variables

The Lock activity is configured using the following key parameters:

* **Key:** Unique mutex identifier used to acquire and release the lock.
* **Max. duration:** The maximum time the lock persists before automatically releasing.
* **Lock attempts:** Defines retry behavior if the lock is initially denied.
* **Max. attempts:** The maximum number of retries to obtain the lock before failure.
* **Delay between attempts:** Time interval between retry attempts after a failure to acquire the lock.

## Activity States and Results

* **Waiting:** The workflow engine is attempting to obtain the lock.
* **Finished:** Lock successfully obtained, workflow instance proceeds.
* **Timeout:** Unable to obtain the lock after maximum attempts; the activity fails.

## Practical Considerations for ServiceNow Customers

* Use the Lock activity to coordinate concurrent workflow instances and prevent race conditions when workflows operate on the same records or resources.
* Pair Lock with Unlock activities to explicitly control when locks are released, avoiding long waits and potential workflow delays.
* Implement a Timer activity before Lock to ensure distinct workflow threads and reliable lock acquisition.
* Be cautious to avoid wait-type activities between Lock and Unlock to prevent lock release issues that can lead to workflow timeouts.  
The Lock activity prevents other instances of this workflow from continuing past this activity until the lock is released.{#r_LockActivity__wf-lock-activity-shortdesc}
Several instances of the same workflow may run concurrently. For example, if a workflow
triggers when a record is added to a particular table. That workflow triggers multiple times
if multiple records are added one after the other, once by each record insertion. You can
use the lock activity to ensure that this instance of the workflow has finished one or more
activities before any other instance of the workflow can proceed.

A workflow can explicitly release a lock with the Unlock activity.
The lock may also be released when the Max duration is reached.

When an instance of the workflow reaches the Lock activity, it
attempts to obtain a lock using the key specified in the lock activity. If another instance
has already obtained the lock and has not yet released it, this lock attempt fails. The
instance continues trying to obtain the lock until Max attempts has
been reached.  
Note:  
We recommend placing a one-second timer activity before the lock activity. This helps
prevent a rare condition in which the lock activity may not be able to distinguish one
workflow instance from another. This condition can occur because the entity owning the
lock is not the specific workflow instance, but rather the code-execution thread in which
that instance is running. In most cases, each workflow instance runs on a different
thread. Adding a timer activity ensures that this is the case.  
Figure 1. Example of Lock Activity Preceded by Timer Activity  
Since a Lock activity can only temporarily prevent processing of other workflow instances, do not add activities that cause the workflow to wait between a Lock and Unlock activity block. This may cause the Unlock activity to be unable to acquire the lock to release it and instead take 60 seconds to complete. Restricted wait activities include:

* Approval activities
* Task activities
* Timer activities
* Wait for condition activity
* Wait for WF Event activity
* MID server activities such as a PowerShell script
{#r_LockActivity__ul_hhw_h2m_wcb}

## Results

{#r_LockActivity__table_g3z_xwv_yr__entry__2}

| Result | Description |
|-|-|
| Success | The activity successfully obtained a lock. This instance of the workflow can proceed past this point, but other instances cannot proceed until the lock is released. |
| Failure | After attempting to obtain the lock Max attempts times, the activity could not obtain the lock. |
[Table 1. Lock activity results]

{#r_LockActivity__table_g3z_xwv_yr}

## Input variables

Input variables determine the initial behavior of the activity.
{#r_LockActivity__table_dfz_zwv_yr__entry__2}

| Field | Description |
|-|-|
| Key | A unique mutex key. The [Unlock activity](https://servicenow-prod.fluidtopics.net/rjyHdVl4fHLKEn9x9cHouQ "The Unlock activity releases a lock that was previously placed by the Lock activity.") activity uses this key to release the lock. |
| Duration ||
| Max. duration | The maximum time the lock persists. The lock is released after it reaches this duration. Releasing a lock this way is equivalent to running the Unlock activity. |
| Lock attempts Specify how the activity behaves if the lock attempt is denied. If the final lock attempt fails, the activity state is set to 'timeout' and the activity result is set to 'failed'. ||
| Max. attempts | Specify the maximum number of times the activity may attempt to obtain the lock. |
| Delay between attempts | The amount of time required after a failed lock attempt before another lock attempt is allowed. |
[Table 2. Lock activity input variables]

{#r_LockActivity__table_dfz_zwv_yr}

## States

The activity state tells the workflow engine what to do with the activity.
{#r_LockActivity__table_lgv_fxv_yr__entry__2}

| State | Description |
|-|-|
| Waiting | The workflow engine is waiting to obtain a lock. |
| Finished | The activity successfully obtained the lock. |
| Timeout | The activity could not obtain a lock within the number of attempts specified by the Max. attempts input variable. |
[Table 3. Lock activity states]

{#r_LockActivity__table_lgv_fxv_yr}

