# Pm.variables inside sendRequest handler not available

**URL:** <https://community.postman.com/t/pm-variables-inside-sendrequest-handler-not-available/26439>\
**Category:** Help Hub\
**Tags:** tests, variables, sendrequest\
**Created:** [August 4, 2021, 3:55pm UTC](https://community.postman.com/t/pm-variables-inside-sendrequest-handler-not-available/26439 "2021-08-04T15:55:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![neilstudd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/neilstudd/32/8213_2.png) [@neilstudd](https://community.postman.com/u/neilstudd)\
**Post date:** [August 5, 2021, 8:06am UTC](https://community.postman.com/t/pm-variables-inside-sendrequest-handler-not-available/26439/2 "2021-08-05T08:06:13Z")

</div>

Hi @satellite-observer-4, and welcome to the Postman community! 🚀

This one had me puzzled for a while. The problem isn’t that `pm.variables` stops being in-scope; the issue is due to the tests running asynchronously, and consequently your final line (which unsets `tmpSeriesKey`) is being executed before the `sendRequest`.

You can demonstrate this by either temporarily commenting-out the unset, or by wrapping it in a hardcoded 10-second timeout (obviously not something that you would want to do, but it will demonstrate the issue):

```auto
setTimeout(() => { pm.variables.unset("tmpSeriesKey") }, 10000);

```

Now, both of your `console.log` statements will contain the variable.

I would recommend finding some similar way to ensure that your tests are completed prior to unsetting this key (depending on your request execution flow, this could potentially include clearing the key at the start of the next test, rather than the end of this one?) - you may also be interested in reading some more tips about how to force the order of execution:

> [@Executing sync requests programmatically from a pre-request or test scripts](https://community.postman.com/t/executing-sync-requests-programmatically-from-a-pre-request-or-test-scripts/14678):
>
> Hello Postman team, We are using Postman to automate a broad number of requests. Sometimes we need to query an API programmatically, wait for its response, process it, and then proceed depending on what we have received. Most of the time these types of checks and requests are best made programmatically and do not warrant another request to be made in the collection as it is to be considered a dummy request and right now we have a lot of them for other reasons, so adding more is not an option as…

---

_[View the full topic](https://community.postman.com/t/pm-variables-inside-sendrequest-handler-not-available/26439)._
