Sunday, December 16, 2012

Dynamics CRM 2011 - Preventing close alert

Dynamics CRM 2011 - Preventing close alert


In Dynamics CRM 4.0 it was easy to disable close alert by using this one line of code before you close the window:
crmForm.detachCloseAlert();

In Dynamics CRM 2011, this method is depracated. The way i workaround it, is setting all dirty fields submit mode to never.
function IsAttributeDirty(attribute, index) {    return attribute.getIsDirty();}
function SetAllDirtyFieldsToNeverSubmit(){ var attributes = Xrm.Page.data.entity.attributes.get(IsAttributeDirty); for (var i in attributes) { attributes[i].setSubmitMode("never"); }}//ends function RemoveAllDirtyFields(){
Close window with out fields change message:
SetAllDirtyFieldsToNeverSubmit();
Xrm.Page.ui.close();

1 comment: