- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 08:51 AM
Hey,
I have a requested by field on the form (refferenced to sys_user table), which based on it's default value detect user (javascript:gs.getUserID()) - that works fine.
Now I would like to create another field
'Does user has a 'itil' role?', how on the Catalog Item/Record producer can query for this and push the outcome to that new field?
TIA
Matt
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 03:56 AM
try to use onLoad catalog client script
Ensure you perform testing by logging in and not impersonating
function onLoad() {
if (g_user.hasRole('itil'))
g_form.setValue('variable', 'Yes');
else
g_form.setValue('variable', 'No');
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 10:25 PM
Hello @mattmg ,
You can use an onchange catalog client script on the requested by,
g_user.hasRole(g_form.getValue(newValue))
It returns true if the user has ITIL role.
You can write an if else condition and populate the value in the Second field, 'Does user has a 'itil' role.
2nd Approach, in the default value, you can write similar to gs.getUserID(), you can write,
javascript:gs.hasRole('itil'). It directly returns True or False in the Second field.
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 10:38 PM
Hi @mattmg
If your variable is in Yes/No type. You can try to put this line below into as Default Value.
javascript:gs.hasRole("itil") ? "Yes" : "No"
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 03:45 AM - edited 02-13-2025 03:49 AM
this is what I get.
When I do 'javascript:gs.hasRole("itil") ? "Yes" : "No"'
it comes back Yes,
but equally if I change the role, that me as a logged in user doesn't have, like:
javascript:gs.hasRole("test_role_that _doesnt_exsist") ? "Yes" : "No"
it comes back with Yes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 03:56 AM
try to use onLoad catalog client script
Ensure you perform testing by logging in and not impersonating
function onLoad() {
if (g_user.hasRole('itil'))
g_form.setValue('variable', 'Yes');
else
g_form.setValue('variable', 'No');
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader