Configuring the datepicker

keithlyon
Kilo Contributor

I am very new to ServiceNow. We are trying to limit the ability to enter dates in a field to the datepicker only. I have referenced the doc -

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/administer/time/task/t_ConfigureD...

and confirmed that the property is configured to true (we are on Helsinki). However dates still can be typed into the datepicker. I'm sure there is something easy I need to do to the field or form to enable this, but I am unable to find anything anywhere. Any help would be appreciated.

Thanks,

Keith

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi Keith,
You can easily achieve this via an onLoad Client Script. See below,   just replace 'field_name' with the actual name of your date or date/time field.


  1. function onLoad() {  
  2.   // Sets the field's background to a gray, making is appear read-only.  
  3.   g_form.getControl('field_name').className='disabled';  
  4.   // Sets the field read-only  
  5.   g_form.getControl('field_name').readOnly=true;  
  6. }  


Please mark this response as correct and helpful via your post link (Configuring the datepicker ) to help others with the same question.



Thanks,


Robbie


View solution in original post

7 REPLIES 7

Robbie
Kilo Patron
Kilo Patron

Hi Keith,
You can easily achieve this via an onLoad Client Script. See below,   just replace 'field_name' with the actual name of your date or date/time field.


  1. function onLoad() {  
  2.   // Sets the field's background to a gray, making is appear read-only.  
  3.   g_form.getControl('field_name').className='disabled';  
  4.   // Sets the field read-only  
  5.   g_form.getControl('field_name').readOnly=true;  
  6. }  


Please mark this response as correct and helpful via your post link (Configuring the datepicker ) to help others with the same question.



Thanks,


Robbie


keithlyon
Kilo Contributor

This worked perfectly. Thanks!


keithlyon
Kilo Contributor

So now that we've tested, we've found the client script only modifies the date picker after the first save of the record. Our client is requesting that the datepicker be disable from manual entry on create as well. I have tried creating a second client script for onChange, onSubmit, and onCellEdit with no luck.   Anythoughts on how I would cause the client script to kick in when I hit create new case?


Robbie
Kilo Patron
Kilo Patron

Hi Keith,



How did you go?



Please mark this response as correct and helpful via your post link (Configuring the datepicker ) to help others with the same question.



Thanks,


Robbie