# Set Variable Value

Discover how Flexito OmniAI's powerful variable management features can streamline your data handling processes. Whether you're collecting user data, performing complex calculations, or managing text and numbers, these tools offer flexibility and precision. Learn how to efficiently set, modify, and clear variables to enhance your system's functionality.

- get text length
- generate random number
- add / subtract / multiply / divide / modulus / power / natural logarithm / square root
- round
- floor / ceil

- from formatted text
- add minutes / hours / days / weeks / months

## # Setting Variable Values

This feature lets you store values in a variable or custom field, which is particularly useful for gathering user data.

\## Types of Values When you select the set custom field action, you can choose which custom field needs its value updated.

You can input data directly or use another custom field as the value.

If you need to create a new custom field, simply enter the name and select the type of custom field you wish to create.

## # Variable Operations

Flexito OmniAI offers a range of built-in operations for modifying variables.

Flexito OmniAI recognises six types of variables:

| **Type** | **Storage** | **Example** | **Operation** |
| --- | --- | --- | --- |
| Text | letters, words, sentences... | Hi, Flexito OmniAI. | 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... |

To access "Set Variable Value" and "Clear Variable Value," click on "Basic Actions" in the Action step.

## ## Clearing Custom Fields and JSON

Use the Clear Custom Field action to clear text, number, boolean, date, or datetime variables.

To clear a JSON variable, use the Remove All Items operation within JSON Operation.

## ## Input Value

The "input value" operation assigns a value to a variable and is compatible with all variable types.

TIP: For text variables, "input value" can link multiple text variables. Refer to the image below to see where to place the original and operated values.

## ## Mathematical Formulas

This operation allows you to perform formula calculations directly within the "Set Variable Value" action step and the "Value" condition step.

Supported math operations and functions include:

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

Note: If the formula is invalid, the system will return 0 for number variables and leave text variables empty.

## ## Setting Text Variables

### ### Trimming Text

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

### ### Substring

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

Note: Indexing starts at 0. Every character, including spaces and punctuation, is counted.

### ### Replace String / Replace String Case Sensitive

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

Note: For case-sensitive replacements, ensure you use the exact case, such as "Hi" instead of "hi", "HI", or "hI".

### ### Convert to Lower / Upper Case

| Type | e.g. Before | e.g. After |
| --- | --- | --- |
| to lower case | "Hi, Flexito OmniAI!" | "hi, Flexito OmniAI!" |
| to upper case | "Hi, Flexito OmniAI!" | "HI, Flexito OmniAI!" |

### ### Generate Random Text

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

This feature is handy for generating one-time verification or reference codes.

### ### URL Encode / Decode

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

### ### Base64 Encode / Decode

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

### ### Convert to URL-Friendly Slug

| 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" |

### ### Get Text Before/After

Description: Extract a portion of the text.

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

## ## Setting Number Variables

### ### Get Text Length

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

### ### Generate Random Number

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

### ### Mathematical Operations: Add, Subtract, Multiply, Divide, Modulus, Power, Natural Logarithm, Square Root

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

TIP: For "natural logarithm", when calculating log2(8), input 8 as "Value" and 2 as "Number".

### ### Rounding Numbers

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

### ### Floor / Ceil

Description: Obtain the nearest integer.

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

## ## Setting DateTime Variables

### ### From Formatted Text

| 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 |

### ### Add Minutes, Hours, Days, Weeks, Months

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