# Use formulas and functions in the set variable value node

In the Set Variable Value node, you can specify not only simple formulas but also various functions as variable values. This enables flexible and powerful data processing.

#### How to use <a href="#pdf-page-5e03eb60574be6f41acd48475cde0e59e2277b72-how-to-use" id="pdf-page-5e03eb60574be6f41acd48475cde0e59e2277b72-how-to-use"></a>

**1. Create the Set Variable Value node**

* Within the workflow **Set Variable Value node**Add.

**2. Add a variable**

* In the node's settings screen **Add variable** click the button.

**3. Specify the target variable**

* For the added variable's **Target variable**Specify.

**4. Select formula mode**

* Choose the method for setting the variable value as **Formula**.

**5. Enter the formula**

* **Formula to be assigned** Enter the desired formula in the field.

<figure><img src="https://2300099500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FP12tuGvLWO89lcuqjaYH%2Fuploads%2FPWcJJSROTgRJQrVc1GAw%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202026-02-26%20%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB%2011.05.30.png?alt=media&#x26;token=bcc3042b-997e-4474-9798-80104e2aa10a" alt=""><figcaption></figcaption></figure>

As shown in the example above, formulas can include variables. The available operations and functions are as follows.

### Basic operations <a href="#pdf-page-5e03eb60574be6f41acd48475cde0e59e2277b72-basic-calculations" id="pdf-page-5e03eb60574be6f41acd48475cde0e59e2277b72-basic-calculations"></a>

1. **Arithmetic operators**
   * Addition: `+`
   * Subtraction: `-`
   * Multiplication: `*`
   * Division: `/`
   * Parentheses can be used: `( )`
2. **Remainder operation**
   * Operator: `%`
   * Example:
     * `100 % 2 = 0`
     * `100 % 8 = 4`
3. **Exponentiation operation**
   * Operator: `**`
   * Example:
     * `100 ** 2 = 10,000`

### Functions <a href="#pdf-page-5e03eb60574be6f41acd48475cde0e59e2277b72-basic-functions" id="pdf-page-5e03eb60574be6f41acd48475cde0e59e2277b72-basic-functions"></a>

All functions use the `function_name(value)` format.

1. **Type conversion**
   * `to_number(value)`
     * Converts a string to a number.
     * Example: `to_number('4') = 4`
   * `to_string(value)`
     * Converts a number to a string.
     * Example: `to_string(7) = '7'`
   * `to_boolean(value)`
     * Converts a value to a boolean (`True`/`False`).
     * Example: `to_boolean(1) = True`
2. **String functions**
   * `length(value)`
     * Returns the length of a string.
     * Example: `length('abcde') = 5`
3. **Math functions**
   * `abs(value)`
     * Returns the absolute value.
     * Example: `abs(-5) = 5`
   * Trigonometric functions:
     * `sin(value)`, `cos(value)`, `tan(value)`
     * Example: `tan(90) = 1`
   * Rounding-related functions:
     * `ceil(value)` (ceiling)
     * `floor(value)` (floor)
     * `round(value)` (round)
     * Example: `floor(2.1) = 2`
4. **Random functions**
   * `random()`
     * Returns a random number between 0 and 1.
     * Example: `random() = 0.5423`
   * `random_int(min, max)`
     * `min`and `max` Returns a random integer between them.
     * Example: `random_int(-1, 2) = -1, 0, 1, or 2`
5. **Time-related functions**
   * `unix_timestamp()`
     * Returns the current time as a Unix timestamp.
     * Example: `unix_timestamp() = 1601672447`

***

### Advanced functions <a href="#pdf-page-5e03eb60574be6f41acd48475cde0e59e2277b72-advanced-functions" id="pdf-page-5e03eb60574be6f41acd48475cde0e59e2277b72-advanced-functions"></a>

Advanced functions are mainly used to handle JSON data and lists of strings. When using them, you must keep data formats consistent, and if using strings as values, be sure to enclose them in quotes (' ').

**1. dict**

