How to list all CRM fields which are dirty in console?

情到浓时终转凉″ 提交于 2019-12-08 09:03:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!