I have been looking for a way to get the list of all dirty fields in the CRM form to determine the what was changed and need to be saved in the browser console. This will help me debugging the javascript or other CRM related issues in general
How can i achieve this ?
You can use the following code for your reference
var attribs = Xrm.Page.data.entity.attributes.get();
to get the list of all fields in the from and then call the function getIsDirty()
for it as
var filterDirty = attribs.filter(function(elem,index,attribs){
var name = elem.getName();
return (Xrm.Page.getAttribute(name).getIsDirty() === true);
});
Now the filterDirty
will hold an array of all the dirty fields and you can just print it with the map as
filterDirty.map(function(e){ console.log(e.getName()); });
Note: Just make sure Xrm is available you can see why there is additional bit of code before the what i described above from here
the whole code will look something like this for you
// get the correct frame
for(var i=0;i<5;i++) //loop through 0 to 4
if(frames[i].Xrm.Page.ui != undefined) //check if undefined
{
Xrm = frames[i].Xrm; //assign Xrm
console.info("~: Xrm updated with frame " + i + " :~"); //show info
break; //breakout the loop
}
//Query
var attribs = Xrm.Page.data.entity.attributes.get();
//Filter
var filterDirty = attribs.filter(function(elem,index,attribs){
var name = elem.getName();
return (Xrm.Page.getAttribute(name).getIsDirty() === true);
});
//print
filterDirty.map(function(e){
console.log(e.getName());
});