- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 07:59 AM
Hello all,
I have a catalog item and I would to set some of the variables to read only based on the login user role.
I created the following OnLoad client script to set the variable to read only if the login user does not has "hari_admin" role.
The script is not working. Could someone help me to take a look?
__________________________
function onLoad() {
var hariUser = g_user.hasRoleExactly('hari_admin)');
if (hariUser) {
g_form.setReadonly('list_of_assets', false);
}}
__________________________
Regards,
Hong
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:08 AM
Looks like either there is another script/ policy which is there on Asset field or backend name of asset field is incorrect, this is very simple requirement please check again. Try below once.
function onLoad() {
//Type appropriate comment here, and begin script below
var hariUser = g_user.hasRoleExactly('hari_admin');
if (!hariUser) {
g_form.setReadOnly('list_of_assets', true);
}
}
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:13 AM
it should be like this
function onLoad() {
var hariUser = g_user.hasRoleExactly('hari_admin)');
if (hariUser.toString() == 'true') {
g_form.setReadonly('list_of_assets', false);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 08:03 AM
On your list_of_assets variable, is mandatory checked? Are there any UI Policies that make the variable mandatory? The reason I ask is if a variable is mandatory it cannot be made read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 08:40 AM
Hi Brian,
No.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 08:06 AM
Hi,
'O' is small in Readonly function, it should be upper case like below
g_form.setReadOnly();
Mark my answer as correct if that helps.
Regards
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 08:41 AM
Hi Musab,
Even I changed to g_form.setReadOnly(), it is still not working.