
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2018 11:06 PM
Hi All,
Is it possible to to make variables editable on catalog task form based on user roles by using Client Script??...
The requirement is some variables should be editable for ITIL users
Can someone help me with this?
Thanks and Regards,
Angshuman
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2018 11:13 PM
Yes, It is possible. You can write a client script like if user has role set field to writable else readable.
var rqdrole = g_user.hasRole('RoleName');
if (rqdrole){
g_form.setReadonly('fieldname',false);
}
Hope this helps.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2018 11:31 PM
yes you can do it via UI policy and client script.
function onLoad(){ var requestedfor = g_form.getValue('requested_for');
var gr= new GlideRecord ('sys_user_has_role');
gr.addQuery('user',requestedfor);
gr.query();
while(gr.next())
{
if <condition>
g_form.setReadonly('incident_state',true); g_form.setReadonly('impact',true); g_form.setReadonly('urgency',true);
}
also refer to below link:-
https://docs.servicenow.com/bundle/jakarta-application-development/page/script/useful-scripts/refere...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2018 03:48 AM
Hi,
I have tried using UI policy both using Run Script and normal UI Policy action, its not working and I am not sure if dot walking is allowed in UI Policy as I used "g_form.setReadonly('variables.variable_name',false)" .
I have also tried the following client script in Catalog Task table :-
function onLoad(){
if (g_user.hasRole('itil')){
g_form.setReadonly('fieldname',false);
}
}
it still didn't work..... 😞
In the RITM form for the same catalog item all the variables are editable for Admin but Read-Only for ITIL users. But, in Catalog Task form it is required editable for both Admin and ITIL users. It is already editable for Admin but for the ITIL users its the same as in RITM Form.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2018 04:09 AM
Hi Guys,
I have tried using UI policy both using Run Script and normal UI Policy action, its not working and I am not sure if dot walking is allowed in UI Policy as I used "g_form.setReadonly('variables.variable_name',false)" .
I have also tried the following client script in Catalog Task table :-
function onLoad(){
if (g_user.hasRole('itil')){
g_form.setReadonly('fieldname',false);
}
}
it still didn't work..... 😞
In the RITM form for the same catalog item all the variables are editable for Admin but Read-Only for ITIL users. But, in Catalog Task form it is required editable for both Admin and ITIL users. It is already editable for Admin but for the ITIL users its the same as in RITM Form.
Thanks,
Angshuman

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2018 04:57 AM
Please correct syntax to setReadOnly from setReadonly.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2018 05:15 AM
Hey,
That was a type here.....
I had typed setReadOnly, but it didn't work actually.