---
title: "Variable Scoping and Resolution"
description: "Variable scoping in Geneos determines which variable value is used when defined in multiple places. The resolution follows specific rules based on sampler location and variable definition hierarchy within the Gateway Setup Editor."
url: "https://docs.itrsgroup.com/docs/faq/geneos/115002983893-geneos-variable-scoping-and-resolution/index.html"
---
Variables can be set in any of the following places within the Gateway Setup Editor:

- Advanced tab of Managed Entity Groups
- Advanced tab of Managed Entities
- Advanced tab of Types
- Environment
- Operating Environment

This can get tricky when the same variable name is defined in multiple places and holds different values. To help figure out which value the variable is resolved to, we rely on the following **Variable Scoping Rules**:

- When a sampler or sampler include is referenced by a Type, we look for the variable in the following order:

  1. The environment specified when the type was added to that managed entity or managed entity group
  2. Variables defined directly in the type
  3. The environment referenced by the type

- When a Type is not used and the sampler or sampler include is referenced in the Managed Entity or Entity group, we look for the variable in the following order:

  1. Variables defined in (or inherited by) the managed entity
  2. The environment referenced by the managed entity
  3. The operating environment

## Examples and scenarios

To help better understand variable scoping rules, we will be using the below toolkit dataview that will echo out the following table. Notice the "Variable value" column is currently blank for the variable name "variableReso".

![7638700296221 mceclip0](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7638700296221-mceclip0.png)

The following rule will be used to set the resolved variable value for "variableReso".

![7638753229341 mceclip2](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7638753229341-mceclip2.png)

The below scenarios have "variableReso" defined in multiple places throughout the setup. Using variable scoping rules will help determine which value the variable resolves to.

The configuration files for these examples can be found in the bottom of the page.

## Scenario 01

- The Sampler is defined on a Type.
  - The variable *variableReso* is defined on the following:
    1. managedEntities > managedEntity > addTypes > type > environment
    2. managedEntities > managedEntity > environment
    3. managedEntities > managedEntity > var > name
    4. types > type > environment
    5. types > type > var > name
    6. operatingEnvironment > var
- Result: The variable used is #1 (managedEntities > managedEntity > addTypes > type > environment):

  ![7625374766621 mceclip1](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7625374766621-mceclip1.png)

## Scenario 02

- The Sampler is defined on a Type.
  - The variable *variableReso* is defined on the following:
    1. managedEntities > managedEntity > environment
    2. managedEntities > managedEntity > var > name
    3. types > type > environment
    4. types > type > var > name
    5. operatingEnvironment > var
- Result: The variable used is #4 (types > type > var > name):

  ![7625570873885 mceclip2](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7625570873885-mceclip2.png)

## Scenario 03

- The Sampler is defined on a Type.
  - The variable *variableReso* is defined on the following:
    1. managedEntities > managedEntity > environment
    2. managedEntities > managedEntity > var > name
    3. types > type > environment
    4. operatingEnvironment > var
- Result: The variable used is #3 (types > type > environment):

  ![7625882710813 mceclip3](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7625882710813-mceclip3.png)

## Scenario 04

- The Sampler is defined on a Type.
  - The variable *variableReso* is defined on the following:
    1. managedEntities > managedEntity > environment
    2. managedEntities > managedEntity > var > name
    3. operatingEnvironment > var
- Result: The variable used is #2 (managedEntities > managedEntity > var > name):

  ![7625908299549 mceclip4](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7625908299549-mceclip4.png)

## Scenario 05

- The Sampler is defined on a Type.
  - The variable *variableReso* is defined on the following:
    1. managedEntities > managedEntity > environment
    2. operatingEnvironment > var
- Result: The variable used is #1 (managedEntities > managedEntity > environment):

  ![7626078629021 mceclip6](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7626078629021-mceclip6.png)

## Scenario 06

- The Sampler is defined on a Type.
  - The variable *variableReso* is defined on the following:
    1. operatingEnvironment > var
- Result: The variable used is #1 (operatingEnvironment > var):

  ![7626251729565 mceclip7](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7626251729565-mceclip7.png)

## Scenario 07

- The Sampler is defined on a Managed Entity.
  - The variable *variableReso* is defined on the following:
    1. managedEntities > managedEntity > addTypes > type > environment
    2. managedEntities > managedEntity > environment
    3. managedEntities > managedEntity > var > name
    4. types > type > environment
    5. types > type > var > name
    6. operatingEnvironment > var
- Result: The variable used is #3 (managedEntities > managedEntity > var > name):

  ![7639951385501 mceclip3](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7639951385501-mceclip3.png)

## Scenario 08

- The Sampler is defined on a Managed Entity.
  - The variable *variableReso* is defined on the following:
    1. managedEntities > managedEntity > addTypes > type > environment
    2. managedEntities > managedEntity > environment
    3. types > type > environment
    4. types > type > var > name
    5. operatingEnvironment > var
- Result: The variable used is #2 (managedEntities > managedEntity > environment):

  ![7640530980253 mceclip4](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7640530980253-mceclip4.png)

## Scenario 09

- The Sampler is defined on a Managed Entity.
  - The variable *variableReso* is defined on the following:
    1. managedEntities > managedEntity > addTypes > type > environment
    2. types > type > environment
    3. types > type > var > name
    4. operatingEnvironment > var
- Result: The variable used is #4 (operatingEnvironment > var):

  ![7640839243037 mceclip5](https://docscdn.itrsgroup.com/faq/images/geneos/115002983893-7640839243037-mceclip5.png)

## Related articles

- [Variable Scoping and Resolution](https://docs.itrsgroup.com/docs/geneos/current/processing/gateway-administration/gateway_user_variables_and_environments/index.html#Heading-variable-scoping-and-resolution)

## Related downloads

- [scenario08.xml](/faq/downloads/geneos/115002983893-7640933985437-scenario08.xml)
- [scenario05.xml](/faq/downloads/geneos/115002983893-7640934039325-scenario05.xml)
- [scenario03.xml](/faq/downloads/geneos/115002983893-7640934059037-scenario03.xml)
- [scenario02.xml](/faq/downloads/geneos/115002983893-7640934119581-scenario02.xml)
- [scenario07.xml](/faq/downloads/geneos/115002983893-7640946835613-scenario07.xml)
- [scenario06.xml](/faq/downloads/geneos/115002983893-7640946859549-scenario06.xml)
- [scenario04.xml](/faq/downloads/geneos/115002983893-7640946880669-scenario04.xml)
- [scenario01.xml](/faq/downloads/geneos/115002983893-7640946910237-scenario01.xml)


