# Set environment current variable values to initial values

**URL:** <https://community.postman.com/t/set-environment-current-variable-values-to-initial-values/62557>\
**Category:** Help Hub\
**Tags:** tests, variables, environments\
**Created:** [June 24, 2024, 3:37am UTC](https://community.postman.com/t/set-environment-current-variable-values-to-initial-values/62557 "2024-06-24T03:37:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrea-ree](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@andrea-ree](https://community.postman.com/u/andrea-ree)\
**Post date:** [June 24, 2024, 3:37am UTC](https://community.postman.com/t/set-environment-current-variable-values-to-initial-values/62557/1 "2024-06-24T03:37:56Z")

</div>

Hi all,

I have a set of environments in Postman and each environments contains hundreds of variable values (saved on current values) that I used in testing. Upon exporting or duplicating the environments, the values are removed.

Is there a quick process of transferring/bulk moving the variable values from `current values` to `initial values` ?

Would really appreciate any suggestions.  
Thank you.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [June 24, 2024, 9:12am UTC](https://community.postman.com/t/set-environment-current-variable-values-to-initial-values/62557/2 "2024-06-24T09:12:37Z")

</div>

This question has been asked before, and I’m pretty sure the answer was “no”. There is no quick way (but I guess this is down to your definition of “quick”).

If I remember rightly, the solution was to use the Postman Collection API to update the info.

@danny-dainton Wasn’t this your solution? Do you have more details?

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [June 24, 2024, 1:13pm UTC](https://community.postman.com/t/set-environment-current-variable-values-to-initial-values/62557/3 "2024-06-24T13:13:55Z")

</div>

@andrea-ree. @michaelderekjones is right.

The neatest way to do this is to use the Postman API to update your environment object using the “[Update an Environment](https://www.postman.com/postman/workspace/postman-public-workspace/documentation/12959542-c8142d51-e97c-46b6-bd77-52bb66712c9a?entity=request-12959542-9f175bea-1df5-44e6-af33-bf2de7f85bb5)” endpoint on the Postman API.

---

<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:** [June 24, 2024, 1:34pm UTC](https://community.postman.com/t/set-environment-current-variable-values-to-initial-values/62557/4 "2024-06-24T13:34:24Z")

</div>

I’m not sure how that would work as if those values are only in the Current Value, the Postman API wouldn’t be able to see them. Much the same way as they are not part of the export file, those values are only ever local to you doing that session.

I guess you could get them all with `pm.environment.toObject()` and then grab the values. Then use the _Postman API_ to update the environment with the data from the current values:

```auto
let environmentObject = pm.environment.toObject();

console.log(Object.values(environmentObject));

```

I would ensure that you trial this out against a dummy environment first to know that it’s working as expected before moving the you actual environment.

* * *

If you wanted to move them the Initial Value, you could just do that in the UI using the _Persist All_ option, this will set the Initial Value to whatever the you have in the Current Value. That also sync’s those variable and doesn’t only keep them local.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/9/c92daaefc5e656af8010707100f77a1cc9fd8229.png)

Doing that, isn’t something that you can easily undo though and you would need to manually remove the Initial Values if you didn’t want them there.

---

<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:** [July 24, 2024, 1:35pm UTC](https://community.postman.com/t/set-environment-current-variable-values-to-initial-values/62557/5 "2024-07-24T13:35:18Z")

</div>

Closed on July 24, 2024, 1:35pm UTC

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