- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 09:28 PM
I want to display help button in incident form only when the user in the owned by field has role hl_help.
the owned by field is in incident table.
I just tried this condition but it doesnt work
current.u_owned_by.role=="hl_help"
Thanks in advance
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 09:47 PM
current.u_owned_by.role=="hl_help"
That won't work as Roles are stored in the many to many table "sys_user_has_role".
Luckily enough ServiceNow provide us with the GlideUser API to do this without needed to query the database directly.
See http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0
Line by line:
var glideUser = gs.getUser();
var ownedByUser = glideUser. ÂgetUserByID( Âcurrent.u_owned_by.user_name);
var hasRole = ownedByUser.hasRole('hl_help');
As Pradeep has suggested, throw this in a script include and call it in your condition field.
Script Include
Script Includes - ServiceNow Wiki
You could then end up with something like
Script Include
UIActionConditionHelper.userHasRole = function(role, user_name) {
var glideUser = gs.getUser();
var ownedByUser = glideUser. ÂgetUserByID(user_name);
var hasRole = ownedByUser.hasRole(role);
return hadRole;
};
var UIActionConditionHelper = Class.create();
UIAction Condition
UIActionConditionHelper.userHasRole('hl_help',current.owned_by.user_name);
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 09:34 PM
Hi Joshwa,
Is the role field populated on the sys_user table. The best way would be to write a script include and then return true or false based on the validation.
Please let me know if you have any questions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 09:47 PM
current.u_owned_by.role=="hl_help"
That won't work as Roles are stored in the many to many table "sys_user_has_role".
Luckily enough ServiceNow provide us with the GlideUser API to do this without needed to query the database directly.
See http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0
Line by line:
var glideUser = gs.getUser();
var ownedByUser = glideUser. ÂgetUserByID( Âcurrent.u_owned_by.user_name);
var hasRole = ownedByUser.hasRole('hl_help');
As Pradeep has suggested, throw this in a script include and call it in your condition field.
Script Include
Script Includes - ServiceNow Wiki
You could then end up with something like
Script Include
UIActionConditionHelper.userHasRole = function(role, user_name) {
var glideUser = gs.getUser();
var ownedByUser = glideUser. ÂgetUserByID(user_name);
var hasRole = ownedByUser.hasRole(role);
return hadRole;
};
var UIActionConditionHelper = Class.create();
UIAction Condition
UIActionConditionHelper.userHasRole('hl_help',current.owned_by.user_name);
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 10:18 PM
Thank you Pradeep/Paul.
Great Learning...
Everyday you guys are teaching me something
Thanks for your wonderfull help
Cheers..