Issue setting field to readonly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 09:16 PM
I'm trying to toggle the read-only property of the Next Step field (u_next_step) on the Service Record screen. I have tried two approaches (UI Policy and Client Script) and neither approach works. I know the code is being executed as I have added log statements to the console. I also in the same code set sys_created_on to read-only (just to see that it works) and that field is being set to read-only while Next Step is not. Both fields are initially editable in the form design. When I create a new SR, the form loads and the Created field is grayed out but the Next Step field is not.
Here is the client script code:
And here are the console statements
I'm sure this should be really simple, but I can't figure it out. Any help would be greatly appreciated. Thx.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 09:18 PM
Hi there,
Have you verified the fields are not mandatory?
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 10:15 PM
Hi Mark,
No the field is not mandatory.
Cheers, Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 10:21 PM
Hello @Mark9 ,
If the Next Step field (u_next_step) has been marked as Mandatory, then the field will not become read-only.
This is the servicenow behaviour that if field is mandatory and it does not have any value then you cannot make it read-only.
If this is the case then you can first mark the field mandatory false and then make it read-only as below :
g_form.setMandatory('u_next_step', false);
g_form.setReadonly('u_next_step', true);
If my answer solves your issue, please mark it as Accepted ✔️ and Helpful 👍 based on impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 10:36 PM
Thanks for your reply Vrushali. It is not a mandatory field but just in case I added the line to set mandatory to false as you suggested, but it still isn't working.