Sometimes while debugging forms in Dynamics 365, we need to know which fields have been modified but not yet saved. These are called dirty fields, and they can be quickly identified by running a small JavaScript snippet directly from the browser console.
We can open the form, press F12 to bring up the developer tools, go to the Console tab, and paste the following code
(function () {
var dirtyFields = [];
var attributes = Xrm.Page.data.entity.attributes.get();
attributes.forEach(function (attribute) {
if (attribute.getIsDirty()) {
dirtyFields.push(attribute.getName());
}
});
if (dirtyFields.length) {
alert("Dirty fields: " + dirtyFields.join(", "));
} else {
alert("No dirty fields found.");
}
})();
This script loops through all the attributes on the form and checks if they are dirty using getIsDirty(). If it finds any, it shows their names in an alert, otherwise it shows a message saying no dirty fields are found.
For example, if we modify First Name and Email on the Contact form without saving, it will pop up an alert showing:

Here we are using Xrm.Page even though it is deprecated, because it is still the quickest way to test such snippets directly from the console for debugging purposes. In actual form scripts, we should always use formContext.
Hope it helps..





























