# Query variable from within Pre-request script

**URL:** <https://community.postman.com/t/query-variable-from-within-pre-request-script/20502>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [February 17, 2021, 4:10pm UTC](https://community.postman.com/t/query-variable-from-within-pre-request-script/20502 "2021-02-17T16:10:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tylerwilson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tylerwilson](https://community.postman.com/u/tylerwilson)\
**Post date:** [February 17, 2021, 4:10pm UTC](https://community.postman.com/t/query-variable-from-within-pre-request-script/20502/1 "2021-02-17T16:10:38Z")

</div>

Good day,

I am writing a collection-level script that will dynamically generate a signature based on all the query params. The issue is that if I use a dynamic variable in the request, it is not getting replaced with the current value. For example, the request is defined like so:

![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/8/580b283f8848273d28b24d295e3afdc3f745174a.png)

where companyId is saved in the login request. I then access via the pre-request script like so:

```
    pm.request.url.query.all().forEach((param) => {
        console.log(param);
    });

```

and it comes back like so:

{key: “p\_com\_id”, value: “{{companyId}}”}

But I need that value to come back replaced with the current value. Any way to do this?

Note that I cannot hard-code or get via pm.environment because each call may use a slight variation on the key name. Perhaps I could check for {{xxx}} and do a lookup that way - any examples of this?

Thank you,  
Tyler

---

<div class="post-metadata">

**Author:** ![tylerwilson](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tylerwilson](https://community.postman.com/u/tylerwilson)\
**Post date:** [February 18, 2021, 7:46pm UTC](https://community.postman.com/t/query-variable-from-within-pre-request-script/20502/2 "2021-02-18T19:46:58Z")

</div>

Okay, to answer my own question: I initially wrote a method that looked for the {{}} in the name, and then call the pm.variables.get.

But then I discovered the pm.variables.replaceIn() method, which will look up the value for me, or simply return back the passed in value. This is exactly what I needed.

Thank you.
