# Util function pre-request scripts in collection doesn't execute update variable

**URL:** <https://community.postman.com/t/util-function-pre-request-scripts-in-collection-doesnt-execute-update-variable/19571>\
**Category:** Help Hub\
**Tags:** variables, collections, pre-request\
**Created:** [January 26, 2021, 4:48pm UTC](https://community.postman.com/t/util-function-pre-request-scripts-in-collection-doesnt-execute-update-variable/19571 "2021-01-26T16:48:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alvaro\_mv.co](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@alvaro\_mv.co](https://community.postman.com/u/alvaro_mv.co)\
**Post date:** [January 26, 2021, 4:48pm UTC](https://community.postman.com/t/util-function-pre-request-scripts-in-collection-doesnt-execute-update-variable/19571/1 "2021-01-26T16:48:24Z")

</div>

I have below utils function in a pre-request scripts in a collection

```
utils = {
    setCreateUpdate: function (json_body, uri_var){
        uri_value = pm.environment.get(uri_var);
        console.log(`Variable:${uri_var} with value:${uri_value}`);
        if(uri_value){  
            json_body.id = uri_value;
            pm.request.method = "PUT";
        }else{
            pm.request.method = "POST";
        }
        console.log(`Method:${pm.request.method}`);
        pm.environment.set("json_body", JSON.stringify(json_body));
    }
};

```

pm.environment.set doesn’t work in the function but it works if I return the value and set in the “pre-request script” of the request.

Is there any limitation context where global or collection functions can’t update variable?

Thanks
