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 prerequisites. SimpleUser API is faster than SimpleRecord queries in terms of accessing user informationДанный класс предоставляет методы, которые возвращают информацию о текущем пользователе. Доступ к информации о пользователе осуществляется быстрее при помощи запросов SimpleUser API, чем SimpleRecord.

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)


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

Note

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


Параметр:

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


Возврат:

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


Info

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


Пример:

Code Block
languagejs
themeEclipse
titlegetPreference (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.

Данный метод возвращает фамилию текущего пользователя.


Возврат:

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


Пример:

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 Value
nameStringYДNН
valueStringYДNН


ReturnВозврат:

TypeТипDescriptionОписание
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 ID of the current user.

Return:

TypeDescription

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


Возврат:

ТипОписание
StringЗначение sys_id текущего пользователя


Пример:

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

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

Данный метод позволяет получить данные о текущем пользователе, такие как имя, фамилия, значение sys_id и другие. Метод возвращает SimpleRecord объект в формате JSON.


Возврат:

ТипОписание
Объект SimpleRecordОбъект, содержащий информацию о пользователе.


Пример:

SimpleRecord objectAn object 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


Use this method to get the Login Данный метод позволяет получить логин (username) of the current user (for exampleтекущего пользователя (например, helpdesk.agent).


ReturnВозврат:

TypeТипDescriptionОписание
StringThe 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