Best practice to make read only variables editable in each task?

Andy P1
Tera Contributor

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.

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

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

View solution in original post

4 REPLIES 4

Murthy Ch
Giga Sage

Hi @Andy P 

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.

Thanks,
Murthy

The SN Nerd
Giga Sage
Giga Sage

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

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.

SAI VENKATESH
Tera Sage
Tera Sage

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