# 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, Rapidbott.</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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2Fsn4jIIJWuXQA5BJ5W0SL%2Ftempsnip.png?alt=media&#x26;token=ed3cb74b-5687-47ba-a1a8-95f2b739b0a2" 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://docs.rapidbott.com/help-center/flow-builder/steps/broken-reference).

### Clear Variable Value <a href="#clear-variable-value" id="clear-variable-value"></a>

This function allows the user to literally clear a value of a single custom field.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FPs10cDMia32KKdLGqm5E%2FUntitled.png?alt=media&#x26;token=7322cfc0-39e8-475c-b8c6-2c8cc4e59c2a" alt=""><figcaption></figcaption></figure>

You just have to choose a specific custom field you want to clear out.

### Clear Multiple Variable Value <a href="#clear-multiple-variable-value" id="clear-multiple-variable-value"></a>

This action allows the user to clear multiple custom field values.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FYlfEYMOwpuyleYdbCh07%2FUntitled.png?alt=media&#x26;token=1fdb5c61-d09e-4ae8-b506-5a0065928a9b" alt=""><figcaption></figcaption></figure>

Make sure to choose all custom fields whose values you want to clear out.

### Clear All Custom User Fields <a href="#clear-all-custom-user-fields" id="clear-all-custom-user-fields"></a>

If you are looking for a way to clear all custom field values of a user, use this action.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FohPERJdDQ4sBeadOdU9K%2FUntitled.png?alt=media&#x26;token=e63ce68e-644c-4731-b62c-464cffa09e9d" alt=""><figcaption></figcaption></figure>

### 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FhrOnw0lMP8YCGI3SG9Xr%2Fvariable2.d9eebed4.png?alt=media&#x26;token=bb21f7b3-345c-4316-a89b-dd164277160d" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FOh2x3iB0bYFPA2beCV0L%2Fdownload%20(60).png?alt=media&#x26;token=17d8aaae-dff7-4ecf-b0fc-2a09c54a4d91" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FHHbNuuW1qW2sjE11sSJ4%2FCapture.png?alt=media&#x26;token=b4545b64-1896-421b-aeb7-8d6a03821cd2" 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, Rapidbott!" | "Hello, Rapidbott!" |

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FdCtLUIutXZqtUMMEVQfi%2FCapture.png?alt=media&#x26;token=58f03385-33ef-4cb8-8c92-341c3aaf1474" 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, Rapidbott!" | "hi, rapidbott!" |
| to upper case | "Hi, Rapidbott!" | "HI, RAPIDBOTT!" |

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2Fixa1NgGaA4RKVN5gVsZ8%2FCapture.png?alt=media&#x26;token=1ff0ce00-62f7-4c8b-9376-331f4cefc720" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F6AKvSsIwWDJaREvmfJo5%2FCapture.png?alt=media&#x26;token=6e42b11d-fee4-44a9-83ba-616fbee1b93e" 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, Rapidbott!"     | "Hi%2C%20Rapidbott!" |
| decode | "Hi%2C%20Rapidbott!" | "Hi, Rapidbott!"     |

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F2VBNAqvG0XEIXFzb70FZ%2FCapture.png?alt=media&#x26;token=2a3336ba-ae33-4fb0-b825-25a650172754" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FA3jbr55jqrzCkCN5cDlG%2FCapture.png?alt=media&#x26;token=e850a7bf-1f1c-44ac-93a3-c4bee8ecdd91" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FOiuMTxhPnjEB2UxeMBdT%2FCapture.png?alt=media&#x26;token=99f3e626-92bc-483c-a636-5515880286af" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FhQBZahkvzHBd71TFObDl%2FCapture.png?alt=media&#x26;token=aca80bd8-023a-4337-b71a-285215ec534e" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FTKmaUHpJLvDeJHpYkdIK%2Fdownload%20(61).png?alt=media&#x26;token=8fb571bd-6c52-4c6e-af13-bcdddfbff6df" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F9vsKjBUuef0lLwgruArv%2Fdownload%20(62).png?alt=media&#x26;token=83a7427a-e7c0-4102-9f94-c9b8ff11e83f" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F7tcId1nOrGWIjJ8Sexsl%2Fvariable16.f1b406f2.png?alt=media&#x26;token=b6862263-fd08-464e-a2ff-ec00d4ed76b8" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FoCKvRwA5I0M4bFDreeRZ%2Fdownload%20(63).png?alt=media&#x26;token=2248cdf9-a656-42cb-afbc-1327fc5f59da" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FwIRJZ1ZDtkykj0vFhvKj%2Fdownload%20(64).png?alt=media&#x26;token=d353c6b6-cb21-410f-bb18-9726de214391" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FpsLqCYtjFr8eRfj9XPrI%2Fvariable19.ef7184e3.png?alt=media&#x26;token=464772bf-b47f-4cb9-8406-e31eb52af9b6" 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://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FlOMuKpXkpboUi7TCqqMe%2Fimage.png?alt=media&#x26;token=422b7130-f36a-49d3-94ad-6d6e5f52dfd6" alt=""><figcaption></figcaption></figure>
