# Выполнить JavaScript

Функциональная команда позволяет выполнить JavaScript, например для установки значений глобальных переменных (переменных бота) или атрибутов лида.

Настроить команду *Выполнить JavaScript* можно, выбрав одноименный пункт **Выполнить JavaScript** из списка **Команд**:

![Список команд](https://1621485802-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lof4a3yX4z_pjUWqMhw%2F-M-ObQPmNFaxdDQJFVH9%2F-M-OcEOtCfv3eUf5TAxb%2F%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5.png?alt=media\&token=04216253-b1e6-4d5d-90b8-5bf8f6747eec)

В диалоговом окне, в поле **JavaScript** необходимо создать, синтаксически верно написанный, JavaScript.&#x20;

Нажать кнопку ***Создать***.

![Настройка свойств команды](https://1621485802-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lof4a3yX4z_pjUWqMhw%2F-M-ObQPmNFaxdDQJFVH9%2F-M-Odguhp_ZoDvb2zSUf%2F%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5.png?alt=media\&token=40c4c2e6-4db1-4245-a005-600b38c42e8c)

В редакторе скриптов появляется команда **Выполнить JavaScript**.

![Команда в редакторе скриптов](https://1621485802-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lof4a3yX4z_pjUWqMhw%2F-M-ObQPmNFaxdDQJFVH9%2F-M-Oef7iAIgbT1-c5XuS%2F%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5.png?alt=media\&token=cd5021d0-a245-4a3b-8499-574b83cc4b00)

#### Пример скрипта, для проверки и установки значения переменной бота

```
//bot.setAttr('globalVarName1', 'var 1 value');
//bot.getAttr('globalVarName1');

bot.setAttr('globalVarName2', bot.getAttr('globalVarName2') + ' Это вторая глобальная переменная');
```

#### Пример скрипта, для проверки и установки значения переменной лида

```
var currentVar1Value = lead.getAttr('LeadVar1');
var glueStr = 'lead variable value|';
var newValue = glueStr;

//if (lead.isAttrExist('LeadVar1')) {
//   newValue  = currentVar1Value  + glueStr;
//}

if (currentVar1Value  !== null) {
   newValue  = currentVar1Value  + glueStr;
}

lead.setAttr('LeadVar1', newValue);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://metabot.gitbook.io/documentation/komandy/vypolnit-javascript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
