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 CRM (Archived)

No OOTB way to validate date selected isn't before TODAY?

(0) ShareShare
ReportReport
Posted on by

I must be missing this very basic requirement to validate the date a user enters isn't before TODAY.  I can't see where this is possible with Business Rules.  Am I missing something?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    razdynamics Profile Picture
    17,308 User Group Leader on at

    Hi Debra

    You will need to use the following JS to perform this validation;

    Function Form_onsave(executionObj)

    {

       var shouldSave = true;

       if (shouldSave)

       {

         var contactDate = Xrm.Page.getAttribute('new_nextcontactdate').getValue();

         if (contactDate != null) {

       contactDate.setHours(0, 0, 0, 0);

       // rest of the code

       var today = new Date();

       today.setHours(0, 0, 0, 0);

       if (contactDate < today) {

           alert("Date can not be less than today");

           executionObj.getEventArgs().preventDefault();

       }

       }

    }

    I hope that helps :)

    Best Wishes, Raz

  • Verified answer
    Neil Benson Profile Picture
    7,369 User Group Leader on at

    The Business Rules feature doesn't provide a method for configuring every possible business rule you might have (unfortunately).

    The two options I would evaluate are:

    1. A custom JavaScript function that fires when the date field is changed and displays an alert to the user.
    2. A third-party add-on, such as North52, that enables non-developers to configure custom business rules.
  • Verified answer
    xrmbase Profile Picture
    on at

    Best OOTB way is to create a Real Time Workflow-

    Check condition - If "date field" is less than or equal to [process] 'execution time.

    Then Stop workflow with status = cancelled [set properties for eg: "Date should be in Future only"]

  • Cyclefitness Profile Picture
    on at

    I like this xrmbase; thank you.  I'm always looking to push the envelope with OOTB.  I didn't realize that Process value was available.

  • Suggested answer
    Anup Maharjan Profile Picture
    5 on at

    Well dynamics should have develop the validations that appears with the date and time field in the form controls.

    Anyway, there is alternate solution to this.

    1st Step:   we need JS to record current time to any required field in the form onLoad (onLoad will update the current time every time the form is loaded).

    function setCurrentDate(eContext, dateField) {
    var formContext = eContext.getFormContext();
    formContext.getAttribute(dateField).setValue(new Date());

    --- this JS can be used globally (in any entity), in the JS you have to parse the date/date-time field's id that will appear in "dateFiled".

    2nd Step: Configure the field and Business Rule validating with above field.

    Congratulation you are done.

    Suggestion to microsoft.

    You can add current date time field to global util of d365 and make available in every entity, or else develop addition function in controls of datetime field in the form.

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans