# Setting an environment variable back to its default value

**URL:** <https://community.postman.com/t/setting-an-environment-variable-back-to-its-default-value/52637>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [September 30, 2023, 4:54pm UTC](https://community.postman.com/t/setting-an-environment-variable-back-to-its-default-value/52637 "2023-09-30T16:54:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ButtockFlesh](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@ButtockFlesh](https://community.postman.com/u/ButtockFlesh)\
**Post date:** [September 30, 2023, 4:54pm UTC](https://community.postman.com/t/setting-an-environment-variable-back-to-its-default-value/52637/1 "2023-09-30T16:54:36Z")

</div>

I sometimes change a variable in my pre-request script for a request

and then in my collection at the end of the collection-level tests I want to set it back. I am having to use a second variable to store the value.

`pm.environment.set("maxErrors", pm.environment.get("maxErrorsDefault"));`

what I really want to do is something like (pseudo-code)

`pm.environment.resetToDefaultValue("maxErrors")`

is there a way?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 30, 2023, 10:47pm UTC](https://community.postman.com/t/setting-an-environment-variable-back-to-its-default-value/52637/2 "2023-09-30T22:47:55Z")

</div>

Hey @ButtockFlesh 👋

I was going to suggest something like this method but I think you’re kinda doing this already:

> [@How to reset variables to initial value from script](https://community.postman.com/t/how-to-reset-variables-to-initial-value-from-script/20629):
>
> Add this to first request’s pre-request script: pm.environment.set("resetValue",pm.collectionVariables.toJSON().values) This wiil store all initial value to resetValue variable And in the last request’s test script use pm.environment.get("resetValue").forEach((a)=\>pm.collectionVariables.set(a.key,a.value)) Now we are resetting all collectionVariables to the initially saved value

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [October 30, 2023, 10:48pm UTC](https://community.postman.com/t/setting-an-environment-variable-back-to-its-default-value/52637/3 "2023-10-30T22:48:16Z")

</div>

Closed on October 30, 2023, 10:48pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
