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)

Date/Time Field validation

(0) ShareShare
ReportReport
Posted on by

i have a Date/Time field in a contract , it is set to accept only date.

i opened Form Editor wanted to set a validation so that this field will accept any date >= today's date

means the user cant select any previous date, but i cant see where to set this validation

any help?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Hi,

    In business rule unfortunately there is no logic for today's date. That's why you need to create customization in javascript to only let user key in value more than today.

  • Community Member Profile Picture
    on at

    Thank you Temmy for your reply,

    in the Form Editor >>Change Field Properties, where can i use this JS ?

  • Suggested answer
    Nitin Meria Profile Picture
    216 on at

    Hi Shaka,

    You can check the value of the currently selected field and then clear it if it is greater than today's date.

    Check out Guido Preite's post on the same (includes JS code) :

    https://community.dynamics.com/crm/f/117/t/163651

  • Suggested answer
    Nitin Meria Profile Picture
    216 on at

    Hi Shaka,

    Change Properties->Events (Tab) then add a new onchange event.

    7674.Issue.png

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Shaka ,

    Try with this  -Make sure you attached the javascript function in change of the date field .  Go to form editor double click on the date fields in the event area select onchange and put the function name .

                 function SetNullIfDateLessThanEqualToday() {
                     var dateTimeValue = Xrm.Page.getAttribute("new_datetime").getValue()  // Replace the date filed Name
                     var crmDateValue = new Date(dateTimeValue);
                     var eventdateTimeValue = crmDateValue.getFullYear() + '/' + (crmDateValue.getMonth() + 1) + '/' + crmDateValue.getDate(); 
                     var todaydate = new Date();
                     var today = todaydate.getFullYear() + '/' + (todaydate.getMonth() + 1) + '/' + todaydate.getDate(); 
                     if (eventdateTimeValue <= today) { 
                         alert("event date less than equal today");
                         Xrm.Page.getAttribute("new_datetime").setValue(null); // Replace the date filed Name
                     }                 
                 }


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