web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

TypeError: Cannot read property 'preventDefault' of undefined

(0) ShareShare
ReportReport
Posted on by 17

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.

I have the same question (0)
  • Joana Pinto Profile Picture
    740 on at

    Hi,

    Are you passing the execution context as a parameter?

    pastedimage1605005494714v1.png

  • Ethan_009 Profile Picture
    17 on at

    Yes, I have passed this parameter but it still shows the error.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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.

  • Ethan_009 Profile Picture
    17 on at

    It worked,

    Thanks.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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?"

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 60 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 51

#3
Satyam Prakash Profile Picture

Satyam Prakash 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans