How to replace event.returnValue after installing UR12 for Dynamics CRM 2011
If you are using the event.returnValue function in a custom script, after upgrading to UR12, this method could throw a script error.
Cause:
From the article https://msdn.microsoft.com/en-us/library/hh771584.aspx
Update Rollup 12 and the December 2012 Service Update support additional browsers by generating HTML that supports W3C standards. This requires removing dependencies on HTML components (HTC) that are specific to Internet Explorer.
The crmForm API that was used to access form elements in Microsoft Dynamics CRM 4.0 will continue to provide backward compatibility only for Internet Explorer. If you have code that uses the crmForm API, or any unsupported internal methods that interact with form objects that used HTC components, you must select to Include HTC support in CRM Forms on the Customization tab of System Settings . Using this setting will not allow newer versions of Internet Explorer to provide the best performance possible. Internet Explorer 10 does not support HTC components. The option to continue support for HTC will be removed in the next major release of Microsoft Dynamics CRM. At that time the crmForm API will no longer be supported. Before that time you should upgrade your form scripts to use Xrm.Page . For more information, see Upgrade Scripts to Microsoft Dynamics CRM 2011.
Resolution:
If you need a quick solution, and you only use Internet Explorer to access the CRM 2011 webpage, you can turn on HTC support in the system settings of the organization.
HTC is only supported with IE so if you want to use other browsers, you will need to upgrade your code to use the preventDefault() function.
Please see https://msdn.microsoft.com/en-us/library/gg509060.aspx
We recommend that you use the context.getEventArgs.preventDefault() function to cancel the form save. Of course, to access the context, you need to enable the OnSave event handler to pass the execution context as the first parameter to the OnSave event handler.
For example:
function Contact_OnSave(Context) {
//-------------------SAI CODE---------------//
// Set Phone number to us Format
if (Xrm.Page.getAttribute('igrn_leadsource') != null && Xrm.Page.getAttribute('igrn_leadsource').getValue() == "754340020") {
alert('Lead Source is Required and Cannot be None');
Context.getEventArgs.preventDefault();
}
var firstname = Xrm.Page.getAttribute('firstname').getValue();
var lastname = Xrm.Page.getAttribute('lastname').getValue();
NameValidation(firstname, lastname);
Best Regards
Dynamics CRM Team
Comments
Anonymous
March 01, 2013
The following syntax worked for me: Context.getEventArgs().preventDefault(); getEventArgs is also a method. Hence, getEventArgs().Anonymous
August 24, 2015
The following syntax worked for me, too: Context.getEventArgs().preventDefault(); Please update the document to use "Context.getEventArgs().preventDefault();" instead of "Context.getEventArgs.preventDefault();".