logo

NJP

Real-time Cases with Glide User

Import · Jun 13, 2022 · article

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);

  1. Working with lastName () method

Display current user Last Name

alert (g_user. LastName);

  1. Working with fullName () method

Display current user Full Name

alert (g_user. fullName);

  1. Working with userID () method

Display current 32-digit user ID

alert (g_user. userID);

  1. Working with hasRole () method

Display true if the current user has the specified role

alert (g_user.hasRole ('admin'));

  1. Working with hasRoleExactly () method

Display true only if the current user has the specified role.

alert (g_user.hasRoleExactly('itil'));

  1. 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'));

  1. Working with hasRoles () method

Returns true if the current user has any role.

alert (g_user.hasRoles ('itil, admin'));

  1. Working with userName () method

Return current logged in user name

alert ('User Name is' + g_user.userName);

  1. 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

  1. Navigate to System Definition
  2. Open Scripts – Background Application
  3. 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

View original source

https://www.servicenow.com/community/developer-articles/real-time-cases-with-glide-user/ta-p/2298300