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 :
Microsoft Dynamics CRM (Archived)

Disable or doesn't allow to select past date

(0) ShareShare
ReportReport
Posted on by 310

Hello Sir,

My question is , How to Prevent past date selection from  date field if the date field have +3 future days followup ?

means i.e. (05/02/2019)+3days = 08/02/2019 means date field doesn't allow to select 07/02/2019 or past dates

please help

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Disable or doesn't allow to select past date

    Hi,

    you can use javascript to do the calculation between days.

    [View:https://stackoverflow.com/questions/10453810/find-the-number-of-business-days-between-two-dates-in-microsoft-dynamics-crm-201]

    if the final result is not 3 days.

    use setnotification to show message.

    [View:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/controls/setnotification]

  • David Jennaway Profile Picture
    14,065 on at
    RE: Disable or doesn't allow to select past date

    You'll need to use a javascript function to do this. This can run on change of the date field, and can throw an error, and clear out the value, if the user selects a date that is in the past.

    It is just about possible to do this without code, as a business rule allows you to compare the difference between 2 date fields, and you could probably use a workflow or calculated field to store the current date, but this is quite messy, and in this case I think javascript is simpler

  • Screen one Profile Picture
    310 on at
    RE: Disable or doesn't allow to select past date

    I have only one date field & followup for +3 for same field

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Disable or doesn't allow to select past date

    hi,

    you could use current date and compare with the follow up date.

    var currentdate=new Date(); //which will return current date and time object

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: Disable or doesn't allow to select past date

    Dynamics 365 calendar control cannot be configured or modified in a supported way to do what you mentioned above.

    You could have a hidden field on the form to keep the current date and set its value using a tiny js function on load of the form as shown below

    function SetCurrentDate()

    {

    Xrm.Page.getAttribute("new_todaydate").setValue(Date.now());

    }

    And you can then have a business rule on the selected date field, and if the selected value is less than the today's date field value, you can use the Set Error on the field. This will prevent the record from being saved and also the red error message on the field will force the user to select valid date.

    Hope this helps

  • Screen one Profile Picture
    310 on at
    RE: Disable or doesn't allow to select past date

    But I want only future dates and if you select one  past day from that future date  then it should not be allowed in same date field

  • Screen one Profile Picture
    310 on at
    RE: Disable or doesn't allow to select past date

    How to prevent past date selection from future date ?

  • Screen one Profile Picture
    310 on at
    RE: Disable or doesn't allow to select past date

    How to prevent past date selection from future date , NOT from "Today's Date"

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Disable or doesn't allow to select past date

    Manoj ,

    Try with this -

    // Register below method in onchange event 
    
    function ValidatePastDate() {
        var dateFieldVal =  Xrm.Page.getAttribute("new_dateField").getValue(); // Replace Field Name
        var dateFieldValDT = new Date(dateFieldVal);
        var dateFieldValWithFormat = dateFieldValDT.getFullYear() + '/' + (dateFieldValDT.getMonth() + 1) + '/' + dateFieldValDT.getDate(); 
        var todaydate = new Date();
        var todaywithFormat = todaydate.getFullYear() + '/' + (todaydate.getMonth() + 1) + '/' + todaydate.getDate(); 
        if (dateFieldValWithFormat < todaywithFormat) {
            alert("Selected  date less than  today");
            rm.Page.getAttribute("new_dateField").setValue(null);
        }
        else {
            alert("Selected event date greater than today");
        }
    }


  • Suggested answer
    shivaram Profile Picture
    3,315 on at
    RE: Disable or doesn't allow to select past date

    Hi Manoj,

    You can only write a Javascript function and there you can get the current date + 3 days. Once you have this value, then you need to check what is updated value. If he selects which supposed to restrict, then you can clear the value and Show error message. This is the best option to achieve your requirement.Hope it helps.

    Thanks,

    Shivaram.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans