This server-side class allows getting information about the current user and his or her prerequisites. For example, the assigned roles and preferences.

getAccessToken()


This method returns an access token of the current user within the current session.

In the following cases, it returns an empty string:

  • calling this method within any scheduled functionality (for example, Scheduled Script),
  • calling this method by any other functionality without any direct user actions and collateral client-side requests.


Return:

TypeDescription
String

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


Example:

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


getContext()


This method allows getting information about the current user given the context (whether this is the system user or an employee having additional attributes against regular users).


Return:

Type

Description

SimpleRecord objectThis method returns an object containing the current user information.

Example:

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

getID()


This method gets the current user ID.


Return:

TypeDescription
StringCurrent user ID.


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


getPreference(preferenceName)


This method allows getting a 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'.


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


hasRole(role)


Use this method to find out whether the current user has a specified role. It always returns 'true' if the current user has the admin role.


Parameter(s):

NameTypeMandatoryDefault Value
roleStringYN


Return:

TypeDescription
Boolean

This method returns 'true' if the user has a specified role; otherwise, it returns 'false'.


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


setPreference(preferenceName, value)


This method allows setting a value for User Preference for the current user. 

The system creates a preference with the given name for the current user if such a preference did not exist before.


The value attribute must be shorter than 255 symbols.


Parameter(s):

NameTypeMandatoryDefault Value
preferenceNameStringYN
valueStringYN


Return:

TypeDescription
VoidThis method does not return a value.


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