Show content of variable in console log

Hi there

I like to have an output of a created variable who is actually using the result of another variable but i do not get the value that i want in the console log. I already tried with 2 different variables but then i receive both values in the following format “Test-” “1234”.

Here is what i have in me pre-request script:

pm.environment.set(“transactionIdNr”, pm.variables.replaceIn(’{{$timestamp}}’));
pm.environment.set(“transactionId”, “Test-{{transactionIdNr}}”);

console.log(pm.environment.get(‘transactionId’));

And here is what i get:

Test-{{transactionIdNr}}

I would expect:

Test-1615466972

In the request body himself, i got the right value of the variable, the issue is just to get it in the console!

Thanks a lot for your help

Greetings BeeGee

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Hey @beegee3235 :wave:

As you’re saving the environment variable as a string, directly logging that variable to the console, will display that string value.

pm.environment.set(“transactionId”, “Test-{{transactionIdNr}}”);

The request body is resolving the environment variable correctly, as that already knows how to handle the {{}} syntax that’s part of that string.

To log the correctly resolved environment value, you can use the same .replaceIn() method that you used to set the {{$timestamp}} value.

console.log(pm.environment.replaceIn('{{transactionId}}'));

3 Likes

Thanks Danny!

Works perfectly well!

You’re such a help!

Have a good day!

Greetings Benjamin

1 Like