# Create Dynamic Variable

This is a pre-built Action located under the **@Generic Element.** The functionality of this Action in Avo Assure is to create a dynamic variable, assign a value based on the input provided. The execution result is stored in the given dynamic variable.

## **Syntax**

&#x20;**Input Value**: `<variable name>;<value to be stored>`

{% hint style="info" %}
&#x20;**Note**:&#x20;

* The variable you create appears within curly brackets {}.
* A dynamic variable does not have a fixed value, and you can update it at any point during test execution using the **Modify Variable Value** action. To learn more about how to modify, [click here](https://docs.avoautomation.com/actions/generic/variable-operations/modify-variable-value).
* The index starts at 0.
* When you create a dynamic variable in a Test Step Group, you can use its value in any Test Case or Test Step Group within the same project.
* You can access and reuse the created dynamic variable while building an end-to-end flow within the same project.
  {% endhint %}

| Argument                                      | Description                                                                                                                                                                         |
| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>\<variable name></p><p>(Required)</p>      | Provide the name of the variable you want to create.                                                                                                                                |
| <p>\<value to be stored></p><p>(Required)</p> | <p>Provide the value that you want to store in the variable.<br>Supported strings are: </p><ul><li>Number </li><li>String</li><li>Alphanumeric</li><li>Special Characters</li></ul> |

**Output Value**: `<Dynamic Variable>(Optional);<Dynamic Variable>(Optional)`

| Argument                                                    | Description                                                       |
| ----------------------------------------------------------- | ----------------------------------------------------------------- |
| \<Dynamic Variable>(Optional);\<Dynamic Variable>(Optional) | Both dynamic variables store the status as **True** or **False**. |

### **Example 1: Creating a Dynamic Variable with a Specific Value**

In this example, we explain how to create a dynamic variable and assign a value at runtime.

* **Action**: Create Dynamic Variable
* **Input Value**: {Username};Admin
  * The first argument (**{Username}**) specifies the name of the dynamic variable.
  * The second argument (**Admin**) specifies the value of the dynamic variable.
* **Output Value**: {VariableStatus}
  * The execution status is stored in this **{VariableStatus}** dynamic variable with the following possible values:
    * **True**: If the variable is created successfully and the value is assigned.
    * **False**: If the operation fails due to an invalid variable name or missing value.

{% hint style="info" %}
**Note**: If you do not define an output variable, Avo Assure displays the result only in the execution logs and does not store it in any variable.
{% endhint %}

* **Logical Explanation**: The **Create Dynamic Variable** action fetches the value from the **Input Value** column (**{Username};Admin**). It creates a dynamic variable named {Username} and assigns the value (Admin) to it. This variable can be reused throughout the Test Case. The execution result is stored as (True) in the **{VariableStatus}** dynamic variable.

<figure><img src="https://2174257472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk8QZzXZMIJSStKAzDSTu%2Fuploads%2F0stdw5hn7UTteZpdtKJE%2Fimage.png?alt=media&#x26;token=a579a9c2-30bc-48d1-8bcd-928ee45662de" alt=""><figcaption></figcaption></figure>

### **Example 2:** Creating a Dynamic Variable Containing an Array and Accessing Its Values

In this example, we explain how to create a dynamic variable that stores an array and then retrieve a specific value from that array using its index.

* **Action**: Create Dynamic Variable
* **Input Value**: {Values};\[12,34,23,45]
  * The first argument (**{Values}**) specifies the name of the dynamic variable.
  * The second argument (**\[12,34,23,45]**) specifies the array value of the dynamic variable.
* **Output Value**:&#x20;
  * The execution status is stored in this **{VariableStatus}** dynamic variable with the following possible values:
    * **True**: If the array variable is created successfully.
    * **False**: If the operation fails due to an invalid variable name or incorrect array index.

{% hint style="info" %}
**Note**: If you do not define an output variable, Avo Assure displays the result only in the execution logs (Avo Assure Client) and does not store it in any variable.
{% endhint %}

* **Using Array Index**:
  * When the action creates the array, you access its values using index value as shown below.
    * **{Values\[0]}** → stores **12**
    * **{Values\[1]}** → stores **34**
    * **{Values\[2]}** → stores **23**
    * **{Values\[3]}** → stores **45**
* **Logical Explanation**: The **Create Dynamic Variable** action takes the value from the **Input Value** column (**{Values};\[12,34,23,45]**) and creates a dynamic variable named {Values} containing the array \[12,34,23,45]. Each position in the array can be accessed using array indexing. The **Display Variable Value** action displays the value at the 2<sup>nd</sup> index of the dynamic variable by using **{Values\[2]}** as input and shows the value as (23).

<figure><img src="https://2174257472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk8QZzXZMIJSStKAzDSTu%2Fuploads%2F8OotwKIh1g5114sdQx65%2Fimage.png?alt=media&#x26;token=888ea80b-71bb-4f3b-8eee-496a5416f357" alt=""><figcaption></figcaption></figure>

#### **Knowledge Bites:**&#x20;

Here are some examples of different variable scenarios:

<table><thead><tr><th>Variables</th><th width="304.99993896484375">Input Value</th><th>Result </th></tr></thead><tbody><tr><td>Text Variable</td><td>{String};AdminUser</td><td>AdminUser</td></tr><tr><td>Numeric Variable</td><td>{Number};35629</td><td>35629</td></tr><tr><td>Special Character Variable</td><td>{Email Id};john@gmail.com</td><td>john@gmail.com</td></tr><tr><td>Alphanumeric Variable</td><td>{Alphanumeric};OR1002</td><td>OR1002</td></tr><tr><td>List Values Variable</td><td>{Usernames};[John,Doe,Smith,Mac]</td><td>[John,Doe,Smith,Mac]</td></tr></tbody></table>
