# Variable Operation

Built-in operations for variable modification.There are 6 types of variable:

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

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

<figure><img src="https://289455019-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."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.

<figure><img src="https://289455019-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>

conditionWith 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()If the formula is invalid, the system will return 0 to number variable and empty to text variable.

<figure><img src="https://i.imgur.com/sHDee6i.png" alt=""><figcaption></figcaption></figure>

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

**Trim text**

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

<figure><img src="https://289455019-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"   |

Index starts from 0. Every character counts including space and punctuation.

<figure><img src="https://289455019-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>

#### 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, Konversation!" | "Hello, Konversation!" |

In case sensitive situation, you have to put exactly "Hi" rather than "hi", "HI" or "hI".​

<figure><img src="https://289455019-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>

#### 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, Konversation!" | "hi, flochat!" |
| to upper case | "Hi, Konversation!" | "HI, FLOCHAT!" |

<figure><img src="https://289455019-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" |

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

<figure><img src="https://289455019-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>

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

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

<figure><img src="https://289455019-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://289455019-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://289455019-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 ...**

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://289455019-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://289455019-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://289455019-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          |

​in "natural logarithm", when you are calculating log2(8) = ? put 8 as "Value" and 2 as "Number".

<figure><img src="https://289455019-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>

#### 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://289455019-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://289455019-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://289455019-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://2396751579-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvtuqxyR50geqBaXbrxDh%2Fuploads%2FheF2C9SWg8HygDVHUjKU%2Fimage.png?alt=media&#x26;token=f2f7358f-f667-4380-9c92-ba3c65fc260a" alt=""><figcaption></figcaption></figure>
