Identify “Dirty” fields on Microsoft Dynamics CRM form

By | December 28, 2015

Introduction:

There may be times when you want to identify the fields that have been modified by the user in the current update.

While one way and the most common way has been to create a Plugin, the plugin only receives data of the fields that have been modified in the current update. If you wanted to check the previous value, you could compare the PreImage with the current value in the target and if they don’t match, it has been modified.

What if we had to identify the modified field through scripting?

It is common knowledge the form provides an IsDirty property that can be used to check if the form has been modified. We can check the form IsDirty using

Xrm.Page.data.entity.getIsDirty()

To get the list of attributes that have been modified in this session, you can check the IsDirty of the attribute. Here is a sample code of how you can loop through all the attributes and get the list of the modified attributes on the form

//get list of dirty fields
        oppAttributes = Xrm.Page.data.entity.attributes.get();

        if (oppAttributes != null) {
            for (var i in oppAttributes) {
                if (oppAttributes[i].getIsDirty()) {
                    listofDirtyAttri += oppAttributes[i].getName() + "\n";
                }
            }
        }

Another function that comes in handy here is Xrm.Page.data.entity.getDataXml()

var dataXml = Xrm.Page.data.entity.getDataXml();

the result would be

Identify Dirty fields on Microsoft Dynamics CRM form

Using the above function you can get a list of the data that is passed to the platform on update, and this inturn lists all the attributes that have been modified along with the current values being sent to the platform.

Conclusion:

Combination of getIsDirty on the form/attribute and getDataXml would help you quickly build a tracking tool without the need for a plugin.

Free 70% of storage space in CRM with Attachment Management Apps!

Attach2Dynamics – Store and manage documents/attachments in cloud storage of your choice – SharePoint, Dropbox or Azure Blob Storage from within Dynamics 365 CRM.
SharePoint Security Sync – Robust and secure solution to integrate Dynamics 365 CRM and SharePoint Security Sync thereby ensuring secure access to confidential documents stored in SharePoint.