> ## Documentation Index
> Fetch the complete documentation index at: https://momentic.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Variables

> Store and reuse data across steps using the global `env` object and templating syntax.

All variables live on a global `env` object. Access them anywhere a field
accepts a string using `{{ env.NAME }}`, or directly as `env.NAME` inside
**JavaScript** steps.

See [Environment variables](/configuration/environment-variables) for the full
list of reserved variables and how Momentic loads them at runtime.

## Example

Extract a value, then use it in a later step:

```yaml extract-order-id.test.yaml theme={null}
fileType: momentic/test/v2
id: extract-order-id
steps:
  - act: Click "Place order"
  - extract:
      goal: The order id shown in the confirmation banner
      saveAs: ORDER_ID
  - assert: "A confirmation email mentioning order {{ env.ORDER_ID }} was sent"
```

## Setting variables

### From JavaScript

```javascript theme={null}
setVariable("USERNAME", "testuser");
setVariable("PASSWORD", Math.random().toString(36).substring(2, 15));
```

### From any step with a return value

Any step with a return value (e.g. **AI extract**, **JavaScript**) can write
that value to the environment with `saveAs` - the editor's **Save to environment
variable** option. Provide a key; the step's return value is written to `env`
after execution.

```yaml theme={null}
- extract:
    goal: The discounted subtotal in the order summary
    saveAs: SUBTOTAL
- javascript:
    code: return faker.string.uuid()
    saveAs: SESSION_ID
```

## Scope

All variables are test-scoped. Set a variable in one step; any subsequent step
in the same test can read it.

### Module parameters

Module parameters are variables scoped to the module's execution. A parameter
named `API_KEY` is available as `{{ env.API_KEY }}` inside that module.
