How to log variable value of environment variable

Hi there

I’ve a very basic question about logging of environment variables. I’ve defined 2 env. variables in my pre request script and both of them are well taken into the Body of my Post request. The only problem is that i can’t log both of the variables as I recieve always the error that the 2nd variable isn’t defined. I defined it in the environment AND in the pre-request script, but i can’t log it.

Can anybody help me with that…it’s certainly just a syntax error…

My pre-request script:

const transactionId = Math.floor((Math.random() * 100) + 1);

pm.environment.set(“transactionId”,transactionId);

pm.environment.set(“transactionIdEnv”, “BASKALT-”);

console.log(transactionIdEnv,transactionId);

In the console output i recieve “ReferenceError: transactionIdEnv is not defined” - When i delete the console entry or i delete just my env. variable transactionIdEnv in the brackets , the request is well generated and sent…?!

My goal is to have both values logged, one after the other (transactionIdEnv+transactionId)

Thanks a lot for your help!

Benjamin

To log out the environment variable, you would need to do this:

console.log(pm.environment.get('transactionIdEnv')) 

console.log(transactionId)

Thanks a lot Danny! Thats working pretty well…

Greetings Benjamin

1 Like