Collection runner variable scope

I feel like you’ve already answered your own question.

Here is the documentation on variable scoping.

If a variable is defined in a specific scope, but has no value - it is still going to return a blank value. So if your data variable is blank, you’ll get a blank.

One way you could get around this is to coalesce the values in a pre-request script.

let myVariable = pm.iterationData.get("variable_name");
if(!myVariable) {
  myVariable = pm.collectionVariables.get("variable_name");
}

pm.variables.set("variable_name", myVariable);

This will set either the data variable or the collection variable to a local variable, which has the highest priority.

1 Like