Developer Docs - Helix - Modify Entity

MOVED TO LAVA DOCS

Make changes to properties or attributes of an entity.

Introduction

Familiar with Lava's Entity command for data retrieval? The Modify Entity command extends its capabilities, allowing you to update or insert data directly into your database, enhancing your data management toolkit.

While the Modify 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 modify entity command allows you to update a single entity in your database. Below is a very simple example where we are changing the nick name, connection status and an attribute of a specific person in the database.

{% assign personId = 12 %}
{% assign nickName = 'Ted' %}
{% assign connectionStatus = 67 %}
{% assign employer = 'Rock Solid Church' %}

{% modifyperson id:'{{ personId }}' %}

    [[ property name:'NickName' ]]{{ nickName }}[[ endproperty ]]
    [[ property name:'ConnectionStatusValueId' ]]{{ connectionStatus }}[[ endproperty ]]

    [[ attribute key:'Employer']]{{ employer }}[[ endattribute ]]

{% endmodifyperson %}

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

Properties

To edit an entity's property, simply specify the property name and the desired value. Ensure that the provided data type and value are accurate and appropriate for the property.

Attributes

Updating an entity's attribute requires specifying the attribute's key along with a new value. Similar to properties, the provided value must match the expected format for the specific attribute. For guidance on the raw values required by different attribute types, refer to the documentation on this page.

Property and Attribute Validation

Both the property and attribute elements can handle data validation for you through additional settings. These settings mimic the HTML validation API. The Rock data model does enforce some validation for you (e.g. a group must have a name) but these settings allow you to go above and beyond.


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.

Below is some sample Lava showing error information.

 {% if ModifyResult.Success == false %}
    
{{ ModifyResult.ErrorMessage }}
Validation Messages
    {% for message in ModifyResult.ValidationErrors %}
  • {{ message.ErrorMessage }}
  • {% endfor %}
{% endif %}

Client-side Validation

Client-side validation only works with Lava Applications when using the Lava Application Content Block and Endpoint.

When this clientvalidationenabled property is set to true and validation configuration is added to properties and/or attributes the endpoint can send configuration back to the client to display the validation messages for you and to highlight the control that needs attention.