Versions Compared

Key

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

Данный класс предоставляет методы и свойства для взаимодействия с информацией о текущем пользователе. Доступ к информации о пользователе осуществляется быстрее при помощи запросов SimpleUser API, чем SimpleRecord.

Свойства

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

s_user.accessToken


Используйте данный методэто свойство, чтобы получить токен доступа текущего пользователя.

ВозвратВозвращаемое значение:

ТипОписание
String
Токен
Возвращает токен доступа текущего пользователя.

Пример:

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


Данный метод возвращает Используйте это свойство, чтобы вернуть имя текущего пользователя. 

ВозвратВозвращаемое значение:

ТипОписание
String
Имя
Возвращает имя текущего пользователя.

Пример:

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

s_user.

getPreference(name)

lastName


Используйте этот методданное свойство, чтобы получить указанные значения преференций для вернуть фамилию текущего пользователя. 

Note

Это асинхронный метод. Для оптимальной работы используйте ключевое слово  async/await, как показано в примере ниже.

Параметр:

НазваниеТипОбязательныйДефолтное значенеиnameString или ArrayДН

Возвращаемое значение

Возврат

:

theme
ТипОписание
ObjectЭтот метод возвращает promise object, содержащий определенные данные.
Info

Сторокой можно передать название одного предпочтения. В случае, если необходимо передать названия большего количества предпочтений, используйте тип Array, как показано ниже.

Пример:

Code BlocklanguagejstitlegetPreference (
Eclipse
String
type)linenumberstrue
Возвращает фамилию текущего пользователя.

Пример:

const getMyPreference = 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 the full name (first and last names) of the current user (see the First name and Last Name field values).

Возврат:

ТипОписаниеStringИмя и фамилия текущего пользователя

s_user.lastName

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

Return:

TypeDescriptionStringThe last name of the current user.

Code Block
languagejs
themeEclipse
titles_user.lastName
linenumberstrue
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 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):

NameTypeMandatoryDefault ValuenameStringYNvalueStringYN

Return:

TypeDescriptionObjectThis method returns a promise object containing specific data.

userID


Используйте данное свойство, чтобы получить ID текущего пользователя.

Возвращаемое значение:

ТипОписание
StringВозвращает значение ID текущего пользователя.

Пример:

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 ID of the current user.

Return:

TypeDescriptionStringThe 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

Use this method to get the 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:

TypeDescription

Используйте данное свойство, чтобы получить объект с данными о текущем пользователе, такими как имя, фамилия, значение ID и другими. 

Возвращаемое значение:

ТипОписание
ObjectВозвращает объект с информацией о пользователе.

Пример:

SimpleRecord objectAn object containing user information.

Code Block
languagejs
themeEclipse
titles_user.user
linenumberstrue
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 to get the Login Используйте данное свойство, чтобы получить логин (username) of the current user (for exampleтекущего пользователя (например, helpdesk.agent).

ReturnВозвращаемое значение:

Type
Тип
Description
Описание
String
The username of the current user.
Возвращает логин текущего пользователя.

Пример:

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

Методы

s_user.getFullName()


Используйте этот метод, чтобы получить полное имя текущего пользователя (значения полей Имя и Фамилия).

Возвращаемое значение:

ТипОписание
StringМетод возвращает имя и фамилию текущего пользователя.

s_user.getPreference(name)


Используйте этот метод, чтобы получить указанные значения настроек для текущего пользователя. 

Note

Метод является асинхронным. Для оптимальной работы используйте ключевое словоawait,как в примере ниже.

Параметр:

НазваниеТипОбязательныйЗначение по умолчанию
nameArray of StringsДаНет

Возвращаемое значение:

ТипОписание
ObjectМетод возвращает объект Promise, содержащий массив строк.


Info

Строкой можно передать название только одной пользовательской настройки. Для того чтобы передать названия большего количества настроек, используйте тип Array, как показано ниже.

Пример:

Code Block
languagejs
themeEclipse
titles_user.getFullName(getPreference (String type)
linenumberstrue
const commentValue getMyPreference = async () => `${{
    const response = await s_user.getFullNamegetPreference('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.setPreference(name, value)


Используйте данный метод, чтобы установить значение указанной настройки для текущего пользователя. Для того чтобы получить ранее заданное значение настройки, используйте метод s_user.getPreference(name).

Note

Метод является асинхронным. Для оптимальной работы используйте ключевое словоawait,как в примере ниже.

Параметры:

НазваниеТипОбязательныйЗначение по умолчанию
nameStringДаНет
valueStringДаНет

Возвращаемое значение:

ТипОписание
ObjectМетод возвращает объект Promise, содержащий данные.

Пример:

Code Block
languagejs
themeEclipse
titlesetPreference
linenumberstrue
const setMyPreference = async () => {
    const response = await s_user.setPreference('menu.tab', 1);
};
}: "${s_form.getValue('comment')}"`;
s_form.setValue('additional_comment', commentValue);


Table of Contents
absoluteUrltrue
classfixedPosition
printablefalse