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)

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

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