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

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Date/Time Field validation

    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
                     }                 
                 }


  • Suggested answer
    Nitin Meria Profile Picture
    Nitin Meria 216 on at
    RE: Date/Time Field validation

    Hi Shaka,

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

    7674.Issue.png

  • Suggested answer
    Nitin Meria Profile Picture
    Nitin Meria 216 on at
    RE: Date/Time Field validation

    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

  • RE: Date/Time Field validation

    Thank you Temmy for your reply,

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

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: Date/Time Field validation

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans