# Scripting the reset of collection variable to its initial value

**URL:** <https://community.postman.com/t/scripting-the-reset-of-collection-variable-to-its-initial-value/20620>\
**Category:** Help Hub\
**Tags:** variables, testscripts\
**Created:** [February 21, 2021, 1:26am UTC](https://community.postman.com/t/scripting-the-reset-of-collection-variable-to-its-initial-value/20620 "2021-02-21T01:26:07Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:54pm UTC](https://community.postman.com/t/scripting-the-reset-of-collection-variable-to-its-initial-value/20620/3 "2021-02-21T13:54:10Z")

</div>

if you still want to reset then use :

**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

---

_[View the full topic](https://community.postman.com/t/scripting-the-reset-of-collection-variable-to-its-initial-value/20620)._
