Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This server-side class allows to get information about the current user and his prerequisites, for example, assigned roles and preferences.

getAccessToken()


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

In some cases it returns an empty string. These cases are:

  • 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


getContext()

Return:

SimpleRecord objectThis method returns the current attribute object
TypeDescription
String

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


Example:

Code Block
languagejs
themeEclipse
titlegetContextgetAccessToken
linenumberstrue
const recorduser = new SimpleUser();
let user = record.getContext(); //user or employee attributes
ss.info(recorduser.hasRolegetAccessToken('admin')); //true | false
ss.info("Does this user have the security admin role? " + record.hasRole('security_admin')); // true | false
ss.info("Is the navigator menu pinned? " + record.getPreference('menu.pin')); // -1 / 0 / 1
record.setPreference('New user preference', 'Menu pinning'); 
ss.info("New preference value: " + record.getPreference('New user preference')); //Menu pinning
ss.info("not existing preference: " + record.getPreference('non-existing preference')); //null
ss.info(user.username);  //admin

getID()

Info: PV8wLSJWEJONyvF87aIQn2b--7EMEhy_


getContext()


This method allows to get current user information 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:

Code Block
languagejs
themeEclipse
titlegetContext
linenumberstrue
const user = new SimpleUser();
ss.info(user.getContext().username); // Info: admin

getID()


This method gets the current user ID.


Return:

TypeDescription
StringCurrent user ID.


Code Block
languagejs
themeEclipse
titlegetID
linenumberstrue
const user = new SimpleUser();
ss.info(user.getID()); // Info: 155931135900000099


getPreference(preferenceName)


This method allows to get 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
'null'.


Code Block
languagejs
themeEclipse
titlegetPreference
linenumberstrue
const user = new SimpleUser();
ss.info(user.getPreference('application')); // Info: 155931135900000002


hasRole(role)


This method allows to find out whether the current user is granted with a specified role or not. It always returns true if the current user has the admin role.


Parameter(s):

NameTypeMandatoryDefault Value
roleStringYN


Return:

TypeDescription
Boolean

This method

approves or disproves an assumption whether a specified

returns 'true' if user is granted with a specified role; otherwise, it returns 'false'.


Code Block
languagejs
themeEclipse
titlehasRole
linenumberstrue
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 given name for the current user if such a preference did not exist before.


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.


Code Block
languagejs
themeEclipse
titlesetPreference
linenumberstrue
const user = new SimpleUser();
user.setPreference('language', 'en');
ss.info(user.getPreference('language')); // Info: en


Table of Contents
absoluteUrltrue
classfixedPosition
printablefalse