# Pm.environment.set called in Tests don't persist data when called by Flows

**URL:** <https://community.postman.com/t/pm-environment-set-called-in-tests-dont-persist-data-when-called-by-flows/35088>\
**Category:** Help Hub\
**Tags:** variables, bug, postman-flows\
**Created:** [May 6, 2022, 2:39pm UTC](https://community.postman.com/t/pm-environment-set-called-in-tests-dont-persist-data-when-called-by-flows/35088 "2022-05-06T14:39:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![igasparetto](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/igasparetto/32/11914_2.png) [@igasparetto](https://community.postman.com/u/igasparetto)\
**Post date:** [May 6, 2022, 2:39pm UTC](https://community.postman.com/t/pm-environment-set-called-in-tests-dont-persist-data-when-called-by-flows/35088/1 "2022-05-06T14:39:17Z")

</div>

_pm.environment.set called in Tests don’t persist data when called by Flows_:

_Details (like screenshots)_:  
My collection has a bunch of endpoints that need to be called in sequence.  
The first endpoint is a GET that returns a list or other endpoints.

For example, when I call /api/ I get my home URI:

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/0/01c9d528583bd2b4593ea522a935064983e3862c.png)

I then use the HOME URI in the next call:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/7/7729ba1770fb1c60da0fba287e8a154adee792d2.png)

I used the Tests tab to store the values in an environment variable:

```auto
var data = JSON.parse(responseBody);
pm.environment.set('home', data.home);

```

Until here, everything works fine

_How I found the problem_:  
I then created Flows (which I understand is a Beta functionality) and I was expecting to connect the dots by linking Send Requests.  
Although the values are fetched correctly and the SET function is called, the values don’t persist from one to the next Send Request.

_I’ve already tried_:  
To change the environment variables to Global.

I think this is a bug.

---

<div class="post-metadata">

**Author:** ![igasparetto](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/igasparetto/32/11914_2.png) [@igasparetto](https://community.postman.com/u/igasparetto)\
**Post date:** [May 7, 2022, 2:10pm UTC](https://community.postman.com/t/pm-environment-set-called-in-tests-dont-persist-data-when-called-by-flows/35088/2 "2022-05-07T14:10:43Z")

</div>

Answering my own question…

When running Flows, there is no point in persisting the values from the response because Flows Send Request use the result from the previous calls.  
The value can be allocated to the variable through the Variables box.

The value of “home” comes from this request:

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/f/fcbbd165417a3a5e942ca4dd1bb4c7f2f8c95273.jpeg)

I was using the Tests tab to store the value of “home” but we don’t need to do this:

```auto
var data = JSON.parse(responseBody);
pm.environment.set("home", data.home);

```

We then have {{home}} used in the next request:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/e/e9a9689fce9dc35741f14a460205f45cb2e89dae.png)

In Flows, I link the 2 Send Requests

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/2/2985dc6e09cd30ed2e39520c618b1fc68d71a229.jpeg)

And, in the second one, I say: “for this variable, use that value”

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

The value must come from a response example stored alongside the request.  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/4/4d795d9b0b855ef8e32d851c470c20d6854f8d01.png)

To be fair, using Tests to store variables from the response actually helped because I needed to create response example that will be used in Flows later on.
