Cannot set const globalFunction = eval(globals.globalFunction)(); in collection prereq

I am using a global env file to have some functions in.
To call those functions in my test I use

const globalFunction = eval(globals.globalFunction)();

Now, every request has to have the
const globalFunction = eval(globals.globalFunction)(); so I can use my function. Rather than having to add this in each request. I am trying to call it in the collections prereq script. So called before each test.

However, it doesn’t seem to work.
I get the error
There was an error in evaluating the Pre-request Script: ReferenceError: globalFunction is not defined

What is my problem??

Hey @jasoncaunt

Welcome to the Postman community! :rocket:

Would you able able to share more about the function itself and maybe a screenshot of the different areas that you have that in the app?

Just trying to visualize what you’re doing :grin:

Also, would getting the function this way help?


This thread might add some extra information into getting something working:

My function looks like

    var CheckResponseCount = (retryDelay, retryLimit, expectectedCount, retryCount = 1) => {
    var bearer_token = pm.environment.get("bearer_token");

    // Construct our request URL from environment variables
    var baseurl = request["url"].replace("{{BaseURL}}", pm.environment.get("BaseURL"));
    baseurl = baseurl.replace("{{AccountId}}", pm.environment.get("AccountId"));
        url: baseurl,
        method: 'GET',
        header: {
            'content-type': 'application/json',
            'authorization': 'Bearer ' + bearer_token
    }, function (err, response) {
        if (err) {
            console.log("ERROR:" + err);
    } else {
            if (response.json().length !== expectectedCount) {
                if (retryCount < retryLimit) {
                    console.log('Job is still PENDING. Retrying in ' + retryDelay + 'ms');
                    setTimeout(function () {
                        CheckResponseCount(retryDelay, retryLimit, expectectedCount, ++retryCount);
                    }, retryDelay);
                } else {
                    console.log('Retry limit reached, giving up.');
                    pm.test( + " - FAILED TO GET CORRECT RESPONSE COUNT", function () {
            if (response.json().length === expectectedCount) {
                pm.test( + " - Correct Response Count", function () {

I currently call this function in my pre-req of my request

const globalFunction = eval(globals.globalFunction)();

But instead of having the
const globalFunction = eval(globals.globalFunction)();
in every request in the collection. I want it just once in the Collections Pre-Req section