- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2021 06:42 PM
In our environment I have a request to make all variables in requested item view read only. Which is easy enough, I have a ui policy on the sc_req_item table with the below script that marks all variables read only.
function onCondition() {
g_form.setVariablesReadOnly(true);
}
I also need to make all variables read only on the task view, but leave the option for specific variables throughout different catalog items to be editable for the fulfillers to enter data when closing the task. For example "Create user account" task may have a single line variable for "Username" for the fulfiller to enter the username into when closing. Or "Deploy computer" may have a single line variable for "Computer Name".
Is there a best practice for this type of thing? My first thought is to have a UI policy script on each catalog item that applies to the task view. Looping through all available variables, marking those that are not in an exception array as read only. This will get pretty overwhelming as more and more catalog items are created. So I'm hoping there is something a bit more scalable than individual UI policy scripts.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- 5,511 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2021 07:49 PM
If the exception is having a variable editable on the task, you could have an on Load Client Script that makes all variables read-only (as above) then create UI Policy on Catalog Task that controls your exception by making them read-only = false. UI Policy runs after Client Script.
If the exception is the variable being read-only, then control purely through UI Policy.
The best practice would be to minimise code and prefer codeless or low code solutions where possible. Sometimes it makes sense to use code to minimise configuration overhead.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2021 07:39 PM
Hi
UI Policies is the best practice to make fields read only/mandatory/visible.
Thanks & BR,
Murthy
Please mark my answer helpful if its solves your query.
Murthy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2021 07:49 PM
If the exception is having a variable editable on the task, you could have an on Load Client Script that makes all variables read-only (as above) then create UI Policy on Catalog Task that controls your exception by making them read-only = false. UI Policy runs after Client Script.
If the exception is the variable being read-only, then control purely through UI Policy.
The best practice would be to minimise code and prefer codeless or low code solutions where possible. Sometimes it makes sense to use code to minimise configuration overhead.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2021 02:34 PM
Thanks, this is basically the route I took. I enabled the default client scripts for item and task readonly, set exceptions in it based off of sysid of specific catalog items. Within those catalog items I did a UI policy script to set all as readonly, with the input variables as mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2021 10:45 PM
Hi ,
The best way to make fields mandatory or read only is by using ui policies and also we can use the cleint scripts to make fields mandatory or read only.
Based upon your criteria you can use the best desire one.
Thanks and regards
Sai Venkatesh