Hi Team,
I have registered a Javascript function "validateYear" on the OnChange event of the year field. I am doing a validation like if the year field has less than 4 characters then alert the user.
Action Performed : On the Form, i entered year as 12
Expected Result :
validateYear function is triggered and execute #line from 2 to 6.
execute #line 7 and sets the year as empty string. so this will again trigger that validateYear function. This time when the #line 2 gets executed it is expected to have the year as empty string and it should not execute the line 3.
Actual Result :
validateYear function is triggered and execute #line from 2 to 6.
execute #line 7 and sets the year as empty string. so this will again trigger that validateYear function. This time when the #line 2 gets executed it still holds the year value as 12 .
Code Below :
I guess this is a Microsoft bug on the crm 2016 online 8.1 version. As anyone face this same issue ?
Thanks & Regards,
Awad.
*This post is locked for comments
Yes that seems to be a bug. What about setting the variable year to an empty string after execution of line 7 as a workaround? Then the lines 4 to 6 should not be executed again
Hth Thomas
Hi Awad,
Faced this issue in CRM 2016. setValue() is triggering onChange(). Looks like this is a bug in CRM.
As per MSDN, setValue() should not trigger onChange.
https://msdn.microsoft.com/en-us/library/gg334409.aspx
Updating an attribute using setValue will not cause the OnChange event handlers to run. If you want the OnChange event handlers to run you must use fireOnChange in addition to setValue.
One workaround is turning turbo form off (turning legacy form rendering ON ) using Settings > Administration > System Settings > General.
But turning turbo forms off has some other side effects and issues.
Another workaround is using JavaScript.
Can you try the below code:
var isSettingYear = false; function validateYear() { if (isSettingYear) { return; } var year = Xrm.Page.getAttribute("year").getValue(); if (year != null && year != "") { if (year.length < 4) { Xrm.Utility.alertDialog("Please enter a valid Year", function() {}); isSettingYear = true; Xrm.Page.getAttribute("year").setValue(""); isSettingYear = false; return; } } }
Regards,
Charmis
Hi Guido,
Line 7 does getting triggered OnChange in the CRM 2016 online instance (8.1.0.563) (DB 8.1.0.538). And so i have the issue.
You can try by writing a simple javascript, which just shows an alert and then clears the same field value on which this onchange is triggered.
Hello Awad,
Try these 2 options, it may help you.
crmbusiness.wordpress.com/.../crm-2013-javascript-null-setting-oddity
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156