In Dynamics 365, there is a common need to identify which fields have been modified on the form during an update.
One way is by creating a Plugin that will receive data of the modified fields in the current update event.
However, the purpose of this article is to check how to identify the modified fields through JavaScript.
It is done by verifying if the form or fields are in a dirty state which incdicates if they have been changed.
Three methods are available that you can use to get if the form or specific fields are dirty.
- Check if form is dirty to verify if any field on the form has been changed.
Using the function getIsDirty, you can check if any field on the form has been modified.
formContext.data.entity.getIsDirty();
This function will return true if the form is dirty, false otherwise.
- Check if a field is dirty to verify if a specific field on the form has been changed.
formContext.getAttribute("schema-field-name").getIsDirty();
This function will return true if the field is dirty, false otherwise.
- Display all the modified fields to verify what fields on the form have been changed.
formContext.data.entity.getDataXml();
This function will get the list of attributes that have been modified on the form with the values of each field.
A Xml result having a parent tag and inner elements where the root tag contains the entity logical name and the inner tags contain the fields' logical name with the current value of each field.
Hope This Helps!
*This post is locked for comments