# How to set and get dynamic environmental variable?

**URL:** <https://community.postman.com/t/how-to-set-and-get-dynamic-environmental-variable/7482>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [August 28, 2019, 2:29pm UTC](https://community.postman.com/t/how-to-set-and-get-dynamic-environmental-variable/7482 "2019-08-28T14:29:40Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [August 29, 2019, 10:16am UTC](https://community.postman.com/t/how-to-set-and-get-dynamic-environmental-variable/7482/4 "2019-08-29T10:16:22Z")

</div>

In the version `7.6.0`, which is currently on the Canary Channel but soon to be released, you can achieve this by using the new `replaceIn()` function.

I modified your code slightly to add this new feature in there:

```
pm.environment.set("employeeName", getRandomName());

function getRandomName() {
    const employeeName = pm.variables.replaceIn("{{$randomFirstName}}");
    return employeeName;
}

```

 ![28](https://us1.discourse-cdn.com/getpostman/original/2X/d/da0a6298ac466f978675ff4c10bf35798b2689e6.png)

Or you could just get rid of that function and do it in one line 🙂

`pm.environment.set("employeeName", pm.variables.replaceIn("{{$randomFirstName}}"));`

---

_[View the full topic](https://community.postman.com/t/how-to-set-and-get-dynamic-environmental-variable/7482)._
