# The ability to set the data from the console log as a variable for the next request

**URL:** <https://community.postman.com/t/the-ability-to-set-the-data-from-the-console-log-as-a-variable-for-the-next-request/32101>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [February 1, 2022, 11:26am UTC](https://community.postman.com/t/the-ability-to-set-the-data-from-the-console-log-as-a-variable-for-the-next-request/32101 "2022-02-01T11:26:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikolay.ivanov](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@nikolay.ivanov](https://community.postman.com/u/nikolay.ivanov)\
**Post date:** [February 1, 2022, 11:26am UTC](https://community.postman.com/t/the-ability-to-set-the-data-from-the-console-log-as-a-variable-for-the-next-request/32101/1 "2022-02-01T11:26:57Z")

</div>

Hello ! May be someone can help me)

What i want:

1. I have a collection variable on `POST/ request`

```auto
{ "Amount": .....,
    "Id": ........,
    "customerId": "{{$randomUUID}}",
  }

```

1. To cath the value of this variable to use it in the next POST request i need to log it in console so i have used script:

```auto
const requestJson = pm.request.toJSON();
pm.collectionVariables.set('aRequestAsJson', JSON.stringify(requestJson));
const x = JSON.parse(pm.collectionVariables.get('aRequestAsJson'));
console.log(JSON.parse(x.body.raw).customerId);

```

and the UUID that were used in request body is successfully logged in my console  
and presented as :

```auto

POST https://............
"fb8c4dd4-5e31-4620-b94f-849dffb0d2fd"

```

But how can i set that console data(i mean `fb8c4dd4-5e31-4620-b94f-849dffb0d2fd`) as a collection variable to use in my next `POST/ request` ?

I trying something like that:

```auto
const requestJson = pm.request.toJSON();
pm.collectionVariables.set('aRequestAsJson', JSON.stringify(requestJson));
const x = JSON.parse(pm.collectionVariables.get('aRequestAsJson'));
console.log(JSON.parse(x.body.raw).customerId);
pm.collectionVariables.set("UuidForTheNextPostRequest", (x.body.raw).customerId);

```

but it doesnt works(

---

<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:** [February 1, 2022, 12:34pm UTC](https://community.postman.com/t/the-ability-to-set-the-data-from-the-console-log-as-a-variable-for-the-next-request/32101/2 "2022-02-01T12:34:02Z")

</div>

I’ve created this Collection as an example of using the `pre-request` to set and store the random value. This can then be used in other requests.

[https://www.getpostman.com/collections/06fb7486cd2dcd743645](https://www.getpostman.com/collections/06fb7486cd2dcd743645)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [February 1, 2022, 12:36pm UTC](https://community.postman.com/t/the-ability-to-set-the-data-from-the-console-log-as-a-variable-for-the-next-request/32101/3 "2022-02-01T12:36:37Z")

</div>

@dannydainton Interesting, I’ve not used pm.variables.replaceIn yet, is there anywhere that explains the use options? Cheers

---

<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:** [February 1, 2022, 12:44pm UTC](https://community.postman.com/t/the-ability-to-set-the-data-from-the-console-log-as-a-variable-for-the-next-request/32101/4 "2022-02-01T12:44:24Z")

</div>

The learning center explains most things - If it doesn’t we can change that 😃

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

> **[Postman JavaScript reference | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-variables-in-scripts)**
>
> Postman JavaScript reference: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

---

<div class="post-metadata">

**Author:** ![nikolay.ivanov](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@nikolay.ivanov](https://community.postman.com/u/nikolay.ivanov)\
**Post date:** [February 1, 2022, 2:47pm UTC](https://community.postman.com/t/the-ability-to-set-the-data-from-the-console-log-as-a-variable-for-the-next-request/32101/5 "2022-02-01T14:47:43Z")

</div>

Wow, great solution ! Thanks a lot !
