Check if data is from a CSV or variable

I have collection variables defined, but I also run my collection with a CSV file. In order for either to work I do a check with a pre-request script with

    if (data['SERIAL']) {
        // data from file
    } else {
       // data from collection variable
    }

So I have to check for a specific name I can’t just for example check with

if (data) {
    // Data from file
} else {

}

I’m sure I’m missign something and hoping someone can point me in the right direction.

Could you take advantage of the Variable Scope here, if the names are the same?

If a variable with the same name is declared in two different scopes, the value stored in the variable with narrowest scope will be used—for example if there is a global and a local variable both named username, the local value will be used when the request runs.

You could get the variable using the pm.variables.get('var_name')

1 Like