# How to use variables in Leapwork?

## Introduction

The variables building blocks are used to Get and Set variable values for later use. Variables can be temporary or be persisted forever.

[**Get Variable**](/content/product/documentation/building-blocks/variables/get-variable/index.html): A Get variable building block is used to get the value of a variable and pass it on to other building blocks. Variables can be scoped to be available only in the same run of a case, across all cases in a run, and even permanently for as long as the Project exists.

[**Set Variable**](/content/product/documentation/building-blocks/variables/set-variable/index.html): A Set variable building block is used to set the value of a variable. Variables can be scoped to be available only in the same run of a case, across all cases in a run, and even permanently for as long as the Project exists.

## Scope

Set the scope in which to load this variable.

- **Only this case** means that the variable only exists during the execution of this one case, i.e. scope of the variable is only fixed in that particular flow where it is been used. This is the by default value for both variable blocks.
- **Schedule** means the variable will exist across all cases defined in a schedule during the same run. It is beneficial when the user wants to pass the value at the scheduled run time under the variable category. The finest example of this scope will be doing cross-browser testing using Leapwork.
- **Permanent** means the variable will continue to exist permanently. These variables will hold the value even after the flow is completed and also across multiple flows. Once the variable with the permanent scope is set with a value, then that variable can be used across all the flows with permanent scope.

## Example 1: Get and Set Variable Block

Here is an example to use get and set blocks to add two variables Variable1 and Variable2.

For more details please visit the [Use Numbers and Variables](/content/services/learning-center/use-numbers-and-variables/index.html) lesson on how to use variables.

**Note:** Variable name is case sensitive so please use the correct case while accessing it.

## Example 2: Schedule Variables

You can define variables in the schedule and run the schedule based on that.

It is also possible to get or set schedule variables in the flow, by changing their scope to schedule.

To get more information on schedule variables and their usage, see [Cross-Browser Testing](https://support.leapwork.com/s/article/HowtodocrossbrowsercompatibilitytestingwithLeapwork633070d434aa1).

## Example 3: Accessing variables using Variable Endpoints in REST API

Users can also use Leapwork REST API endpoints to manipulate the variables. There are 3 variable endpoints in Leapwork that can be used dynamically:

- [Get All Variables](/content/product/documentation/rest-api/get-all-variables/index.html): This endpoint returns a list of all permanent variables and their corresponding values.
- [Edit Variable by Name](/content/product/documentation/rest-api/edit-variable-by-name/index.html): This endpoint is used to update the value of a permanent variable.
- [Get Variable By Name](/content/product/documentation/rest-api/get-variable-by-name/index.html): This endpoint is used when the user wants the detail of a specific permanent variable.

## Example 4: Passing Variable as Parameters in RunScheduleNow Endpoint

User can also specify the variable directly in the [Run Schedule Now endpoint](/content/product/documentation/rest-api/run-schedule-now/index.html) where values can be assigned to the variables.

For any clarification, contact our [Priority Support](mailto:prioritysupport@leapwork.com).
