# Please help with execution order while using a collection-pre-request-defined function in a pre-request script

**URL:** <https://community.postman.com/t/please-help-with-execution-order-while-using-a-collection-pre-request-defined-function-in-a-pre-request-script/31761>\
**Category:** Help Hub\
**Tags:** variables, environments, collections, functions\
**Created:** [January 20, 2022, 9:25pm UTC](https://community.postman.com/t/please-help-with-execution-order-while-using-a-collection-pre-request-defined-function-in-a-pre-request-script/31761 "2022-01-20T21:25:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![satellite-architect2](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@satellite-architect2](https://community.postman.com/u/satellite-architect2)\
**Post date:** [January 20, 2022, 9:25pm UTC](https://community.postman.com/t/please-help-with-execution-order-while-using-a-collection-pre-request-defined-function-in-a-pre-request-script/31761/1 "2022-01-20T21:25:41Z")

</div>

_My question_:  
I’ve ilustrated my question in the following scenario:  
i have collection pre-request where i define an object that contains a function that returns the value of an environment variable.  
In my request, i have a pre-request script where i set the environment variable, then call the object.function of the collection pre-request. I would have expected the value to be defined, as i defined earlier in the execution. But it is not defined. Please help me understand this.

_Details (like screenshots)_:

The collection Pre-request script

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/1/2184c99b365d7a88ce23aae092613e4640886130.png)

The request pre-request script

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/8/88f445e16322e30eb48e3fe8367844458482818f.png)

The environment (i need the “oneVar” to be without an initial value, as i need to set this in the request pre-request script)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/c/9ccfa42290b19df1841c4b7e35506e6c2d5bece6.png)

The console log:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/6/f608e11d5616fa61ba6d03643fa8850e5eca019d.png)

In the environment print, the “oneVar” is not defined. If i print it in the request pre-request script, both variables are defined.

_How I found the problem_:  
I need to dynamically build the parameters to multiple requests, and i am using functions that i defined at the collection level.

_I’ve already tried_:  
using globals and/or collections variables, and i have the same result.

I suspect the collections-pre-request object somehow uses another instance of pm.environments. One that was instanced when the script is run. And even if the execution order seems to be:

1. collections script: initialize utils
2. request script: set variables
3. request script: use utils.function

i suspect that in the third step, utils object somehow uses the environment instance of it’s own moment of instantiation (at step 1).
