This server-side class allows to get information about the current user and his prerequisites, for example, assigned roles and preferences.
getContext()
This method allows to get user information given the context (whether this is the system user or an employee having additional attributes against regular users).
Return:
Type
Description
SimpleRecord object
This method returns an object containing user information.
Example:
getContext
const record = new SimpleUser();
let user = record.getContext(); //user or employee attributes
ss.info(record.hasRole('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 for this user? " + record.getPreference('menu.pin')); // -1 / 0 / 1
record.setPreference('New user preference', 'Menu pinning');
ss.info("Real preference value: " + record.getPreference('menu.pin')); // Menu pinning
ss.info("Non-existing preference value: " + record.getPreference('Non-existing preference value')); //null
ss.info(user.username); //admin
getID()
This method gets the current user' ID.
Return:
Type
Description
String
Current user ID.
getID
const record = new SimpleUser();
ss.info(record.getID());
getPreference(preferenceName)
This method allows to get a value of the specified User Preference for the current user.
Parameter(s):
Name
Type
Mandatory
Default Value
preferenceName
String
Y
N
Return:
Type
Description
String
This method returns the specified preference value for the current user. If the specified preference does not exist, it returns 'null'.
getPreference
const record = new SimpleUser();
ss.info("Is the navigator menu pinned for this user? " + record.getPreference('menu.pin')); // -1 / 0 / 1
hasRole(role)
This method allows to find out whether the current user is granted with a specified role or not.
Parameter(s):
Name
Type
Mandatory
Default Value
role
String
Y
N
Return:
Type
Description
Boolean
This method approves or disproves an assumption whether a specified user is granted with a specified role.
hasRole
const record = new SimpleUser();
ss.info("Does this user have the security admin role? " + record.hasRole('security_admin')); // true | false
setPreference(preferenceName, value)
This method allow to set a value for an existing or newly created preference for the current user.
Parameter(s):
Name
Type
Mandatory
Default Value
preferenceName
String
Y
N
value
String
Y
N
Return:
Type
Description
Void
This method does not return a value.
setPreference
const record = new SimpleUser();
record.setPreference('menu.pin', '1');
ss.info(record.getPreference('menu.pin')); // 1