Versions Compared

Key

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

This class provides methods returning information about the current user and user's prerequisites. Using the SimpleUser API allows you to access the user information quicker than using SimpleRecord queries.

s_user.accessToken


This Use this method returns to get access token of the current user.


Return:

TypeDescription
StringAccess token of the current user.


Code Block
languagejs
themeEclipse
titles_user.accessToken
linenumberstrue
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


Using Use this method , you can retrieve to get the first name of the current user.


Return:

TypeDescription
StringFirst name of the current user.


Code Block
languagejs
themeEclipse
titles_user.firstName
linenumberstrue
console.log(s_user.firstName);
//John


s_user.

getFullName

getPreference(name)

Using this method, you can retrieve full name (first and last names) of the current user (see the values of the fields "First name" and "Last Name").

This method allows to get the specified preference value for the current user.

Note

Please 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
StringFirst and last name of the current user
ObjectThis method returns a promise object containing specific data.


Info

It is allowed to pass a single preference name as a string. But if you need to pass more than one preference names, please use Array type (as shown in code examples below).


Code Block
languagejs
themeEclipse
titles_user.getFullName(getPreference (String type)
linenumberstrue
const commentValuegetMyPreference = `${s_user.getFullName()}: "${s_form.getValue('comment')}"`;
s_form.setValue('additional_comment', commentValue);

s_user.lastName

 async () => {
    const response = await s_user.getPreference('preference_name');
};


Code Block
languagejs
themeEclipse
titlegetPreference (Array type)
linenumberstrue
const getMyPreference = async () => {
    const response = await s_user.getPreference(['preference_name', 'preference2_name']);
};

s_user.getFullName()


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


Return:

TypeDescription
StringFirst and last name of the current user.


s_user.lastName


Use this method to get Using this method, you can retrieve the last name of the current user.


Return:

TypeDescription
StringLast name of the current user.


Code Block
languagejs
themeEclipse
titles_user.lastName
linenumberstrue
console.log(s_user.lastName);
//Doe

s_user.setPreference(name, value)


This method allows to define a value to specified preference for the current user. To get a value of a preference previously set, use the s_user

.userID

.getPreference(name) method.


Note

Please 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
nameStringYN
valueStringYN


Return:

TypeDescription
ObjectThis method returns a promise object containing specific data.


Example:

Code Block
languagejs
themeEclipse
titlesetPreference
linenumberstrue
const setMyPreference = async () => {
    const response = await s_user.setPreference('menu.tab', 1);
};
// Promise {<pending>}
// [[PromiseState]]: "fulfilled"
// [[PromiseResult]]: Object

s_user.userID


Use this method to get the

Using this method, you can retrieve the user ID of the current user.


Return:

TypeDescription
StringThe sys_id value for the current user.


Code Block
languagejs
themeEclipse
titles_user.userID
linenumberstrue
const currentCaller = new SimpleRecord(s_user.user.essence);
currentCaller.get(s_user.userID, ()=> {
  s_form.setValue('email', currentCaller.email);
});

s_user.user


Returns a SimpleRecord object containing Use this method to get user data of the current user, such  such as first name, last name, sys_id value, and so on, formatted as JSON.. The method returns a JSON-formatted SimpleRecord object.


Return:

TypeDescription
SimpleRecord objectObject containing user information


Code Block
languagejs
themeEclipse
titles_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


Using Use this method , you can retrieve the username to get the Login (username) of the current user (for example, helpdesk.agent).Please note that it does not return user's name, whether it be first name, or last name, or full name (for example, John, or Doe, or John Doe).


Return:

TypeDescription
StringID Username of the current user.


Code Block
languagejs
themeEclipse
titles_user.userName
linenumberstrue
console.log(s_user.userName);
//"admin"


Code Block
languagejs
titles_user.getFullName()
linenumberstrue
const commentValue = `${s_user.getFullName()}: "${s_form.getValue('comment')}"`;
s_form.setValue('additional_comment', commentValue);


Table of Contents
absoluteUrltrue
classfixedPosition
printablefalse