You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

This class provides methods for operating information about the current user. SimpleUser API is faster than SimpleRecord queries in terms of accessing user information.

s_user.accessToken


Use this class property to get an access token of the current user.


Return:

TypeDescription
StringAn access token of the current user.
s_user.accessToken
const url = new URL(`${API_BASE_URL}/export/json/${s_list.getTablesName()[0]}`);
url.searchParams.set('access-token', s_user.accessToken);
url.searchParams.set('condition', s_list.getQuery());
window.open(url, "_blank");

s_user.firstName


Use this property to get the first name of the current user.


Return:

TypeDescription
StringThe first name of the current user.


s_user.firstName
console.log(s_user.firstName);
//John


s_user.getPreference(name)


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

Note that this method is asynchronous; for better performing, use the async/await keyword like shown in the code example below.


Parameter(s):

NameTypeMandatoryDefault Value
nameString or ArrayYN

Return:

TypeDescription
ObjectThis method returns a promise object containing specific data.

It is possible to pass a single preference name as a string. To pass more than one preference names, use the Array type, as shown in code examples below.

Example:

getPreference (String type)
const getMyPreference = async () => {
    const response = await s_user.getPreference('preference_name');
};
getPreference (Array type)
const getMyPreference = async () => {
    const response = await s_user.getPreference(['preference_name', 'preference2_name']);
};

s_user.getFullName()


Use this method to get the full name (first and last names) of the current user (see the First name and Last Name field values).


Return:

TypeDescription
StringThe first and the last name of the current user.

s_user.lastName


Use this method to get the last name of the current user.


Return:

TypeDescription
StringThe last name of the current user.


s_user.lastName
console.log(s_user.lastName);
//Doe

s_user.setPreference(name, value)


Use this method to define a value to the specified preference for the current user. To get a value of a preference set previously, use the s_user.getPreference(name) method.


Note that this method is asynchronous; for better performing, use the async/await keyword as shown in the code example below.


Parameters:

NameTypeMandatoryDefault Value
nameStringYN
valueStringYN


Return:

TypeDescription
ObjectThis method returns a promise object containing specific data.


Example:

setPreference
const setMyPreference = async () => {
    const response = await s_user.setPreference('menu.tab', 1);
};

s_user.userID


Use this method to get the ID of the current user.


Return:

TypeDescription
StringThe sys_id value for the current user.


s_user.userID
const currentCaller = new SimpleRecord(s_user.user.essence);
currentCaller.get(s_user.userID, ()=> {
  s_form.setValue('email', currentCaller.email);
});

s_user.user


This property stores an object with the user data of the current user, such as first name, last name, sys_id value, and other. 


Return:

TypeDescription
ObjectAn object containing user information.


s_user.user
console.log(JSON.stringify(s_user.user, null, 2));
/*"{
  "sys_id": "155931135900000001",
  "first_name": "Admin",
  "last_name": "Admin",
  "username": "admin",
  "essence": "user",
  "timezone": "Europe/Moscow",
  "language": "en",
  "photo_path": null,
  "elevate_access": -1,
  "version": "1.3.6",
  "dictionary": {...},
  "impersonate_state": null
}"*/

s_user.userName


Use this property to get the login (username) of the current user (for example, helpdesk.agent).


Return:

TypeDescription
StringThe username of the current user.


Example:

s_user.userName
console.log(s_user.userName);
//"admin"
s_user.getFullName()
const commentValue = `${s_user.getFullName()}: "${s_form.getValue('comment')}"`;
s_form.setValue('additional_comment', commentValue);

  • No labels