
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 06-13-2022 12:48 AM
What is Glide User API and Usage
- Glide User API and methods are useful to get current logged in user details and their roles. The typical use cases are personalizing feedback to the user and inspecting user roles.
- Glide user typically running from client side (browser)
- Very simple API in servcenow platform
- Typically used in client scripts and UI policies but is also found in UI actions that run on the client.
- Glide User Contains name and role information about the current user.
- The global object of Glide User is (g_user)
- This API contain different methods to use in our platform
- Determine if a user has a particular role assigned or not
- Using the Glide User API avoids the need to use the slower Glide Record queries to get user information.
Note: We cannot used in Business Rules or UI Actions that run on the server.
Glide User Methods
Glide User | |
firstName() |
userID() |
lastName() |
hasRoles() |
fullName() |
userName() |
hasRole() |
getFullName() |
hasRoleExacctly() |
getClientData() |
hasRoleFromList() |
getClientName() |
Practically work with these methods |
Glide User Exercises
- Navigate Incident table
- Open one existing record
- Click on Ctrl+Shift+j Ctrl+Shift+J
- Open Java Script Executor
- Run our code here
- Working with firstName () method
Display current user First Name
alert (g_user.firstName);
- Working with lastName () method
Display current user Last Name
alert (g_user. LastName);
- Working with fullName () method
Display current user Full Name
alert (g_user. fullName);
- Working with userID () method
Display current 32-digit user ID
alert (g_user. userID);
- Working with hasRole () method
Display true if the current user has the specified role
alert (g_user.hasRole ('admin'));
- Working with hasRoleExactly () method
Display true only if the current user has the specified role.
alert (g_user.hasRoleExactly('itil'));
- Working with hasRoleFromList () method
Returns true if the current user has at least one of the specified roles or has the admin role.
alert (g_user.hasRoleFromList('itil, admin'));
- Working with hasRoles () method
Returns true if the current user has any role.
alert (g_user.hasRoles ('itil, admin'));
- Working with userName () method
Return current logged in user name
alert ('User Name is' + g_user.userName);
- Working with fisrtName () and lastName () and userName () and userID () methods
This script will shows the difference between the firstName, lastName, userName, and userID property values.
alert("First Name = " + g_user.firstName
+ ", \n Last Name = " + g_user.lastName
+ ", \n User Name = " + g_user.userName
+ ", \n User ID = " + g_user.userID);
Glide User from Scoped or Global
The GlideUser (Scoped) API provides access to information about the current user and current user roles. Using the GlideUser API avoids the need to use the slower GlideRecord queries to obtain user information.
Glide User Server or Scoped Methods
Glide User (Scoped or Global) | |
getCompanyID() |
getID() |
getDisplayName() |
getPreference() |
getDomainID() |
getRoles() |
getFirstName() |
getUserRoles() |
getLastName() |
isMemberOf() |
getFullName() |
hasRole() |
getName() |
savePreference() |
getEmail() |
getUserName() |
Practically work with these all methods |
Glide User Scoped or Global Exercises
- Navigate to System Definition
- Open Scripts – Background Application
- Write code into given space
1.Working with getFirstName() method
Returns the user's first name.
var cu = gs.getUser();
gs.print(cu.getFirstName());
2.Working with getLastName() method
Returns the user's last name.
var cu = gs.getUser();
gs.print(cu.getLastName());
3.Working with getFullName() method
Returns the user's full name.
var cu = gs.getUser ();
gs.print (cu.getFullName ());
4.Working with getEmail() method
Returns the user's email address.
var cu = gs.getUser ();
gs.print (cu.getEmail ());
5.Working with getID() method
Returns the 32-digit sys_id of the current user.
var cu = gs.getUser ();
gs.print (cu.getID ());
6.Working with getName() method
Returns the user ID, or login name, of the current user.
var cu = gs.getUser();
gs.print(cu.getName());
7.Working with getCompanyID() method
Returns the current user's company sys_id.
var cu = gs.getUser ();
gs.print (cu.getCompanyID ());
8.Working with getDisplayName() method
Returns the current user's display name.
var cu = gs.getUser ();
gs.print (cu.getDisplayName());
9.Working with getDomainDisplayName() method
Returns the display value of the user's session domain.
var cu = gs.getUser ();
gs.print (cu.getDomainDisplayValue ());
10.Working with getMyGroups () method
Returns an iterator containing the list of all groups to which the user belongs. Only active groups are returned.
var myGroupsArray = gs.getUser ().getMyGroups ().toArray ();
gs.print (myGroupsArray [0]);
11.Working with getRoles () method
Returns a list of roles that includes explicitly granted roles, inherited roles, and roles acquired by group membership.
var cu = gs.getUser ();
gs.print (cu.getRoles ());
12.Working with getUserByID () method
Returns the user object associated with the passed-in user ID (sys_id in sys_user) or user_name.
var newUser = gs.getUser ();
gs.print (newUser.getUserByID ('abel.tuter').getFirstName ());
13.Working with getUserRoles () method
Returns the list of roles explicitly granted to the user.
var cu = gs.getUser ();
gs.print (cu.getUserRoles ());
14.Working with hasRole () method
Determines if the current user has the specified role.
var cu = gs.getUser ();
gs.print (cu.hasRole ('admin'));
15.Working with isMemberOf () method
Determines if the current user is a member of the specified group.
var cu = gs.getUser();
gs.print(cu.isMemberOf('database'));
Feel free to comment for any queries or suggestions. If this article helps you, share it with your fellow developers and mark as helpful.
Regards,
Vaishnavi Lathkar
- 2,840 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi, Can anyone provide me the Real time Scenarios of Reference Qualifiers(Both Advanced & Dynamic Reference Qualifier?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi, @ Vaishnavi Lathkar, Can you provide Real-Time Examples of Reference Qualifiers (Advanced & Dynamic)?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@teeparti tarun Happy to help you via email :). if you required anything you can ping me.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi, Vaishnavi Thanks for your help.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
hi,Vaishnavi Thanks for your help.