* **Description**: Creates JSON-formatted data using the given key-value pairs. If the same key already exists, its value is overwritten.
* **Format**: `dict(key1, value1, key2, value2, …)`
* **Result**: JSON format
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # When the @NAME variable has the value 'Allganize':
  dict('Name', @NAME, 'Email', 'test@allganize.ai')  
  # Result: { 'Name': 'Allganize', 'Email': 'test@allganize.ai' }
  ```

***

**2. dict\_set**

* **Description**: Adds new key-value pairs to existing JSON data. If the same key exists, its value is overwritten.
* **Format**: `dict_set(@JSON_variable, key1, value1, key2, value2, …)`
* **Result**: JSON format
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # When @JSON_VAR variable is { 'Name': 'Allganize' }:
  dict_set(@JSON_VAR, 'Email', 'test@allganize.ai')  
  # Result: { 'Name': 'Allganize', 'Email': 'test@allganize.ai' }
  ```

***

**3. dict\_del**

* **Description**: Removes a specific key from JSON data.
* **Format**: `dict_del(@JSON_variable, key)`
* **Result**: JSON format
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # When @JSON_VAR variable is { 'Name': 'Allganize', 'Email': 'test@allganize.ai' }:
  dict_del(@JSON_VAR, 'Email')  
  # Result: { 'Name': 'Allganize' }
  ```

***

**4. dict\_update**

* **Description**: Merges two JSON objects. If the same key exists, the value from the latter JSON is used.
* **Format**: `dict_update(@JSON_variable1, @JSON_variable2)`
* **Result**: JSON format
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @JSON_VAR = { 'Name': 'Allganize', 'Email': 'test@allganize.ai' }
  # @JSON_VAR2 = { 'Name': 'Alli', 'Type': 'AnswerBot' }
  dict_update(@JSON_VAR, @JSON_VAR2)  
  # Result: { 'Name': 'Alli', 'Email': 'test@allganize.ai', 'Type': 'AnswerBot' }
  ```

***

**5. json\_loads**

* **Description**: Converts JSON data written as a string into a JSON-type variable.
* **Format**: `json_loads('JSON_string')`
* **Result**: JSON format
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  #json_loads('{ "Name": "Alli", "Email": "test@allganize.ai" }')  
  # Result: { 'Name': 'Alli', 'Email': 'test@allganize.ai' }
  ```

***

**6. json\_dumps**

* **Description**: Converts JSON data into string format.
* **Format**: `json_dumps(@JSON_variable)`
* **Result**: String format
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @JSON_VAR = { 'Name': 'Allganize', 'Email': 'test@allganize.ai' }
  json_dumps(@JSON_VAR)  
  # Result: '{ "Name": "Allganize", "Email": "test@allganize.ai" }'
  ```

***

**7. list**

* **Description**: Creates a list of strings using the given strings.
* **Format**: `list(string1, string2, …)`
* **Result**: List of strings
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  #list('Allganize', 'Test')  
  # Result: [ 'Allganize', 'Test' ]
  ```

**8. list\_append**

* **Description**: Adds new string values to an existing list of strings.
* **Format**: `list_append(@string_list_variable, string1, string2, …)`
* **Result**: List of strings
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR_LIST = ['Allganize', 'Test']
  list_append(@STR_LIST, "Alli")  
  # Result: ['Allganize', 'Test', 'Alli']
  ```

***

**9. list\_reverse**

* **Description**: Reverses the order of a string list variable.
* **Format**: `list_reverse(@string_list_variable)`
* **Result**: List of strings
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR_LIST = ['Allganize', 'Test']
  list_reverse(@STR_LIST)  
  # Result: ['Test', 'Allganize']
  ```

***

**10. get\_by\_json\_path**

* **Description**: Extracts the value at the specified path from a JSON variable.
* **Format**: `get_by_json_path(@JSON_variable, JSON_path)`
* **Result**: String
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @JSON_VAR = { 'Name': 'Allganize', 'Email': 'test@allganize.ai' }
  get_by_json_path(@JSON_VAR, '$.Email')  
  # Result: 'test@allganize.ai'
  ```

***

**11. storage\_set / storage\_get**

* **Description**: Stores or retrieves a specific variable value under a given key.
  * `Use storage_set`to store a value.
  * `Use storage_get`to retrieve a value. You can manage data by sharing key values across the entire project.
* **Format**:
  * Save: `storage_set('key', @variable)`
  * Retrieve: `storage_get('key')`
