Pre request script in collection, folder and request are unique scopes?

I was super excited to hear about collection, and folder level scripting, but the current implementation leaves much to be desired.

It seems that nothing between the various scripts is shared. For instance, I have a lot of script code with functions for data handling in my pre request sections for requests, a lot are helper type methods. Currently I have a lot of duplication due to needs of those methods in many requests, not cool! Yes, I have gone down the whole eval(myscriptblock) path as well, but it is too obfuscated for other users on my team to maintain or understand. And again, maintenance is a PITA.

I was hoping that by allowing a collection level script block I could move all of those methods to that collection script block and then call the methods from the pre request script in each request. But alas, that is not the case. Why? Without this ability I see little value in a collection level script block other than generating all the data required for a set of requests all in one go, but even this is not great since the script is run every time a request is sent! So if my request needs 2 of 20 data objects created by my script I am wasting effort on 18 others and likely polluting my environment variables in the process.

Is the functionality of the script blocks at the various levels still evolving? Please tell me yes!

1 Like

@kevin.costner While the sandbox functionality for scripts is not actively being worked on at the moment, we do realize that this is a feature request. I can imagine that this would help eradicate a world of maintenance issues around handling common code, etc.