# Concat/Edit/Manipulate Variables in Pre-request Script

**URL:** <https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [July 25, 2019, 2:52pm UTC](https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766 "2019-07-25T14:52:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidbeinhart](https://avatars.discourse-cdn.com/v4/letter/d/dbc845/32.png) [@davidbeinhart](https://community.postman.com/u/davidbeinhart)\
**Post date:** [July 25, 2019, 2:52pm UTC](https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766/1 "2019-07-25T14:52:03Z")

</div>

**Describe the bug**  
I’d like to combine several variables.  
I have a series of requests that GET information and I’d like to combine several of them to be used in a POST. However, when I concat the variables or otherwise try to use it, the result is a string of the variable names, and not their values. ex. {{Var1}} {{Var2}} {{Var3}}

**To Reproduce**  
Steps to reproduce the behavior:

1. Collect several environment variables, these variables all work on their own and in different contexts. **(Note:** I’ve successfully used these variables separately, it’s combining them that is creating the problem)
2. In Pre-request Script add the variables: Option 1) let string = “{{Var1}}” + “{{Var2}}” or Option 2) using concat (note must have “” around variable otherwise I receive an error about the {}'s matching.
3. Check value of new string is updated correctly.
4. Sadness.

**Expected behavior**  
I’d like to be able to add variables so that if Var1= A, Var2 = B and Var3 = C in a Pre-request Script or Tests I could set Var4 to be {{Var1}}+{{Var2}}+{{Var3}} and get “ABC” and not {{Var1}}{{Var2}}{{Var3}}

**App information (please complete the following information):**

- App Type [Native App]
- Postman Version [e.g. 7.3.4]
- OS: [Windows 10]

Thanks!

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [July 26, 2019, 4:58pm UTC](https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766/2 "2019-07-26T16:58:00Z")

</div>

You don’t use `{{ }}` in the Pre-request and Test scripts.

You have to use the `pm` object to retrieve and set variables

```
let a = pm.environment.get('A');
let b = pm.environment.get('B');
let c = pm.environment.get('C');

d = a + b +c; 

pm.environment.set('D',d);

```

> **[Process data and script workflows using Postman JavaScript objects | Postman...](https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/)**
>
> Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.

The Sandbox is also opensourced if you want to take a look at it.

> **[GitHub - postmanlabs/postman-sandbox: Sandbox for Postman Scripts to run in Node.js or...](https://github.com/postmanlabs/postman-sandbox)**
>
> Sandbox for Postman Scripts to run in Node.js or browser

---

<div class="post-metadata">

**Author:** ![aamir.ahmed](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@aamir.ahmed](https://community.postman.com/u/aamir.ahmed)\
**Post date:** [July 26, 2019, 4:58pm UTC](https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766/3 "2019-07-26T16:58:07Z")

</div>

HI @davidbeinhart,

You can access environment variables like so: {{Var1}} only on the Request path area and not in the test scripts. If you would like to access environment variables in a test script you would need to fetch the environment variable as so:  
Var1 = pm.environment.get(“Var1”);

You can click on “Get an environment variable” code snippet on the right side of the Test scripts area to get the syntax right. After that, you can manipulate the data as you wish. Reference docs given here:[https://learning.getpostman.com/docs/postman/environments\_and\_globals/variables\_complete\_reference/](https://learning.getpostman.com/docs/postman/environments_and_globals/variables_complete_reference/)

---

<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:** [July 26, 2019, 7:25pm UTC](https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766/4 "2019-07-26T19:25:41Z")

</div>

You could also do that like this but either way would work 🙂

```
let concatString = `${pm.environment.get('A')} ${pm.environment.get('B')} ${pm.environment.get('C')}`

pm.environment.set('concatString', concatString);

```

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [July 26, 2019, 7:33pm UTC](https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766/5 "2019-07-26T19:33:26Z")

</div>

**+1** for template literals my favvvvv 😍

---

<div class="post-metadata">

**Author:** ![davidbeinhart](https://avatars.discourse-cdn.com/v4/letter/d/dbc845/32.png) [@davidbeinhart](https://community.postman.com/u/davidbeinhart)\
**Post date:** [August 1, 2019, 1:31pm UTC](https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766/6 "2019-08-01T13:31:13Z")

</div>

Thank you all for the comments! This was very helpful.

---

<div class="post-metadata">

**Author:** ![shriduttkothari](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/shriduttkothari/32/5286_2.png) [@shriduttkothari](https://community.postman.com/u/shriduttkothari)\
**Post date:** [August 17, 2020, 2:25pm UTC](https://community.postman.com/t/concat-edit-manipulate-variables-in-pre-request-script/6766/7 "2020-08-17T14:25:16Z")

</div>

Thanks for this approach !!
