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)

Business rule - use current date !

(0) ShareShare
ReportReport
Posted on by 101


I would like to use a business rule in the Opportunities form to prevent a date field from being filled with a value that is in the past.
What is the best way to do this?


Thank you & Greetings
Patrick

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Swetha Poojary Salaskar Profile Picture
    326 on at

    Hi Patrick,

    Best ways is using javascript:

    function DateFieldValueChange(){

    var datefield= Xrm.Page.getAttribute("new_datefield").getValue();

    if(datefield!= Date.now())

    {

    // clear the field value and give error message

    }

    }

    Refer below link for reference:

    community.dynamics.com/.../set-date-as-today-using-business-roles

    Thanks,

    Swetha

    Please mark the answer as verified if it helped you.

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    It is not possible to reference current date in a business rule. You can use above mentioned javascript if you want to restrict/validate on change.

    If it is okay to validate on create/ update then you can use Real Time Workflow which triggers on create/ update and checks the date with the current execution time. if it is less then Stop the workflow as cancelled and disaply error.

    survivingcrm.com/.../

    Hope this helps.

  • Verified answer
    Pawar Pravin Profile Picture
    5,237 on at

    Hi Patric,

    You cant compare date using business rule. Anyway you could use js to validate it.

    Please refer below code for your reference:

    var DateValue = Xrm.Page.getAttribute("fieldlogicalaname").getValue();

           if (DateValue != null) {

               var today = new Date();

               var todayyear = today.getFullYear() + "";

               var todaymonth = (today.getMonth() + 1) + "";

               var todayday = today.getDate() + "";

               var datepublishyear = DateValue.getFullYear() + "";

               var datepublishmonth = (DateValue.getMonth() + 1) + "";

               var datepublishday = DateValue.getDate() + "";

               var todaydate = new Date(todayyear, todaymonth, todayday);

               var datepublish1 = new Date(datepublishyear, datepublishmonth, datepublishday);

               if (datepublish1 > todaydate) {

                   Xrm.Page.getAttribute("fieldlogicalaname").setValue(null);

                   Xrm.Page.getControl("fieldlogicalaname").setNotification("Date should not be greater than today.");

               }

               else {

                   Xrm.Page.getControl("fieldlogicalaname").clearNotification();

               }

  • Patrick Jaehne Profile Picture
    101 on at

    Hello, thanks for the answers.

    I have now created a field in which the current date will be entered. (OnLoad form)

    Now I can check if other date fields are in the past and display an error message.

    Unfortunately the error message is not displayed when opening the form because the script is too late to say so.

  • Martin Donnelly Profile Picture
    1,030 on at

    to pop a message for old records (assuming the date limit is createdOn not NOW) you might be able to compare the field to the createdOn in a business rule.  I would be careful about using == between datetime values.  It's almost impossible to be true.

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans