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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Prevent Page from Auto save.

(0) ShareShare
ReportReport
Posted on by

Hi, 

I want to check to condition if any one condition satisfies the Contact must save. 

For Example. If the person entered Email or phone number for a contact  it must be saved. If both are not Both are empty  it must not be saved. 

So i tried to achieve it using JavaScript. 

But the Prevent.default() function is not working, 

Any other suggestion would be grate

Thanks

Leonard Francis

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi Leonard,

    What is see in your description it say that if either phone or Email has value then only you want to save the record.

    In this sceniro you no need to write prevent default.  Just make this both field as mandatory and write a business rule if any of the field has value make the other field as Non-Mandatory and vice-Versa rule for other field.

  • Kishor Kumar Profile Picture
    3,710 on at

    Hi Francis,

    Please Check it for Auto save

    blogs.msdn.microsoft.com/.../manage-auto-save

    inogic.com/.../all-you-want-to-know-about-auto-save

    I would suggest you, write a JavaScript to check the  first filed value say Email address if does not have any value make the second filed say Number as mandatory filed.

    function SetRequirementLevel() {

       var Emailaddress = Xrm.Page.data.entity.attributes.get("Emailaddress ");

       var Number= Xrm.Page.data.entity.attributes.get("Number");

       if(Emailaddress!=null)

    {

       Number.setRequiredLevel("required");

    }

    else

    {

    Emailaddress.setRequiredLevel("required");

    }

    Hope it helps!!

  • Suggested answer
    Community Member Profile Picture
    on at

    function preventAutoSave(econtext) {

       var eventArgs = econtext.getEventArgs();

       if (eventArgs.getSaveMode() == 70) {

           eventArgs.preventDefault();

       }

    }

  • Verified answer
    ArunKumar.V Profile Picture
    on at

    Hi Francis,

    This can be achieved by using Business Rule itself.

    If you are using CRM 2016,then business rule have such functionality to acheive it or else you can go for  Number.setRequiredLevel("required");

  • Suggested answer
    Community Member Profile Picture
    on at

    Forget JavaScript. Use a simple business rule that has two conditions:

    If Email - Does not contain data

    AND Phone - Does not contain data

    Then

    Show Error message on Email field "You must provide an email address or phone number as a minimum"

    <second Action> Show Error message on Phone field "You must provide an email address or phone number as a minimum"

    Showing an error message prevents the form from saving (just like "business required" does), but with the added bonus of not needing an "else" to reverse it back out again (if you change either field, the rule is re0evaluated and sees there is no need for an error now). The message helps to explain to the user why they can't save.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans