- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 11:20 AM
I have an offboarding workflow triggered by a catalog item.
There is a variable in the form called "employee_name".
I would to setup a task in my workflow if this user has an "itil" role.
I can't seem to figure out how to get this information from the variables.
I can populate a variable called Employee role from the sys_user table attribute "roles" on the form, but it comes up blank.
I'm would like a recommendation on the best way to handle this requirement.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 12:51 PM
Syntax looks fine. Just need to add current.variables.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 12:03 PM
You can make a glideajax from the client script. If you just have the employee user name, you may need to do a query to the sys_user_has_role to get the role. Below links can help you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 12:06 PM
You will need to do a GlideAjax from the client script to get the role. If you have the employee's user name, in the script include, you need to query the sys_user_has_role table. Below link should help you.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 11:42 AM
Let me make sure I understand.
First, I create a Ajax call function. Do I need to specify the “itil” role there?
var AjaxUserUtil = Class.create();
AjaxUserUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'AjaxUserUtil',
hasRole: function(user, role) {
if (!user) user = this.getParameter('sysparm_user');
if (!role) role = this.getParameter('sysparm_role');
if (user && role)
return gs.getUser().getUserByID(user).hasRole(role);
},
});
Next I create a client-side script to use this function to check for the “itil” role.
Is the below script correct?
var ga = new GlideAjax('AjaxUserUtil');ga.addParam('sysparm_name', 'hasRole');ga.addParam('sysparm_user', 'jdoe');ga.addParam('sysparm_role', 'itil');ga.getXML(function(resp) { var hasRole = JSON.parse(resp.responseXML.documentElement.getAttribute('answer')); if (hasRole) { // User has role. Note that admin users will always return true for // all roles. }});
So if the user has the itil role, then the value of variable “hasRole” is true?
And if these two steps are correct, how do I use this answer for my “if” condition in the workflow?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 12:05 PM
Ohh...So you have it in the workflow.
Then you dont need this client script.
Just in the workflow, use an If with script and in the script you can do
if (gs.getUser().getUserByID(employee_name).hasRole('itil')
return 'yes';
And from the decision Yes, you can create the task. Just to confirm employee_name has the user name.
If not, another way to find out is querying the sys_user_has_role.
Please mark this response as correct or helpful if it assisted you with your question.