> For the complete documentation index, see [llms.txt](https://metabot.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://metabot.gitbook.io/documentation/komandy/vypolnit-javascript.md).

# Выполнить JavaScript

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

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

![Список команд](/files/-M-OcEOtCfv3eUf5TAxb)

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

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

![Настройка свойств команды](/files/-M-Odguhp_ZoDvb2zSUf)

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

![Команда в редакторе скриптов](/files/-M-Oef7iAIgbT1-c5XuS)

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

```
//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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
