- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 12:54 PM
gs.hasRole('itil') && newGlideRecord("sys_user").get(gs.getUserID()).company.u_business_unit.getValue().includes('Metro') || gs.hasRole('admin') but is not working.
u_buiness_unit = is a custom field on the core company table
I am trying to only let admin and anyone that belongs to Metro see the UI action
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 01:44 PM
Hey Ricardo,
As Tiagomacul suggested try using script include like this
UI condition:
new metroUsers().isMetro(gs.getUserID());
Script include:
var metroUsers = Class.create();
metroUsers.prototype = {
initialize: function() {},
isMetro: function(user) {
var gr = new GlideRecord('sys_user');
gr.get(user);
if (gr.manager.last_name.toString().indexOf('Bordwell') > -1) { // I am just checking last name of the manager as an example
return true;
}
},
type: 'metroUsers'
};
Also, you are missing parenthesis in your query '&&' is higher than '||'.
(gs.hasRole("itil") && // added opening parenthesis
new GlideRecord("sys_user")
.get(gs.getUserID())
.company.u_business_unit.getValue()
.includes("Metro")) || // added a closing parenthesis
gs.hasRole("admin");
When debugging UI action condition, I always try to break it down one condition at a time to check which condition is breaking it, just a tip that may help in future.
Thanks
Anks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 01:09 PM - edited 03-14-2023 01:10 PM
You need a space between new and GlideRecord, but I don't think the system is going to like an inline GlideRecord like that. I'm sure you could use a GlideQuery inline like that. I have done that before but I'm not finding my example at the moment.
https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/GlideQueryAPI
Something like this is what I was thinking for the GlideQuery.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 01:28 PM
Use a script include, easier way also reusable.
https://www.servicenow.com/community/developer-blog/use-script-include-in-a-condition-field/ba-p/227...
https://docs.servicenow.com/bundle/tokyo-application-development/page/script/server-scripting/concep...
Function/Method | Return Value | Usage |
---|---|---|
gs.getUser() | Returns a reference to the user object for the currently logged-in user. | var userObject = gs.getUser(); |
gs.getUserByID() | Returns a reference to the user object for the user ID (or sys_id) provided. | var userObject = gs.getUser().getUserByID('employee'); |
gs.getUserName() | Returns the User ID (user_name) for the currently logged-in user. e.g. 'employee' |
var user_name = gs.getUserName(); |
gs.getUserDisplayName() | Returns the display value for the currently logged-in user. e.g. 'Joe Employee' |
var userDisplay = gs.getUserDisplayName(); |
gs.getUserID() | Returns the sys_id string value for the currently logged-in user. | var userID = gs.getUserID(); |
getFirstName() | Returns the first name of the currently logged-in user. | var firstName = gs.getUser().getFirstName(); |
getLastName() | Returns the last name of the currently logged-in user. | var lastName = gs.getUser().getLastName(); |
getEmail() | Returns the email address of the currently logged-in user. | var email = gs.getUser().getEmail(); |
getDepartmentID() | Returns the department sys_id of the currently logged-in user. | var deptID = gs.getUser().getDepartmentID(); |
getCompanyID() | Returns the company sys_id of the currently logged-in user. | var companyID = gs.getUser().getCompanyID(); |
getCompanyRecord() | Returns the company GlideRecord of the currently logged-in user. | var company = gs.getUser().getCompanyRecord(); |
getLanguage() | Returns the language of the currently logged-in user. | var language = gs.getUser().getLanguage(); |
getLocation() | Returns the location of the currently logged-in user. | var location = gs.getUser().getLocation(); |
getDomainID() | Returns the domain sys_id of the currently logged-in user (only used for instances using domain separation). | var domainID = gs.getUser().getDomainID(); |
getDomainDisplayValue() | Returns the domain display value of the currently logged-in user (only used for instances using domain separation). | var domainName = gs.getUser().getDomainDisplayValue(); |
getManagerID() | Returns the manager sys_id of the currently logged-in user. | var managerID = gs.getUser().getManagerID(); |
getMyGroups() | Returns a list of all groups that the currently logged-in user is a member of. | var groups = gs.getUser().getMyGroups(); |
https://servicenowguru.com/scripting/user-object-cheat-sheet/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 01:44 PM
Hey Ricardo,
As Tiagomacul suggested try using script include like this
UI condition:
new metroUsers().isMetro(gs.getUserID());
Script include:
var metroUsers = Class.create();
metroUsers.prototype = {
initialize: function() {},
isMetro: function(user) {
var gr = new GlideRecord('sys_user');
gr.get(user);
if (gr.manager.last_name.toString().indexOf('Bordwell') > -1) { // I am just checking last name of the manager as an example
return true;
}
},
type: 'metroUsers'
};
Also, you are missing parenthesis in your query '&&' is higher than '||'.
(gs.hasRole("itil") && // added opening parenthesis
new GlideRecord("sys_user")
.get(gs.getUserID())
.company.u_business_unit.getValue()
.includes("Metro")) || // added a closing parenthesis
gs.hasRole("admin");
When debugging UI action condition, I always try to break it down one condition at a time to check which condition is breaking it, just a tip that may help in future.
Thanks
Anks