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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to add validation to date only field on a form

(0) ShareShare
ReportReport
Posted on by 187

Hi there,

As per requirement, is there a way to add validation to a date only field on a model driven app form so that only today's date and future dates can be selected on the field through OOTB workflow? Or is it easier with applying business rule logic.Any further guidance or method is appreciated, thanks in advance.

I have the same question (0)
  • Sol007 Profile Picture
    187 on at
    RE: How to add validation to date only field on a form

    Hi ,

    yes the scenario is not achievable with BR due to limitations on calculated field. Although achiev with js code, see code please if this helps anyone:

    function EntitynameDateValidation (executionContext){

    var formContext = executionContext.getFormContext();

    var displaynameoffield = formContext.getAttribute ("logicalnameoffield");

    var currentDate = new Date ();

    currentDate.setHours (0,0,0,0);

    if (displaynameoffield!=null)

    {

    var logicalnameoffield = displaynameoffield.getvalue();

    logicalnameoffield.setHours (0,0,0,0);

    if (logicalnameoffield < currentDate)

    {

    formContext.getControl ("logicalnameoffield").setNotification (Sorry, select not a past date", "dm");

    }

    else

       {

    formContext.getControl ("logicalnameoffield").clearNotification ("dm");

    }

       }

    }

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    RE: How to add validation to date only field on a form

    Hello

    Can you contact me on linked in because this is the possible issues with BR. Still you are facing this issue I need more information related with this.

  • Sol007 Profile Picture
    187 on at
    RE: How to add validation to date only field on a form

    No js on the field or form. Just changed the scope to entity level same behaviour. When you select a past date the error does not automatically pop up until you click save and then that past date is saved on the record.

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    RE: How to add validation to date only field on a form

    Can you try to remove other logic on those fields which can be JS or other BRs.

    and can you also change the scope of this BR as the entity level rather than that specific form and try again

  • Sol007 Profile Picture
    187 on at
    RE: How to add validation to date only field on a form

    Yes, old date field is visible on the form and new one that was added on the form is hidden.

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    RE: How to add validation to date only field on a form

    Does both fields Like Old date field and new one is added/ present on the form ?

  • Sol007 Profile Picture
    187 on at
    RE: How to add validation to date only field on a form

    Hi, the scope of the Business rule is set correctly to form specific.

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    RE: How to add validation to date only field on a form

    Hello,

    have set the scope of Business rule correctly?

    Because if it is not set correctly then it will not work. you can set as entity/all form/form specific

    pastedimage1651774498763v1.png

  • Sol007 Profile Picture
    187 on at
    RE: How to add validation to date only field on a form

    Hi Amit Katariya, yes I did see screenshot below. When I select a past date on the field I have to click save for the error message to appear and the past date is stored in the record table until I select a current or future date for it to clear.

    BR.jpg

    I am giving js code on the field a try now: please  someone help me with what js function I need to pass for the current date not to error? If I select a past date I get the error notification also when I select a current date (today) I still get same error

    Js-field-date_5F00_LI-_2800_2_2900_.jpg

    Thanks in advance

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    RE: How to add validation to date only field on a form

    Have you followed all 3 steps which are mentioned in the Business rule. Please consider "Date" field as your existing field and "Today's Date" as the new field(Make it as hidden on the form) which you will need to create.

    pastedimage1651760634459v2.png

    You will need to use Now() function which will populate current date in "Today's Date" automatically because it is calculated field.

    and Last but not least we have BR which will compare existing "Date" field and "Today's Date" field.

    if "Date" field is less than "Today's Date" field then it will clear the "Date" field and also show the error message.

    7725.Animation.gif

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 156

#2
DAnny3211 Profile Picture

DAnny3211 89

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans