How to disable days from being selected on the Date/Time Datepicker field

craig_attersall
Kilo Contributor

When I requested a patch on Service-Now HI that required a version entitlement request, I was presented with a Date/Time Datepicker field to schedule the patch. On this field I could not select a date in the past or 3 days in the future (3 days for the version entitlement request).

See below, the 2 Aug was the first date that I could select.
Datepicker with disabled days.png

Does anyone know how they did this?

I know you can produce alerts if you select a past date, like this http://wiki.servicenow.com/index.php?title=Verify_Request_Start_and_End_Dates, but how do you grey-out the past dates so they can't be selected?

7 REPLIES 7

asd13
ServiceNow Employee
ServiceNow Employee

Hey Craig,


I think the greyed dates just denote they're in the previous month.   As for the selection of the past dates, I've only alerted on the submission and not sure how you would go about restricting on the UI.   I'd suggest looking at the UI Macro - ui_date - and see if you can do something with the object GwtDateTimePicker.   Maybe someone with backend access to HI can answer.



cheers


Dave


coryseering
ServiceNow Employee
ServiceNow Employee

Hi Craig,



I've tried posting an answer to this question about 15 times over the past two days, but I keep getting en error. It may not like the code I was trying to post, so I'll leave that out of this response and see if it goes through.



I helped build the entitlement request item, and have worked on the upgrade request item as well. I took a look at our items in Hi, and I can tell you we aren't doing anything overly-fancy.



There is an onChange script on the date field which makes a GlideAjax call to see if the date/time you picked is within the acceptable time period. It also fudges the value of now just a bit, so if you wanted to upgrade ASAP but it took you a minute to fill out the form, it'll still go through.



If the value is outside of the acceptable range, it simply sets the value to an empty string.



All of the values for the current month could technically be clicked. If you use the arrows on the datepicker to go back a month, you could click those values too. However, the onChange script would validate as explained above, and if it failed, the selection would be imemdiately undone.



I think this is why it appears that those dates can't be clicked- because after you click one that you aren't "allowed" to, it resets the field to an empty string.



You should be able to mock up something similar quickly and validate the behavior too.



Fingers crossed that this response gets through!


so can you provide the code as well please? the GlideAjax that you called from client script?


coryseering
ServiceNow Employee
ServiceNow Employee

Hi Soni,



Sorry, I don't even have read-only access to that code anymore. At the time I posted my previous answers, I was also working on an integration, which necessitated access to a development clone of Hi. As I'm not working on that anymore, I don't have access to any Hi code.



The code wasn't complex. I know there was a client-callable Script Include which had a method that accepted a date/time, instantiated a new GlideDateTime from it, and checked that it wasn't more than a minute or so in the past. Sorry I can't be more specific than that.