- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 09:31 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 09:49 AM
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:
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 09:49 AM
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:
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 10:03 AM
I appreciate your help!
It worked.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 10:06 AM
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