Delete Entity

Delete an entity from the database.

Introduction

Familiar with Lava's Entity command for data retrieval? The Delete Entity command extends its capabilities, allowing you to delete data directly from your database.

While the Delete Entity command is a powerful tool, it comes with significant security responsibilities. It's crucial to thoroughly understand and implement the security measures outlined in the following section before integrating this command into your Lava workflows.

The delete entity command allows you to delete a single entity in your database. Below is a very simple example where we are removing a connection request record.

{% assign requestId = 12 %}

{% deleteconnectionrequest id:'{{ requestId }}' %}
{% enddeleteconnectionrequest %}

Pretty cool right?! Let's look at some of the input options at your disposal.

  • id - This is a required input that tells us what entity we want to update. The value for 'id' can be an integer, guid or IdKey. We strongly recommend using GUIDs when passing data to your endpoints for the Delete Entity command. This approach significantly enhances security by making it harder for someone to manipulate your endpoint by altering an ID integer.

  • securityenabled (true) - Determines if entity security should be checked. Be careful with modifying individuals as there is no security on the person entity.

  • clientvalidationenabled (false) - When enabled the block will wire-up client-side validation for you. See the Client-Side Validation section below.

  • result (DeleteResult) - The key designated for the merge field to hold the command's results.

Result Merge Fields

The properties and attributes you wish to modify should be specified within the Lava block. We will explore each of these in detail.

The command will insert a merge field labeled DeleteResult (this can be change by the result parameter), providing details about the update's outcomes. The field has the following properties:

  • Success - A boolean value that determines if the record was saved successfully.

  • ErrorMessage - Should any issues occur, this field will detail the nature of the problem.

  • ValidationErrors - This is a list of the validation errors that occurred.

    • ErrorMessage - Specific validation message.

    • SourceControl - The control that was linked to the message. This is provided through the control setting on the property or attribute.

Below is some sample Lava showing error information.

 {% if DeleteResult.Success == false %}
    <div class="alert alert-warning">
        <strong>{{ DeleteResult.ErrorMessage }}</strong><br>
        Validation Messages<br>
        <ul>
        {% for message in DeleteResult.ValidationErrors %}
            <li>{{ message.ErrorMessage }}</li>
        {% endfor %}
        </ul>
    </div> 
{% endif %}

Last updated