Close Campaign Response window

Did you ever notice that you will get an warning message when you close a new Campaign Response window? The message you will get is:


Are you sure you want to navigate away from this page?
Your changes have not been saved. To stay on the page so that you can save your changes, click Cancel.
Press OK to continue, or Cancel to stay on the current page.
OK Cancel

You do get this message because Microsoft is automatically filling the Received On attribute. This does set the modified flag on this attribute and the close screen event will recognize this flag. To remove the flag, you will need to reset the value for Received On by using a very simple script like this:

//Receivedon is automatically filled. Setting this value to null prevents a warning when closing the screen.
crmForm.all.receivedon.DataValue = null;

When you bind this script to the OnLoad, you will need to keep in mind that the receivedon won't be automatically filled. You can also look into binding this script to the close window event which will be a bit harder. I'm sure that's possible, who will creat this script for the community?

1 comment:

Bertil said...

Hi Ronald,

Your post was a good start on the problem. I added a couple of simple lines extra to overcome the complete problem.
First - On the OnLoad, check if FormType is Create. If so, clear the receivedon field:
if(crmForm.FormType == 1)
{
crmForm.all.receivedon.DataValue = null;
}
Second - On the OnSave, check if FormType is Create and the receivedon field is still null (user didn't manually fill). If so, fill out the field with current date:
if((crmForm.FormType == 1)&&(crmForm.all.receivedon.DataValue == null))
{
crmForm.all.receivedon.DataValue = new Date();
}

That should do the trick.
Bertil