# Environment variable not updated via Run Collection

**URL:** <https://community.postman.com/t/environment-variable-not-updated-via-run-collection/57628>\
**Category:** Help Hub\
**Tags:** variables, collections\
**Created:** [February 14, 2024, 4:04am UTC](https://community.postman.com/t/environment-variable-not-updated-via-run-collection/57628 "2024-02-14T04:04:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jebkoz](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jebkoz](https://community.postman.com/u/jebkoz)\
**Post date:** [February 14, 2024, 4:04am UTC](https://community.postman.com/t/environment-variable-not-updated-via-run-collection/57628/1 "2024-02-14T04:04:00Z")

</div>

Hello,  
I have a collection with 2 requests (create\_user and get\_user).  
When I run create\_user request , userid is generated .I set this userid as environment variable.  
Then I run get\_user request it picks userid from environment variables and gets user info accordingly.  
It all works perfectly when I run each request separately one by one.  
But when I run it via collection, environment variable is not updated.  
Please advise, what can it be.  
Thanks.

---

<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:** [February 14, 2024, 10:44am UTC](https://community.postman.com/t/environment-variable-not-updated-via-run-collection/57628/2 "2024-02-14T10:44:09Z")

</div>

Can you please provide screenshots of what you’ve got.

There is no reason that this shouldn’t work if you have the correct environment set.

---

<div class="post-metadata">

**Author:** ![jebkoz](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jebkoz](https://community.postman.com/u/jebkoz)\
**Post date:** [February 14, 2024, 9:32pm UTC](https://community.postman.com/t/environment-variable-not-updated-via-run-collection/57628/3 "2024-02-14T21:32:32Z")

</div>

Thanks for reply, Mike! Please see attached screenshots.  
 ![Create User pre Request](https://us1.discourse-cdn.com/getpostman/original/3X/d/a/da3b304dd58d7e1d7600ad417a3033c0c2180dec.png)

 ![Create User Body](https://us1.discourse-cdn.com/getpostman/original/3X/1/0/10de01943cea3927178ae2c8d2f51d7a2dfa35c9.png)  
 ![Create User Test](https://us1.discourse-cdn.com/getpostman/original/3X/7/c/7cf952f59d0c551876d4bb4931a688494d199bb0.png)

---

<div class="post-metadata">

**Author:** ![jebkoz](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jebkoz](https://community.postman.com/u/jebkoz)\
**Post date:** [February 14, 2024, 9:33pm UTC](https://community.postman.com/t/environment-variable-not-updated-via-run-collection/57628/4 "2024-02-14T21:33:36Z")

</div>

![Get User Details](https://us1.discourse-cdn.com/getpostman/original/3X/c/f/cf62f1d80289d538d2ad5d0c3e508037fe8567db.png)  
 ![Collection](https://us1.discourse-cdn.com/getpostman/original/3X/1/7/17bef88569b02ff0f84857d761af06282d8f8a6a.png)

---

<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:** [February 15, 2024, 9:00am UTC](https://community.postman.com/t/environment-variable-not-updated-via-run-collection/57628/5 "2024-02-15T09:00:50Z")

</div>

Which one is failing, or are they all failing?

This is where the console log comes into play.

As soon as you set the environment variable, use pm.environment.get to retrieve it again. This should give you confidence that the variable is indeed set.

Start with the first request.

You can also put this in the tests tab and console log those variable before you have the pm.test block.

Are you 100% sure you have the environment selected when using the collection runner? I assume you are running this via the Collection runner. If you are using something else like the CLI or Newman, you will need to tell us. Make sure you tick the option to persist responses in the collection runner, and this will give you another place to check things out.

---

<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:** [March 16, 2024, 9:01am UTC](https://community.postman.com/t/environment-variable-not-updated-via-run-collection/57628/6 "2024-03-16T09:01:39Z")

</div>

Closed on March 16, 2024, 9:01am UTC

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