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.
Use this method to get access token of the current user.
Return:
Type | Description |
---|---|
String | Access token of the current user. |
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"); |
Use this method to get the first name of the current user.
Return:
Type | Description |
---|---|
String | First name of the current user. |
console.log(s_user.firstName); //John |
This method allows to get the specified preference value for the current user.
Please note that this method is asynchronous; for better performing, use the async/await keyword like shown in the code example below. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
name | String or Array | Y | N |
Return:
Type | Description |
---|---|
Object | This method returns a promise object containing specific data. |
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). |
const getMyPreference = async () => { const response = await s_user.getPreference('preference_name'); }; |
const getMyPreference = async () => { const response = await s_user.getPreference(['preference_name', 'preference2_name']); }; |
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:
Type | Description |
---|---|
String | First and last name of the current user. |
Use this method to get the last name of the current user.
Return:
Type | Description |
---|---|
String | Last name of the current user. |
console.log(s_user.lastName); //Doe |
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.getPreference(name) method.
Please note that this method is asynchronous; for better performing, use the async/await keyword like shown in the code example below. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
name | String | Y | N |
value | String | Y | N |
Return:
Type | Description |
---|---|
Object | This method returns a promise object containing specific data. |
Example:
const setMyPreference = async () => { const response = await s_user.setPreference('menu.tab', 1); }; // Promise {<pending>} // [[PromiseState]]: "fulfilled" // [[PromiseResult]]: Object |
Use this method to get the ID of the current user.
Return:
Type | Description |
---|---|
String | The sys_id value for the current user. |
const currentCaller = new SimpleRecord(s_user.user.essence); currentCaller.get(s_user.userID, ()=> { s_form.setValue('email', currentCaller.email); }); |
Use this method to get user data of the current user, such as first name, last name, sys_id value, and so on. The method returns a JSON-formatted SimpleRecord object.
Return:
Type | Description |
---|---|
SimpleRecord object | Object containing user information |
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 }"*/ |
Use this method to get the Login (username) of the current user (for example, helpdesk.agent).
Return:
Type | Description |
---|---|
String | Username of the current user. |
console.log(s_user.userName); //"admin" |
const commentValue = `${s_user.getFullName()}: "${s_form.getValue('comment')}"`; s_form.setValue('additional_comment', commentValue); |