getControl is not working in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 08:47 AM
Hi All,
I have a field called -"Start Date" of type 'Date' on the catalog item. The requirement was to make the field read only so that the user can make use of Calendar and do not enter the date manually. So, I have written a onLoad catalog client script to make it readOnly.
g_form.getControl('start_date').readOnly=true;
This script works for the Desktop view but doesn't work in the service portal. Can anyone suggest some logic which can work on both UI Type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 08:51 AM
Hi,
Why dont you just use the below, works on all UI
g_form.setReadOnly('start_date', true);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 08:58 AM
@Anurag Tripathi I can't use the 'setReadOnly' method as I need the control of the calendar and make the field read only for manual intervention. I have attached the image for your reference.
The user should be able to use the calendar option instead of manually entering the date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 10:11 AM - edited 01-08-2025 10:12 AM
I see, you want to force user to use the date picker,
Try this
g_form.getElement('date_field_name').readOnly = true;
If the above doesn't work then maybe solution provided here
Solved: How to make date text box Read-Only in Service Por... - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 04:28 AM
This do not work in ESC