问题
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 ?
回答1:
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());
});
回答2:
Open the developer tools (F12), select the Console and enter the following:
Xrm.Page.data = Xrm.Page.data || frames[0].Xrm.Page.data || frames[1].Xrm.Page.data; Xrm.Page.data.entity.getDataXml()
The returned Xml will list the dirty fields and their values as XML. For example
<contact><firstname>changed on form but not saved in db</firstname></contact>
来源:https://stackoverflow.com/questions/47926862/how-to-list-all-crm-fields-which-are-dirty-in-console