Hi,
I am getting this error 'TypeError: Cannot read property 'preventDefault' of undefined'.
Requirement is user should not be able to save the form when a field condition is not satisfied.
Code:
var AccountCustomJS = {
telephoneValue: function(executionContext){
debugger;
var formContext = executionContext.getFormContext();
var telephoneVal = formContext.getAttribute("telephone1").getValue();
if(telephoneVal.length != 10){
var alertStrings = { confirmButtonLabel: "Ok", text: "Make sure your phone number is 10 digits", title: "Error" };
var alertOptions = { height: 120, width: 260 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
executioncontext.getEventArgs().preventDefault();
}
else
var alertStrings = { confirmButtonLabel: "Ok", text: "Phone Number Saved", title: "Success" };
var alertOptions = { height: 120, width: 260 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
}
Thanks in advance.
Hello,
If my reply (or replies) answers your question take a minute and verify the answer. You can do it by clicking "Yes" at the top of the reply (or replies) under the label "Does this answer your question?"
It worked,
Thanks.
Ethan,
JavaScript is case-sensitive and your issue is in the line
executioncontext.getEventArgs().preventDefault();
replace it with
executionContext.getEventArgs().preventDefault();
and try it again.
Yes, I have passed this parameter but it still shows the error.
Hi,
Are you passing the execution context as a parameter?
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,817
Most Valuable Professional
nmaenpaa
101,156