Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Date field-Is there a way to not allow user to select a holiday?

Posted on by 728

On our order forms, we have a field to specify the date the customer would like to receive their order.

Is there a way to not allow the user entering the information a date that is a holiday?  Example: Christmas day

*This post is locked for comments

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Date field-Is there a way to not allow user to select a holiday?

    Hi,

    It is good time for you to learn webApi. At least try yourself first, if you encounter any problem, feel free to post your code in here.

    1. How to write webapi in JS.

    community.dynamics.com/.../ms-crm-2016-web-api-operations-retrieve-single-or-multiple-records

    If you are using holiday schedule feature, you have to access the calendar

    2. Calendar

    docs.microsoft.com/.../calendar-entities

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Date field-Is there a way to not allow user to select a holiday?

    Yes that would be great Idea , as I mentioned already  create separate entity and maintain all holiday with the date which you want .

    Entity Name : Holiday List

    Event Name               Day

    Christmas Day           25/12

    Bank Holiday             14/7

    Retrieve those data using WebAPI and validate whether the date you selected is exists or not .

  • wperkinson3 Profile Picture
    wperkinson3 728 on at
    RE: Date field-Is there a way to not allow user to select a holiday?

    Thank you sir.

    I would prefer not to hardcode values into the javascript.  I was hoping to have a script that would query the "Business Closures" so that maintaining dates would be easier for the end-user.

    Regards,

    Will

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Date field-Is there a way to not allow user to select a holiday?

    Hi ,

    You need to write custom logic using JS which will fire onchange of date field  like below  -

            function CheckDateOnChange() {           
                var dateTimeValue = Xrm.Page.getAttribute("new_datetime").getValue()  // Replace the date filed Name         
                var crmDateValue = new Date(dateTimeValue);
                var year = crmDateValue.getFullYear();
                var month = (crmDateValue.getMonth() + 1);
                var day = crmDateValue.getDate();  
    if (month == 12 && day == 25) { Xrm.Page.getAttribute("new_datetime").setValue(null); alert("You can not select holiday date"); } //OR You can also write like this var holidayDateMonth = day + "/" + month; if (holidayDateMonth == "25/12") { // You can maintain this value in an entity and loop through the list to validate Xrm.Page.getAttribute("new_datetime").setValue(null); alert("You can not select holiday date"); } }


  • wperkinson3 Profile Picture
    wperkinson3 728 on at
    RE: Date field-Is there a way to not allow user to select a holiday?

    Thank you.

    Is the java script available somewhere?  I would rather not have to re-invent the wheel if I do not need to do so.

    Regards,

    Will

  • Suggested answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: Date field-Is there a way to not allow user to select a holiday?

    Hi..

    You can do using JavaScript, when user selects holiday.. you need to show message to user and clear date field.

    you need to write java script on date selection.. retrieve holiday list and check selected date against holiday list, and if user selected holiday date then show alert to user.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans