# How to reset variables to initial value from script

**URL:** <https://community.postman.com/t/how-to-reset-variables-to-initial-value-from-script/20629>\
**Category:** Help Hub\
**Created:** [February 21, 2021, 1:59pm UTC](https://community.postman.com/t/how-to-reset-variables-to-initial-value-from-script/20629 "2021-02-21T13:59:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [February 21, 2021, 1:59pm UTC](https://community.postman.com/t/how-to-reset-variables-to-initial-value-from-script/20629/1 "2021-02-21T13:59:35Z")

</div>

**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:** [December 12, 2024, 2:46pm UTC](https://community.postman.com/t/how-to-reset-variables-to-initial-value-from-script/20629/2 "2024-12-12T14:46:57Z")

</div>

Closed on December 12, 2024, 2:46pm UTC

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