- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have created a role and added the role to the user, when I check in background script I do see the role for user. But in workflow when I try to get the "Requested For" user's role in condition, it's always evaluating to false.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Workflow conditions in ServiceNow run in the system context, not under a user session, so methods like hasRole() don’t work on referenced users such as “Requested For.” While checking in a background script works since it runs in your own user context, within a workflow the “Requested For” field is just a reference to a sys_user record, not an active GlideUser object.
To accurately check a user’s role inside a workflow, you need to query the sys_user_has_role table directly, for example by creating a GlideRecord query that looks for the “Requested For” user and the role name. This ensures the condition correctly evaluates whether that user actually holds the specified role. You can also encapsulate this logic in a reusable Script Include and call it in the workflow condition.
If the role was recently added or assigned through a group, you may need to refresh the user’s role cache or log out and back in before the workflow recognizes it.
ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.
ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ
ꜱʀᴇᴇʀᴀᴍ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SuvarnaJadhav,
can you provide any of your configurations?
What role it is, what scope (global or custom)???
Also in the workflow, please share the condition how it is built.
Tip: for the roles, there are hasRole('itil') and hasRoleExactly('itil') - in the first one admin will evaluate true (itil is inherited) while in the latter it would be false...
Please give me more context to give you better response
This reply is 100 % GlideFather and 0 % AI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I was able to achieve it by looking at sys_user_has_role, thank you for your response, appreciate it.
Suvarna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Workflow conditions in ServiceNow run in the system context, not under a user session, so methods like hasRole() don’t work on referenced users such as “Requested For.” While checking in a background script works since it runs in your own user context, within a workflow the “Requested For” field is just a reference to a sys_user record, not an active GlideUser object.
To accurately check a user’s role inside a workflow, you need to query the sys_user_has_role table directly, for example by creating a GlideRecord query that looks for the “Requested For” user and the role name. This ensures the condition correctly evaluates whether that user actually holds the specified role. You can also encapsulate this logic in a reusable Script Include and call it in the workflow condition.
If the role was recently added or assigned through a group, you may need to refresh the user’s role cache or log out and back in before the workflow recognizes it.
ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.
ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ
ꜱʀᴇᴇʀᴀᴍ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
share screenshot on what you are trying to do in workflow.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
