What is GlideUser

gs.getUser() is used pretty heavily to control access and other things
in Servicenow. I go over all the methods and properties of those below.

Method Scoped Global
getCompanyID Scoped Global
getDisplayName Scoped Global
getEmail Scoped Global
getFirstName Scoped Global
getID Scoped Global
getLastName Scoped Global
getName Scoped Global
getRoles Scoped Global
getUserRoles Scoped Global
hasRole Scoped Global
isMemberOf Scoped Global
getPreference Scoped
savePreference Scoped
getDomainDisplayValue Global
getManagerID Global
getMyGroups Global
getLanguage Global
getDepartmentID Global
getLocation Global
getCompanyRecord Global
getDomainID Global

Server

getCompanyID

Returns the current user's company sys_id.

 var currentUser = gs.getUser();
 gs.info(currentUser.getCompanyID());

getDisplayName

Returns the current user's display name.

 var currentUser = gs.getUser();
 gs.info(currentUser.getDisplayName());

getDomainDisplayValue

Returns the display value of the user's session domain.

Note: There is no workaround for scoped applications.

 var currentUser = gs.getUser();
 gs.info(currentUser.getDomainDisplayValue());

getEmail

Returns the user's email address.

 var currentUser = gs.getUser();
 gs.info(currentUser.getEmail());

getFirstName

Returns the user's first name.

 var currentUser = gs.getUser();
 gs.info(currentUser.getFirstName());

getID

Gets the sys_id of the current user.

 var currentUser = gs.getUser();
 gs.info(currentUser.getID());

getLastName

Returns the user's last name.

 var currentUser = gs.getUser();
 gs.info(currentUser.getLastName());

getName

Returns the user ID, or login name, of the current user.

 var currentUser = gs.getUser();
 gs.info(currentUser.getName());

getPreference

Gets the specified user preference value for the current user.

 var currentUser = gs.getUser();
 currentUser.savePreference(­'myPref','red');
 gs.info(currentUser.getPreference(­'myPref'));

getRoles

Returns a list of roles that includes explicitly granted roles,
inherited roles, and roles acquired by group membership.

 var currentUser = gs.getUser();
 gs.info(currentUser.getRoles());

getUserRoles

Returns the list of roles explicitly granted to the user.

Unlike the getRoles() method, this method does not return roles the user
inherits or roles acquired from group membership.

 var currentUser = gs.getUser();
 gs.info(currentUser.getUserRoles());

gs hasRole

Determines if the current user has the specified role.

 var currentUser = gs.getUser();
 gs.info(currentUser.hasRole('admin'));

isMemberOf

Determines if the current user is a member of the specified group.

NOTE: This only takes a text string of the name.

 var currentUser = gs.getUser();
 gs.info(currentUser.isMemberOf('Capacity Mgmt'));
 
 // I prefer to use the sys_id's so here's an example of that instead;
 var changeManagementGroup = 'a715cd759f2002002920bde8132e7018';
 var userObj = gs.getUser();
 var sys_user_grmember = new GlideRecord('sys_user_grmember');
 sys_user_grmember.addQuery('user', userObj.getID());
 sys_user_grmember.addQuery('group',changeManagementGroup);
 sys_user_grmember.setLimit(1);
 sys_user_grmember.query();
 gs.print(sys_user_grmember.getEncodedQuery());
 var isMemberOfChangeManagement = sys_user_grmember.hasNext();
 gs.print('isMemberOfChangeManagement: ' + isMemberOfChangeManagement);
 if (isMemberOfChangeManagement) {
  return true;
 }

savePreference

Saves a user preference value to the database.

 var currentUser = gs.getUser();
 currentUser.savePreference('myPref','red');
 gs.info(currentUser.getPreference('myPref'));

getMyGroups

Returns the list the user's groups.

 var currentUser = gs.getUser();
 gs.info(currentUser.getMyGroups());

getUserByID

Returns the user object by the user's id.

 var currentUser = gs.getUser();
 gs.info(currentUser.getUserByID('admin'));

getLanguage

Returns the user language.

 var currentUser = gs.getUser();
 gs.info(currentUser.getLanguage());

getDeparmentID

Returns undefined.

 var currentUser = gs.getUser();
 gs.print("this seems to fail: " + currentUser.getDeparmentID());
 var deptID = currentUser.getDepartmentID();
 gs.info("this seems to work: " + deptID);

getLocation

Returns empty string regardless of the user's "location" value.

 var currentUser = gs.getUser();
 gs.info(currentUser.getLocation());

getCompanyRecord

Returns GlideRecord to core_company record.

 var currentUser = gs.getUser();
 gs.info(currentUser.getCompanyRecord());
 gs.info(currentUser.getCompanyRecord().getTableName()); // core_company

getDomainID

Returns domain id or null.

 var currentUser = gs.getUser();
 gs.info(currentUser.getDomainID());