Glide User

 

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

 

1. Working with firstName () method

Display current user First Name

alert (g_user.firstName);


 

2. Working with lastName () method

Display current user Last Name

alert (g_user. LastName);


 

3. Working with fullName () method

Display current user Full Name

alert (g_user. fullName);


 

4. Working with userID () method

Display current 32-digit user ID

alert (g_user. userID);


5. Working with hasRole () method

Display true if the current user has the specified role

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


 

6. Working with hasRoleExactly () method

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

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

 

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

 

8. Working with hasRoles () method

      Returns true if the current user has any role.

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

9. Working with userName () method

Return current logged in user name

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

 

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

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

 

Comments

Popular Posts