# Variables to override data file

**URL:** <https://community.postman.com/t/variables-to-override-data-file/7368>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [August 23, 2019, 10:15am UTC](https://community.postman.com/t/variables-to-override-data-file/7368 "2019-08-23T10:15:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VeroScreening](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@VeroScreening](https://community.postman.com/u/VeroScreening)\
**Post date:** [August 23, 2019, 10:15am UTC](https://community.postman.com/t/variables-to-override-data-file/7368/1 "2019-08-23T10:15:38Z")

</div>

I am wanting to override the variables in the data file for just one of my tests.

I’ve tried setting the variables in my pre-request script, but they get overridden by the data file.

Is this possible?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 23, 2019, 11:27am UTC](https://community.postman.com/t/variables-to-override-data-file/7368/2 "2019-08-23T11:27:22Z")

</div>

Hey @VeroScreening,

I’m not sure what you have tried and not sure about your context so I offer this basic code with that in mind. 🙂

I added this code to a `Pre-request Script`:

```
let dataValue = pm.iterationData.get('test')

dataValue = "Changed"

pm.globals.set("newValue", dataValue) 

```

It basically grabbed the `test` key, that I had in my data file:

```
[
  {
    "test": "This is the data variable"
  }
]

```

It then set this `datafile` value as a new variable and used this in the request.

I logged out that `before` and `after` values to show you the difference:

 ![30](https://us1.discourse-cdn.com/getpostman/original/2X/f/fdbc8837a0fb5b061b7343842751613e9acc12c6.png)

Like I said, very basic but hopefully it just you an idea about _how_ you could do it.

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [August 23, 2019, 11:33am UTC](https://community.postman.com/t/variables-to-override-data-file/7368/3 "2019-08-23T11:33:16Z")

</div>

According to the Postman [variable scopes](https://learning.getpostman.com/docs/postman/environments_and_globals/variables/#variable-scopes), the only variable that can override a data variable is a local variable.

For example, you can set a local variable in a pre-request script:

```
if (some condition) {
    pm.variables.set("yourvariable", "new-value");
}

```

Remember to unset the variable once you don’t need it, otherwise, it will be persisted during the entire execution.
