How to reuse a function

@idpbee you could do the following:

  • In the Collection level pre-request script, declare an object without using the var, let or const keywords. The object is then attached to the global sandbox and is available in child context of that collection.

In the collection pre-request script:

utils = {
    getEnv(v) {
        return pm.environment.get(v);
    }
}

Now within any of the children of that collection, you could simply do the following:

utils.getEnv('name');
3 Likes