--- title: "Lock by key" slug: "core-lock-by-key-actor" updated: 2026-03-31T13:31:07Z published: 2026-03-31T13:31:07Z canonical: "docs.lobstersoftware.com/core-lock-by-key-actor" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.lobstersoftware.com/llms.txt > Use this file to discover all available pages before exploring further. # Lock by key > [!NOTE] > Event action – Abstract > > **Purpose:** The Event handling can achieve a sequencing of competing processes in different transactions in event handling by checking and, if necessary, setting a lock key. > > > [!TIP] > > Tooltip > > > > - **Usage**: This event action checks whether the specified **Lock key** is locked by another (current) transaction on the server side. > > - If there is a lock, its own event processing is interrupted until the other transaction is completed (or cancelled). > > - If there is no lock, a lock is registered for its own transaction and event processing is continued immediately. > > - **Parameter**: The **Lock key** parameter names – via direct input or *value configuration* – a string that should characterise the lock as specifically as possible. > > - The event action has no effect with an empty string ('') or if the **Lock** **key** is 'No value' (`$null`). > > - **Lock key** values are case-sensitive. > > - Strings for **Lock key** values are automatically trimmed so that marginal *whitespace* characters are effectively irrelevant. > > - If the return value of a *value configuration* is not a string, the string image of the return value is used. > > - **NOTE:** An impending *deadlock* between transactions with two mutual dependencies (via two lock key values) is intercepted at runtime with an error message that cancels one of the transactions involved so that the other can continue. ![images/download/attachments/189441521/image-2024-12-20_16-42-29-version-1-modificationdate-1734709348661-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image-2024-12-20_16-42-29-version-1-modificationdate-1734709348661-api-v2.png) The [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action can be used in [Event handling](/v1/docs/en/administration-designer-workflow-action-event-handler-configuration) to control the sequencing of competing processes in different transactions. When the [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action is executed, the system checks whether a lock has already been registered by another transaction on the server for the specified **Lock key** value. - If there is a lock for the **Lock key** value, event processing (for its own transaction) is temporarily stopped until the other transaction has been completed. - If there is not yet a lock for the **Lock key** value, a lock is registered so that other transactions relating to the same **Lock key** value will have to wait until its own transaction is completed, whose event processing continues without any interruption. If several transactions execute the [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action with the same **Lock key** value while a lock already exists for this key, waiting transactions are processed in a sequential manner according to the 'first come, first served' principle. ![images/download/attachments/189441521/image-2024-12-20_16-35-39-1-version-1-modificationdate-1734708938696-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image-2024-12-20_16-35-39-1-version-1-modificationdate-1734708938696-api-v2.png) The [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action is typically used to prevent different, simultaneous transactions from attempting to execute an action with the same content, e.g. creating an entity for the 'same' master data record. However, this option should be used sparingly and always in conjunction with a suitable **Lock key** value that is as specific as possible to avoid creating a 'bottleneck' in event processing. > [!NOTE] > What about deadlocks? > > --- > > As soon as several *lock key* values are in play, a *deadlock* can occur between two transactions, in which they block each other because each of them are waiting for the other. > > Example: > > - An event handling (I) starts with a [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action for the *lock key* value 'X' and then starts a lengthy database operation ([Execute SQL query](/v1/docs/en/core-native-sql-actor-configuration)). > - This is followed by another [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action for the *lock key* value 'O' before the results are reported via [Show alert](/v1/docs/en/freaction-show-alert). > - Another event handling (II) begins with a [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action for the *lock key* value 'O'. > - This is followed by another [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action for the *lock key* value 'X' before a return value is reported via [Show alert](/v1/docs/en/freaction-show-alert). > > If the first event handling (I) is triggered at runtime and the second event handling (II) is also started while the database operation is in progress, the following happens: > > - (II) immediately sets a lock for the *lock key* value 'O' and then waits for the lock initiated by (I) for the *lock key* value 'X' to be cancelled. > - As soon as (I) completes the database operation, a *deadlock* is imminent since (I) then has to wait for the lock for the *lock key* value 'O', which has been initiated by (II) in the meantime, to be lifted, which is not expected until the completion of (I) due to the lock for the *lock key* value 'X'. This completes the 'circle'. > > To prevent an acute *deadlock* from irrevocably 'sending both transactions nowhere', **Lobster Data Platform/Orchestration** intercepts the impending *deadlock* at runtime and triggers an error message when the [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action that would close the loop is executed. > > - The triggered error message (`Deadlock detected`) names the *lock key* values involved and cancels one of the transactions. > - The other transaction will then be continued. ## Configuration Event handling does not require a *reference object*. However, an existing *reference object* is available as an *input value* for the *value configuration* in the **Lock key** value parameter. A text value is expected for the **Lock key** value parameter, which can be provided either by *direct input* (default) or – after clicking on the small grey arrow at the bottom left of the [Text field](/v1/docs/en/custom-custom-text-field) – via a *value configuration*. - If a *value configuration* does not return a text value at runtime, the server-side string image of the return value is used as the **Lock key** value. - If there is no input or *value configuration* or a *value configuration* for the **Lock key** value returns 'No value' (`$null`) at runtime, the event action has no effect. - If a *value configuration* returns a list as the **Lock key** value that contains the dynamic enumeration value for the [Country](/v1/docs/en/core-country) 'France' (`FR`) as the only entry, this has the same effect as entering the character string '`[FR]'` . - The identifier adopted as the **Lock key** value is trimmed on both sides to generate the effective key value for the lock. - The input of marginal whitespace characters has no effect on the effective key value. Character strings such as 'A51', '`A51`' or '`A51`' always effectively address the key value '`A51`'. - Blocking only takes place if the string contains at least one character after trimming. - The string defined as the **Lock key** value is processed in a case-sensitive manner. - The strings '`eMail`' and '`Email`' generate different effective lock key values. ## Example ### Simple scenario to experiment --- **IMPORTANT:** The following scenario is not a typical use case but is well suited to familiarize users with the effect of the [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action with little effort in an experiment. It is expressly not a recommended procedure for solving the task described. --- A [Custom action event](/v1/docs/en/core-custom-action-events) (`LOCK_FILE_FOR_APPEND`) is triggered via a ribbon macro that can be 'attached' to the ribbon of various views. In this way, authorized users should be able to attach a text entry to a server-side file of their choice: - Firstly, the user is asked for the name of the target file using the [User prompt](/v1/docs/en/frebehav-user-prompt) resolver. Whether the file already exists or has to be created during the subsequent write access should not play a role here. - As a second step, the text to be added is again queried using the [User prompt](/v1/docs/en/frebehav-user-prompt) resolver. - The file is then updated. As soon as a user has named a specific target file in the first step, further write access to the same file should be restricted until the file update has been completed. - For a simple test, it is sufficient to open two views (or two instances of the same view) alongside each other that offer the *ribbon button*. Two concurrent transactions can then be started within the same session, in which the file name can either be the same or different. Configuration: The following screenshot on the right shows the configuration for the only event handling required for this demonstration. | A [Custom action event](/v1/docs/en/core-custom-action-events) (`LOCK_FILE_FOR_APPEND`) serves as the **Triggering event**. The data context is irrelevant for the demonstration. --- The **Validating rule** is implemented here as a [Role rule](/v1/docs/en/base-role-rule) in order to restrict the user group. --- The **Action on passed rule** should be executed if an authorized user has triggered the **Triggering** **event** via the *ribbon*: - The [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action uses a *value configuration* with a value resolver chain (see [Chained resolver](/v1/docs/en/core-chained-resolver)): - The [User prompt](/v1/docs/en/core-user-prompt-value-resolver) resolver requests a file name from the user. - The concatenated [Store value as variable](/v1/docs/en/core-store-value-resolver) resolver ensures that the text input is available for subsequent steps via a variable (`target`). **NOTE:** The input text here is unchecked and used directly as a **Lock key** value to create a lock under the name of the addressed file or to determine whether a lock already exists. If the user names a file via [User prompt](/v1/docs/en/frebehav-user-prompt) that is already locked by an ongoing transaction, event processing is paused until this has been completed. This happens after the input dialog has been closed and without any further feedback apart from the *waiting cursor*. - The write process in the following [Execute with](/v1/docs/en/core-with-actor) event action will not be explained in more detail here. However, when experimenting with the 'lock' using the [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action, it is crucial that this sub-step contains another instance of the [User prompt](/v1/docs/en/frebehav-user-prompt) for entering the text to be attached to the target file. The user can then decide how long the block will last in the transaction that triggered it. The actual writing process to a file (see [File reference](/v1/docs/en/core-file-reference-content-builder)) is not necessarily required for experimentation. The decisive factor is whether the second [User prompt](/v1/docs/en/frebehav-user-prompt) appears after a file name has been entered. If this is not the case, a continuous transaction locks the selected file name until the text input has been completed. | ![images/download/attachments/189441521/image-2024-12-20_16-41-37-version-1-modificationdate-1734709296954-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image-2024-12-20_16-41-37-version-1-modificationdate-1734709296954-api-v2.png) | | --- | --- | Runtime example: ![images/download/attachments/189441521/image-2024-12-20_16-39-22-version-1-modificationdate-1734709161624-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image-2024-12-20_16-39-22-version-1-modificationdate-1734709161624-api-v2.png) - The *view* on the left shows a transaction in the second step (text input) after a `notepad` file has been named for the output. - In this state, a lock with the *lock key* value `notepad` has been set up for this transaction. - After entering the text and clicking **OK**, the entry is saved and the transaction ends. This cancels the `notepad` lock. - The *view* on the right shows a transaction started later in the first step (file selection), which attempts to access the same file as the transaction on the left. - Clicking **OK** executes the [Lock by key](/v1/docs/en/core-lock-by-key-actor) event action, which is paused until the transaction on the left ends. The dialog for text inputting only appears on the right once the left-hand transaction has ended. - If a different file name (e.g. `notepad2`) is entered before clicking **OK** on the right, which is not yet used as a *lock key* value for an active lock, the dialog for text input appears immediately.