Monday 23 September 2013

Finding the Culprit - Dirty Fields

Always had this issue...Finding which field is Dirty


When we are developing some functionality, we are frequently hit with the IE's save alert box. This dialog box shows up when any of the field is actually dirty (in the sense, its value is modified). 


IE Save Alert

 The pain point here is, we don't know which field it is, as some part of our code, might actually be setting some field, which we are not aware of.

The below function will help in finding the dirty fields. All you need to do is call this function whenever and wherever required.


Code to throw dirty fields

function ThrowDirtyFields() { 
    var ctrlName = Xrm.Page.ui.controls.get(); 
    for (var i in ctrlName) { 
        var ctrl = ctrlName[i]; 
        if (ctrl.getControlType() != 'subgrid' && ctrl.getControlType() != 'notes' && typeof ctrl.getAttribute() ! 'unknown' && typeof ctrl.getAttribute() != 'undefined') { 
            var isDirty = ctrl.getAttribute().getIsDirty(); 
            if ((isDirty != null) && (isDirty == true)) 
                alert(ctrl.getName()); 
        } 
    } 
}


Hope it helps. !! :) Happy Coding!!

No comments:

Post a Comment