This class provides methods returning and properties for operating information about the current user and user prerequisites. SimpleUser API is faster than SimpleRecord queries in terms of accessing user information.
Propereties
s_user.accessToken
Use this method class property to get an access token of the current user.
Return:
An Returns an access token of the current user. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_user.accessToken |
---|
linenumbers | true |
---|
|
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 method property to get the first name of the current user.
Return:
The Returns the first name of the current user. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_user.firstName |
---|
linenumbers | true |
---|
|
console.log(s_user.firstName);
//John |
s_user.
getPreference(name)This method allows getting the specified preference value for the current user.
Note |
---|
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. |
lastName
Use this property to get the last name of the current user
Info |
---|
It is possible to pass a single preference name as a string. But if you need to pass more than one preference names, use the Array type (as shown in code examples below). |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getPreference (String type) |
---|
linenumbers | true |
---|
|
const getMyPreference = async () => {
const response = await s_user.getPreference('preference_name');
}; |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getPreference (Array type) |
---|
linenumbers | true |
---|
|
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:
The first and Returns the last name of the current user. |
s_user.lastName
Use this method to get the last name of the current user.
Return:
Type | Description |
---|
String | The last name of the current user.Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_user.lastName |
---|
linenumbers | true |
---|
|
console.log(s_user.lastName);
//Doe |
s_user.setPreference(name, value)
This method allows defining a value to the specified preference for the current user. To get a value of a preference previously set, use the s_user.
getPreference(name) method. Note |
---|
Note that this method is asynchronous; for better performing, use the async/await keyword as 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:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setPreference |
---|
linenumbers | true |
---|
|
const setMyPreference = async () => {
const response = await s_user.setPreference('menu.tab', 1);
};
// Promise {<pending>}
// [[PromiseState]]: "fulfilled"
// [[PromiseResult]]: Object |
s_user.userID
Use this method property to get the ID of the current user.
Return:
The sys_id Returns the ID value for the current user. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_user.userID |
---|
linenumbers | true |
---|
|
const currentCaller = new SimpleRecord(s_user.user.essence);
currentCaller.get(s_user.userID, ()=> {
s_form.setValue('email', currentCaller.email);
}); |
s_user.user
Use this method to get This property stores an object with the user data of the current user, such as first name, last name, sys_id ID value, and so on. The method returns a JSON-formatted SimpleRecord object.other.
Return:
SimpleRecord objectAn containing that contains user information. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | 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 method property to get the Login login (username) of the current user (for example, helpdesk.agent).
Return:
The Returns the username of the current user. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_user.userName |
---|
linenumbers | true |
---|
|
console.log(s_user.userName);
//"admin" |
Methods
s_user.getFullName()
Use this method to get the full name of the current user (the values of the First name and Last name fields).
Return:
Type | Description |
---|
String | This method returns the first and the last name of the current user. |
s_user.getPreference(name)
Use this method to get the specified preference values for the current user.
Note |
---|
Note that this method is asynchronous; for better performance, use the await keyword, as in the code example below. |
Parameter(s):
Name | Type | Mandatory | Default value |
---|
name | Array of Strings | Y | N |
Return:
Type | Description |
---|
Object | This method returns a Promise object that contains specific data. |
Info |
---|
It is possible to pass a single preference name as a string. To pass more than one preference names, use theArray type, as shown in the code example below. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_user.getFullName(getPreference (String type) |
---|
linenumbers | true |
---|
|
const commentValuegetMyPreference = async () => `${{
const response = await s_user.getFullNamegetPreference('preference_name');
}; |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getPreference (Array type) |
---|
linenumbers | true |
---|
|
const getMyPreference = async () => {
const response = await s_user.getPreference(['preference_name', 'preference2_name']);
}; |
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 previously set preference, use the s_user.getPreference(name) method.
Note |
---|
Note that this method is asynchronous; for better performance, use the await keyword, as shown in the code example below. |
Parameters:
Name | Type | Mandatory | Default value |
---|
name | String | Y | N |
value | String | Y | N |
Return:
Type | Description |
---|
Object | This method returns a Promise object that contains specific data. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setPreference |
---|
linenumbers | true |
---|
|
const setMyPreference = async () => {
const response = await s_user.setPreference('menu.tab', 1);
}}: "${s_form.getValue('comment')}"`;
s_form.setValue('additional_comment', commentValue); |