> For the complete documentation index, see [llms.txt](https://help.flochat.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.flochat.ai/flow-builder/steps/variable-operation.md).

# Variable Operation

Built-in operations for variable modification.

There are 6 types of variable:

<table><thead><tr><th width="145">Type</th><th>Storage</th><th>Example</th><th>Operation</th></tr></thead><tbody><tr><td>Text</td><td>letters, words, sentences...</td><td>Hi, Flochat.</td><td>cutting, change case, encode, decode...</td></tr><tr><td>Number</td><td>number</td><td>123.45</td><td>+ - x ÷, mod, power, log, root, round...</td></tr><tr><td>Boolean</td><td>either "yes" or "no"</td><td>yes</td><td>assign</td></tr><tr><td>Date</td><td>date</td><td>2021-03-30</td><td>format, add months/weeks/days</td></tr><tr><td>DateTime</td><td>date and time</td><td>2021-03-30 16:52:00</td><td>format, add months/weeks/days/hours/minutes</td></tr><tr><td>JSON</td><td>a series of variables</td><td>{"name":"jack", "age":"10"}</td><td>load, get, update, remove, count, sum, average, sort, shuffle, reverse...</td></tr></tbody></table>

Click "Basic Actions" in the Action step and here are the "Set Variable Value" and "Clear Variable Value".

<figure><img src="/files/YCxDfP76ypQ6bjac3Zg9" alt=""><figcaption></figcaption></figure>

### Clear Custom Field / Clear JSON <a href="#clear-custom-field-clear-json" id="clear-custom-field-clear-json"></a>

To clear text, number, boolean, date, datetime variable, please use the **Clear Custom Field** action.

To clear JSON variable, please use the **Remove All Items** operation in the [**JSON Operation**](/flow-builder/steps/json-operation.md).

### Input value <a href="#input-value" id="input-value"></a>

"input value" operation is used to assign value to a variable. This operation works for any variable type.

{% hint style="info" %}
"input value" for text variable can be used to connect several text variables. See the below picture for where to put original value and operated value.
{% endhint %}

<figure><img src="/files/Q1ZXDreunTfUg8tiSHW8" alt=""><figcaption></figcaption></figure>

### Math Formula <a href="#math-formula" id="math-formula"></a>

![condition](https://i.imgur.com/sHDee6i.png)

With this operation, you can now do formula calculation directly in the Action Step - "Set Variable Value" and Condition Step - "Value".

Math operations and function supported:

+, -, \*, e, pi, PI, abs(), min(), max(), ceil(), floor(), log(), pow(), round(), sqrt(), sin(), cos(), tan()

{% hint style="info" %}
If the formula is invalid, the system will return 0 to number variable and empty to text variable.
{% endhint %}

## &#x20;Set Text Variable <a href="#set-text-variable" id="set-text-variable"></a>

#### Trim text <a href="#trim-text" id="trim-text"></a>

| Description                            | e.g. Before | e.g. After |
| -------------------------------------- | ----------- | ---------- |
| remove spaces before or after the text | " abc "     | "abc"      |

<figure><img src="/files/Z4aY4BuWy5X4cQQIXPTC" alt=""><figcaption></figcaption></figure>

### Sub string <a href="#sub-string" id="sub-string"></a>

| Description          | e.g. Before   | e.g. After |
| -------------------- | ------------- | ---------- |
| get part of the text | "Hi, Sendly!" | "Sendly"   |

<figure><img src="/files/X02EPgzs5yj3wNRxo567" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Index starts from 0. Every character counts including space and punctuation.
{% endhint %}

### Replace string / replace string case sensitive <a href="#replace-string-replace-string-case-sensitive" id="replace-string-replace-string-case-sensitive"></a>

| Description              | e.g. Before    | e.g. After        |
| ------------------------ | -------------- | ----------------- |
| replace part of the text | "Hi, Flochat!" | "Hello, Flochat!" |

<figure><img src="/files/BIl5DqLkKeHVL5Y0oP8P" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
In case sensitive situation, you have to put exactly "Hi" rather than "hi", "HI" or "hI".
{% endhint %}

### To lower / upper case <a href="#to-lower-upper-case" id="to-lower-upper-case"></a>

| Type          | e.g. Before    | e.g. After     |
| ------------- | -------------- | -------------- |
| to lower case | "Hi, Flochat!" | "hi, flochat!" |
| to upper case | "Hi, Flochat!" | "HI, FLOCHAT!" |

<figure><img src="/files/qcVB6dxDBjo89CSl4W1c" alt=""><figcaption></figcaption></figure>

### Generate random text <a href="#generate-random-text" id="generate-random-text"></a>

| Description | e.g. Before            | e.g. After             |
| ----------- | ---------------------- | ---------------------- |
| as the name | "code: XXXX-####-xxxx" | "code: UBWT-3657-lkzb" |

<figure><img src="/files/nlS1oZsHFAbW9iNEe4up" alt=""><figcaption></figcaption></figure>

This feature is useful when you need to generate one-time verification code or reference code.

### url encode / decode <a href="#url-encode-decode" id="url-encode-decode"></a>

| Type   | e.g. Before        | e.g. After         |
| ------ | ------------------ | ------------------ |
| encode | "Hi, Flochat!"     | "Hi%2C%20Flochat!" |
| decode | "Hi%2C%20Flochat!" | "Hi, Flochat!"     |

<figure><img src="/files/V68Ou9AKfUBHSeh1pnGl" alt=""><figcaption></figcaption></figure>

### Base64 encode / decode <a href="#base64-encode-decode" id="base64-encode-decode"></a>

| Description | e.g. Before        | e.g. After         |
| ----------- | ------------------ | ------------------ |
| encode      | "Hi, Sendly!"      | "SGksIFVDaGF0IQ==" |
| decode      | "SGksIFVDaGF0IQ==" | "Hi, Sendly!"      |

<figure><img src="/files/fcxXV9NxYF36DyhBqkVT" alt=""><figcaption></figcaption></figure>

### To URL friendly slug <a href="#to-url-friendly-slug" id="to-url-friendly-slug"></a>

| Description                                           | e.g. Before       | e.g. After       |
| ----------------------------------------------------- | ----------------- | ---------------- |
| replace spaces with hyphens and remove the rest signs | "it's a good day" | "its-a-good-day" |

<figure><img src="/files/Jxt51vcK4uW1HCfAYtTz" alt=""><figcaption></figcaption></figure>

#### Get text before/after ... <a href="#get-text-before-after" id="get-text-before-after"></a>

Description: get part of the text.

| Type                                       | e.g. Before                   | e.g. After              |
| ------------------------------------------ | ----------------------------- | ----------------------- |
| get text before another text               | name: Sendly, city: Melbourne | name                    |
| get text before last occur of another text | name: Sendly, city: Melbourne | name: Sendly, city      |
| get text after another text                | name: Sendly, city: Melbourne | Sendly, city: Melbourne |
| get text after last occur of another text  | name: Sendly, city: Melbourne | Melbourne               |

<figure><img src="/files/PVngWx9260vqM2XQIdTX" alt=""><figcaption></figcaption></figure>

## Set Number Variable <a href="#set-number-variable" id="set-number-variable"></a>

### Get text length <a href="#get-text-length" id="get-text-length"></a>

| Description | e.g. Before | e.g. After |
| ----------- | ----------- | ---------- |
| as the name | 500.59      | 6          |

<figure><img src="/files/7UGq8mZM0CbxWgh2g5wm" alt=""><figcaption></figcaption></figure>

### Generate random number <a href="#generate-random-number" id="generate-random-number"></a>

| Description | e.g. Before | e.g. After |
| ----------- | ----------- | ---------- |
| as the name | n/a         | 56         |

<figure><img src="/files/CL8J82Vr4InE81WL84oO" alt=""><figcaption></figcaption></figure>

### Add / subtract / multiply / divide / modulus / power / natural logarithm / square root <a href="#add-subtract-multiply-divide-modulus-power-natural-logarithm-square-root" id="add-subtract-multiply-divide-modulus-power-natural-logarithm-square-root"></a>

| Description | e.g. Before | e.g. After |
| ----------- | ----------- | ---------- |
| as the name | 7           | 8          |

<figure><img src="/files/WKk1a9EY4kn51VVtEOkR" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
in "natural logarithm", when you are calculating log2(8) = ? put 8 as "Value" and 2 as "Number".
{% endhint %}

### Round <a href="#round" id="round"></a>

| Description | e.g. Before | e.g. After |
| ----------- | ----------- | ---------- |
| as the name | 7.8693      | 7.87       |

<figure><img src="/files/J45aPHxJGHNjYsNPbtBM" alt=""><figcaption></figcaption></figure>

### Floor / ceil <a href="#floor-ceil" id="floor-ceil"></a>

Description: get approximate integer.

| Type  | e.g. Before | e.g. After |
| ----- | ----------- | ---------- |
| floor | 6.55        | 6          |
| ceil  | 6.55        | 7          |

<figure><img src="/files/W6hBUiBRnx1AywBWPH2S" alt=""><figcaption></figcaption></figure>

## Set DateTime Variable <a href="#set-datetime-variable" id="set-datetime-variable"></a>

### From formatted text <a href="#from-formatted-text" id="from-formatted-text"></a>

| Description                            | e.g. Before             | e.g. After          |
| -------------------------------------- | ----------------------- | ------------------- |
| get DataTime value from formatted text | 00:00:00 30th Aug, 2020 | 2020-08-30 00:00:00 |

<figure><img src="/files/AlQlrWuOPj14DFW3kWo5" alt=""><figcaption></figcaption></figure>

### Add minutes / hours / days / weeks / months <a href="#add-minutes-hours-days-weeks-months" id="add-minutes-hours-days-weeks-months"></a>

| Description | e.g. Before         | e.g. After          |
| ----------- | ------------------- | ------------------- |
| as the name | 2021-01-01 00:00:00 | 2021-01-01 00:01:00 |

<figure><img src="/files/D1NFVZAdbOK2VXI5ENqR" alt=""><figcaption></figcaption></figure>
