Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Make the (RITM)catalog Task variables Read Only

Service Manager
Kilo Guru

Hi All,

I need some help to figure the best practice to make the variables read only or non editable on catalog task of RITM

Note : there are multiple huge number of catalog items. However I cannot created UI policy for each and every item and therefore created below client script onload. Unfortunately, it didn't work.

function onLoad() {


//Type appropriate comment here, and begin script below


if(g_user.hasRole('admin')) {


g_form.setVariablesReadOnly(false); //so that admins can edit the variables.


} else {


g_form.setVariablesReadOnly(true);


}


}

 

Thanks 

1 ACCEPTED SOLUTION

Tony DiRienzo
Giga Guru

UI Policies are evaluated after the Client Scripts run.  This is probably why your script is not giving the desired result:  your onLoad() Client Script is running first, and then the UI Policies are overriding it.

You should use a scripted UI Policy for what you are trying to do.  Just create a new UI Policy and check the "Run scripts" box, then put your script in the "Execute if true" field.  See this image for an example:

find_real_file.png

I hope this helps!

View solution in original post

3 REPLIES 3

Tony DiRienzo
Giga Guru

UI Policies are evaluated after the Client Scripts run.  This is probably why your script is not giving the desired result:  your onLoad() Client Script is running first, and then the UI Policies are overriding it.

You should use a scripted UI Policy for what you are trying to do.  Just create a new UI Policy and check the "Run scripts" box, then put your script in the "Execute if true" field.  See this image for an example:

find_real_file.png

I hope this helps!

Service Manager
Kilo Guru

I appreciate your help!

It worked.

 

Thanks

Dan R
Kilo Expert

you can replace your g_form.setVariablesReadOnly(true) with the following script in your client script and then it will work:

 

$("variable_map").querySelectorAll("item").forEach(function(item) {
var variable = item.getAttribute("qname");
g_form.setReadOnly("variables."+ variable, true);
});

 

 

referenced doc: https://community.servicenow.com/community?id=community_question&sys_id=ae4560e6dbe453c4852c7a9e0f9619ca