Wednesday, September 29, 2010

Are you sure you want to navigate away from this page?

Some times we used to put some default values in the form level as per the requirements.
Even if the user is doing to create a new record and with out changing anything doing X-off or close, it will give an alert saying "Are you sure you want to navigate away from this page? ...".
So it should not come, as the user did not do anything.
To avoid this there are ways and it depends on the type of attribute it is.

#1 for non-lookup types

window.setTimeout("crmForm.all.<non-lookup_Name>.defaultValue = crmForm.all.<non-lookup_Name>.DataValue",200);

#2 for lookup types

crmForm.<lookup_name>.DataValue = crmForm.<lookup_name>.defaultValue;

if(crmForm.FormType == 1) {
var lookupItem = new Object();
var lookup = new Array();
lookupItem.name = '<lookup_name>';//which will be displayed in lookup
lookupItem.id = <lookUpGUID> // This is the Guid of the record
languageitem.typename = 'new_lookupname';//schema name of the lookup attribute
lookup[0] = lookupItem;

crmForm.<lookup_name>.DataValue = lookup;
crmForm.<lookup_name>.defaultValue = crmForm.<lookup_name>.DataValue;
}

Sudhanshu

1 comment: