---
title: "Storing Global Variables in Transaction Scripts"
slug: "storing-global-variables-in-transaction-scripts"
updated: 2023-01-06T15:48:57Z
published: 2023-01-06T15:48:57Z
---

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

# Storing Global Variables in Transaction Scripts

## Overview

When using the same variables in more than one test, Global Variables can be implemented to perform a login step in one test, extract and save an authorization token, and then use it to authenticate a connection in another test.

*Note: If a global variable hasn't been updated in a week, it is removed from Catchpoint's storage. Global variable naming has a range of 1-32 characters, and Global variable values have a range of 1-1024 characters.*

## Implementation

### How to store and read global variables within Transaction and API tests

Below is the syntax for storing and reading a global variable. For more information for each command, click on their respective names. [storeGlobalVariable(macros, variableName)](https://docs.catchpoint.com/docs/Transaction-Commands-and-Macros#storeGlobalVariable) [${globalVariable(variableName)}](https://docs.catchpoint.com/docs/Transaction-Commands-and-Macros#storeGlobalVariable)

## Example

The example below demonstrates how to store a cookie value from a response header as a global variable named "newCookie". Afterward, the Global Variable is read and set as a new cookie in a different test:

```
//Set Global Variable
open("http://www.google.com")
storeGlobalVariable("${extract(resp-header, regexp:set-cookie: (.*))}", "newCookie")

//Get Global Variable
open("http://www.google.com")
setHeader("Cookie", "${globalVariable(newCookie)}")
```
