Variables to override data file

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?

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. :slight_smile:

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:

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

According to the Postman 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.