# Set enviroment in pre-request script

**URL:** <https://community.postman.com/t/set-enviroment-in-pre-request-script/5972>\
**Category:** Help Hub\
**Tags:** new-feature\
**Created:** [June 19, 2019, 8:38am UTC](https://community.postman.com/t/set-enviroment-in-pre-request-script/5972 "2019-06-19T08:38:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgh-sanistaal](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@mgh-sanistaal](https://community.postman.com/u/mgh-sanistaal)\
**Post date:** [June 19, 2019, 8:38am UTC](https://community.postman.com/t/set-enviroment-in-pre-request-script/5972/1 "2019-06-19T08:38:07Z")

</div>

**Describe the bug**  
Cant choose an enviroment for a specific request in the pre-request script section.

**To Reproduce**  
Script in pre-request script section: e.g. postman.enviroment.set(‘Production’)

**Expected behavior**  
The request should use the Production enviroment variables

---

<div class="post-metadata">

**Author:** ![aamir.ahmed](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@aamir.ahmed](https://community.postman.com/u/aamir.ahmed)\
**Post date:** [June 19, 2019, 10:14am UTC](https://community.postman.com/t/set-enviroment-in-pre-request-script/5972/2 "2019-06-19T10:14:36Z")

</div>

Hi @mgh-sanistaal,

Welcome to the Postman community ! You can only link an environment to one or multiple collections and you cannot link a single request to a particular environment.  
Have a look at the following link to learn more about collections:  
[https://learning.getpostman.com/docs/postman/collections/intro\_to\_collections/](https://learning.getpostman.com/docs/postman/collections/intro_to_collections/)  
With regards to the script to set the environment variable, I would take a look at the right side pane of Postman as shown in the attached image where you can view several code snippets including the one to set an environment variable:

 ![setenvironmentvar](https://us1.discourse-cdn.com/getpostman/original/2X/e/e0ca6b2957b83447ab0d962ac167044ee0bff08d.png)

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [June 19, 2019, 10:29am UTC](https://community.postman.com/t/set-enviroment-in-pre-request-script/5972/3 "2019-06-19T10:29:11Z")

</div>

I know you said “set environment” but just incase you’re wanting to “set an environment variable” use the below:

```auto
pm.environment.set("Production")

```

Also, you spelt “environment” incorrectly every time in your post. I do this all the time 😛
