Skip to main content
Version: 1.20.1

SimpleUser Server-Side

This server-side class provides methods that get information about the current user and their prerequisites, for example, the assigned roles or preferences.

getAccessToken()


Use this method to return an access token of the current user within the current session.

It returns an empty string in the following cases:

  • the method is called within any scheduled functionality (for example, a scheduled script).
  • the method is called by any other functionality without any direct user actions and side request on the client side.

Return:

TypeDescription
StringThe method returns the current user access token. If the user is not set, it returns an empty string.

Example:

getAccessToken()
const user = new SimpleUser();
ss.info(user.getAccessToken());
// Info: PV8wLSJWEJONyvF87aIQn2b--7EMEhy_

getContext()


Use this method to get the information about the current user in the given context. For example, check if a system user or employee has additional attributes compared to regular users.

Return:

TypeDescription
SimpleRecord objectThis method returns an object that contains the information about the current user.

Example:

getContext()
const user = new SimpleUser();
ss.info(user.getContext().username);
// Info: admin

getID()


Use this method to get the current user ID.

Return:

TypeDescription
StringThis method returns the current user ID.

Example:

getID()
const user = new SimpleUser();
ss.info(user.getID());
// Info: 155931135900000099

getPreference(preferenceName)


Use this method to get the value of the specified user preference for the current user.

Parameter(s):

NameTypeMandatoryDefault value
preferenceNameStringYN

Return:

TypeDescription
StringThis method returns the specified preference value for the current user. If the specified preference does not exist, it returns null.

Example:

getPreference()
const user = new SimpleUser();
ss.info(user.getPreference('application'));
// Info: 155931135900000002

hasRole(role)


Use this method to check if the current user has the specified role or the admin role. It always returns true if the current user has the admin role. When checking a role that has the Elevate privileges checkbox selected, the method returns false if the user with the admin role has not elevated to the specified one.

Parameter(s):

NameTypeMandatoryDefault value
roleStringYN

Return:

TypeDescription
BooleanThis method returns true if the user has a specified role or admin; otherwise, it returns false.

Example:

hasRole()
const user = new SimpleUser();
ss.info(user.hasRole('service_owner'));
// Info: false

setPreference(preferenceName, value)


Use this method to set a value for the user preference settings of the current user.

The system creates a preference with the specified name for the current user, if such a preference does not exist.

warning

The value parameter must be no longer than 255 symbols.

Parameter(s):

NameTypeMandatoryDefault value
preferenceNameStringYN
valueStringYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

setPreference()
const user = new SimpleUser();
user.setPreference('language', 'en');
ss.info(user.getPreference('language'));
// Info: en