- 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-13-2025 04:13 AM
How do i thigh this up with the field?
onChange can point out the field, but not onLoad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 04:17 AM
ok, I replaced variables with the field that needs to receive outcome, however, if I add madeup role, it still brings 'Yes'
Can I do instead of g_user some kind of query to the referente field where I actually detected user?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 04:29 AM
why are you testing with some random role which is not present in instance?
also I informed please test by actual user and not with admin
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-13-2025 04:22 AM
Hi @mattmg
gs.hasRole also return Yes if you're Admin.
Flag that indicates whether the current user has at least one of the specified roles.
- true: User has at least one of the passed-in roles. Also returns true if the user has the administrator role.
- false: User does not have any of the passed-in roles.
so do you want to check that if the user has exact role?
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 04:31 AM
@mattmg Oops sorry Matt. Can you clarify that is it to validate the user from the Requested by field? (Not the logged in user).