# 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FtP5r1lBZb3lqvJHP6xNS%2Ftempsnip.png?alt=media&#x26;token=83d680e3-0671-43a9-badf-c4b43eb68f9a" 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**](https://help.flochat.ai/flow-builder/steps/json-operation).

### 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2F38J2sRjE5cSSjdLHcfuS%2Fvariable2.d9eebed4.png?alt=media&#x26;token=70fa9cc3-eb18-4ece-83f4-e8b4d71c88e6" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FPSG7SqqwknVPmWhRm8Gg%2Fdownload%20(60).png?alt=media&#x26;token=e050f62c-3859-48c7-b3a3-0e2eaaa22fe5" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FXfSKszTDIbvADTI0Edqw%2FCapture.PNG?alt=media&#x26;token=bbc027f9-381f-4178-a166-21917b11b8ec" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FHu1llaXAPjgjrROX3WZk%2FCapture.PNG?alt=media&#x26;token=81585742-fb94-4a74-a15e-071f22494be1" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FJeV6bDOpwZ8On1GMBtct%2FCapture.PNG?alt=media&#x26;token=85c2d7ee-f474-4431-ac19-25ad9c328ec1" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FIRI1gwORq9l6vhrcTKj0%2FCapture.PNG?alt=media&#x26;token=1bb61b80-2e11-494d-8bff-ef57360477c8" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FUEPNziA6Ykrzvdvs44CB%2FCapture.PNG?alt=media&#x26;token=602888d4-add9-4db7-890c-793ee73ec91d" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FoQxb6uvoSJeB29ekKOQ5%2FCapture.PNG?alt=media&#x26;token=5554df1b-f497-4b9e-bf22-67177da824c9" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FHHi4B6JIXLtcjO6Dqke0%2FCapture.PNG?alt=media&#x26;token=331f05da-e2a3-47a9-b07b-fcb383b45878" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FybDeinLnPvrkMvA8zvsv%2FCapture.PNG?alt=media&#x26;token=995af3b2-f2cc-4fb6-857a-e77f6cbb7da9" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2F40FkPouE10gI7sZx2YSP%2Fdownload%20(61).png?alt=media&#x26;token=26dd0893-4923-44f2-8510-58a002e22d07" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2F1vMT7DAPXqwqCQP63oK5%2Fdownload%20(62).png?alt=media&#x26;token=ae988477-89c9-4bec-9a31-7e2be3269a02" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2F6s7TkL1gYW5HW8JtDIXS%2Fvariable16.f1b406f2.png?alt=media&#x26;token=1c0b680f-bfdd-4765-9e2c-7c6b3b768c23" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FKJXAZtVz7PHRQoBLqYQv%2Fdownload%20(63).png?alt=media&#x26;token=16a83432-4c6f-49d2-b169-525944051b4d" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FGet3vZA5m1KrpxYvQuKC%2Fdownload%20(64).png?alt=media&#x26;token=eaf67399-bf7f-4669-9b00-84e7c6ab57e9" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2F8pPGLWs6u4Yl3TQJ0wMW%2Fvariable19.ef7184e3.png?alt=media&#x26;token=53dc191a-e7df-4291-9527-9081631d7b12" 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="https://2836971782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRaLazqQDW4JMiGe2iyKg%2Fuploads%2FRRninpuGgTA3t1hzYTHD%2Fdownload%20(65).png?alt=media&#x26;token=6762d5c9-aa03-422f-80a1-c50bd20538cf" alt=""><figcaption></figcaption></figure>