* **Result**: Same type as the stored variable
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # Saving
  storage_set('string_key', @string_variable)

  # Retrieving
  storage_get('string_key')  
  # Result: the stored string value
  ```

**12. contains**

* **Description**: Checks whether a specific string is included in a list of strings.
* **Format**: `contains(@string_list_variable, string)`
* **Result**: Boolean (`True` or `False`)
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR_LIST = ['Allganize', 'Test']
  contains(@STR_LIST, 'Allganize')  
  # Result: True
  ```

***

**13. append**

* **Description**: Adds a new string to a list of strings.
* **Format**: `append(@string_list_variable, string)`
* **Result**: List of strings
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR_LIST = ['Allganize', 'Test']
  append(@STR_LIST, 'Variable')  
  # Result: ['Allganize', 'Test', 'Variable']
  ```

***

**14. unique**

* **Description**: Removes duplicate values from a list of strings.
* **Format**: `unique(@string_list_variable)`
* **Result**: List of strings
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR_LIST = ['Allganize', 'Test', 'Test']
  unique(@STR_LIST)  
  # Result: ['Allganize', 'Test']
  ```

***

**15. urlencode**

* **Description**: Converts JSON format to URL-encoded form.
* **Format**: `urlencode(@JSON_variable)`
* **Result**: String
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @JSON_VAR = {'key': 'hello world!'}
  urlencode(@JSON_VAR)  
  # Result: 'key=hello+world%21'
  ```

***

**16. urldecode**

* **Description**: Converts a URL-encoded string to JSON format.
* **Format**: `urldecode(string)`
* **Result**: String or JSON
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR = 'key=hello+world%21'
  urldecode(@STR)  
  # Result: {'key': 'hello world!'}
  ```

***

**17. regex\_sub / regex\_isub**

* **Description**: Replaces parts of a string with another value using regular expressions.
  * `regex_sub`: Case-sensitive.
  * `regex_isub`: Case-insensitive.
* **Format**:
  * `regex_sub(regex_pattern, string1, string2)`
  * `regex_isub(regex_pattern, string1, string2)`
* **Result**: String
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR = 'ooAoO'
  regex_isub(r'o{2}', 'A', @STR)  
  # Result: 'AAA'
  ```

***

**18. date\_format**

* **Description**: Converts a date to the specified format using a format string.
* **Format**: `date_format(format_string_date, date)`
* **Result**: String
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @DATE = '2020-01-11'
  date_format(r'%Y-%m', @DATE)  
  # Result: '2020-01'
  ```

**20. date\_add**

* **Description**: Adds a number of days to the given date.
* **Format**: `date_add(date, number)`
* **Result**: Date
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @DATE = '2020-01-11'
  date_add(@DATE, 2)  
  # Result: '2020-01-13'
  ```

***

**21. today**

* **Description**: Returns today's date.
* **Format**: `today()`
* **Result**: Date or string
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # If today is 2021-04-15
  today()  
  # Result: '2021-04-15'
  ```

***

**22. first\_day\_of\_month**

* **Description**: Returns the first day of the current month.
* **Format**: `first_day_of_month()`
* **Result**: Date or string
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # If today is 2021-04-15
  first_day_of_month()  
  # Result: '2021-04-01'
  ```

***

**23. last\_day\_of\_month**

* **Description**: Returns the last day of the current month.
* **Format**: `last_day_of_month()`
* **Result**: Date or string
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # If today is 2021-04-15
  last_day_of_month()  
  # Result: '2021-04-30'
  ```

***

**24. find\_all / find\_iall**

* **Description**: Finds all values matching a regex pattern in the given string and returns them as a list.
  * `find_all`: Case-sensitive.
  * `find_iall`: Case-insensitive.
* **Format**:
  * `find_all(regex_pattern, string)`
  * `find_iall(regex_pattern, string)`
* **Result**: List of strings
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR = 'Type of the OS: Windows'
  find_iall(r'(windows|mac|linux)', @STR)  
  # Result: ['Windows']
  ```

***

**25. substr**

* **Description**: Returns the specified number of characters from the start of a string.
* **Format**: `substr(string, number)`
* **Result**: String
* **Example**:

  <a class="button secondary">Copy</a>

  ```
  # @STR = '3months'
  substr(@STR, 2)  
  # Result: '3m'
  ```
