# How to get the name of the current selected environment collection?

**URL:** <https://community.postman.com/t/how-to-get-the-name-of-the-current-selected-environment-collection/28423>\
**Category:** Help Hub\
**Created:** [October 5, 2021, 6:56am UTC](https://community.postman.com/t/how-to-get-the-name-of-the-current-selected-environment-collection/28423 "2021-10-05T06:56:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lisamariechooose](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@lisamariechooose](https://community.postman.com/u/lisamariechooose)\
**Post date:** [October 5, 2021, 6:56am UTC](https://community.postman.com/t/how-to-get-the-name-of-the-current-selected-environment-collection/28423/1 "2021-10-05T06:56:10Z")

</div>

Is there a built in variable to get the name of the currently selected Environment collection?

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [October 5, 2021, 7:15am UTC](https://community.postman.com/t/how-to-get-the-name-of-the-current-selected-environment-collection/28423/2 "2021-10-05T07:15:20Z")

</div>

@lisamariechooose Welcome to the Community 🥳

I believe you are looking for the current environment name.

If so simply this will give you:

```auto
console.log(pm.environment.name);

```

If you need the complete details about the current environment you simple do as:

```auto
console.log(pm.environment);

```

This will return a big JSON with Environment ID, name and the list of variables under the environment 😊

---

<div class="post-metadata">

**Author:** ![lisamariechooose](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@lisamariechooose](https://community.postman.com/u/lisamariechooose)\
**Post date:** [October 5, 2021, 8:32am UTC](https://community.postman.com/t/how-to-get-the-name-of-the-current-selected-environment-collection/28423/3 "2021-10-05T08:32:34Z")

</div>

Hi…  
so I would like to use it like this: {{environment.name}}  
so not in a script. Actually as part of the Naming of OAuth token. Is that possible?

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [October 5, 2021, 8:47am UTC](https://community.postman.com/t/how-to-get-the-name-of-the-current-selected-environment-collection/28423/4 "2021-10-05T08:47:19Z")

</div>

In that case you can assign it to a variable and use it:

```auto
pm.collectionVariables.set("currentEnvironmentName", pm.environment.name);

```

Use {{currentEnvironmentName}} in naming the token. Is this helpful? 😇

---

<div class="post-metadata">

**Author:** ![lisamariechooose](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@lisamariechooose](https://community.postman.com/u/lisamariechooose)\
**Post date:** [October 5, 2021, 1:37pm UTC](https://community.postman.com/t/how-to-get-the-name-of-the-current-selected-environment-collection/28423/5 "2021-10-05T13:37:12Z")

</div>

Thank you so much. Very helpful! 🙂

---

<div class="post-metadata">

**Author:** ![lisamariechooose](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@lisamariechooose](https://community.postman.com/u/lisamariechooose)\
**Post date:** [October 5, 2021, 1:50pm UTC](https://community.postman.com/t/how-to-get-the-name-of-the-current-selected-environment-collection/28423/6 "2021-10-05T13:50:06Z")

</div>

Actually… testing it out it does not work.

I on the Authorization page of a collection and trying to get an access token. Even thought I added the code to Pre-request script… that script is not run when pressing “Get new Access Token” button.  
So the variable is not set with the currently selected Environment collection when fetching a new token.

Any idea on how I can do this without having to add an environment variable to all environment collections?
