In a Mock service, only the Initial variable is always used but I need the Current value

Postman version 9.21.2

Use a Mock service.

GET request

Situation:

The incoming request has a field: QR

I store the value of QR via an environment variable (variable_QR) in this way:

let param = pm.request.url.query.toObject().QR;

pm.environment.set (“variable_QR”,param);

This goes well and is kept as Current value.

Then I fill the response with this variable (variable_QR)

“qr”: {{variable_qr}}

The big problem is that the Initial value comes into the response and not the Current value.

Is there a possibility/script to get the Current value in the response?

Or is it possible to update the Initial with the Current value via a script?

Or is there another solution?

I look forward to a solution.

Thanks

Victor

Hi @vvdkuij

I was trying to replicate your scenario but mine seems to pull in the current value not the initial.

Could you maybe provide some screenshots of what you have tried? and include the console log output too?

cheers.

Hi James, thank you for the comment.

These are the screenshots.

Postman version 9.19

Request gives a Response via Mock

Request:

<img width=“602” height=“135” style=“width:6.2708in;height:1.4062in” id=“Afbeelding_x0020_5” src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/getpostman/original/2X/1/1c9f0b7c769872024bb7b90ef80b30104eab4a32.png" alt="Afbeelding met tafel

Automatisch gegenereerde beschrijving">

<img width=“588” height=“89” style=“width:6.125in;height:.927in” id=“Afbeelding_x0020_4” src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/getpostman/original/2X/c/c1c54d7c9b35aef323cac0fd094756d185c6f820.png" alt="Afbeelding met tekst

Automatisch gegenereerde beschrijving">

Example Body:

<img width=“454” height=“216” style=“width:4.7291in;height:2.25in” id=“Afbeelding_x0020_3” src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/getpostman/original/2X/f/f4f4632f0f3d0c7d818b10efb6214b84c1eda52a.png" alt="Afbeelding met tekst

Automatisch gegenereerde beschrijving">

Executing the request fills the Current value:

Environment variables

<img width=“601” height=“101” style=“width:6.2604in;height:1.052in” id=“Afbeelding_x0020_2” src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/getpostman/original/2X/6/6c8d3a66e79ec8e6e7769604caf8993caf111d1a.png" alt="Afbeelding met tafel

Automatisch gegenereerde beschrijving">

But I get the Initial value in my response:

I want 111111;111111 (Current value) in the resposne and not 1234 (Initial value).

Ahhh I see now. Yeah, I don’t think you can pass ‘current’ variables to a mock server;
(If anyone wants to correct me on this, I’d be really intrigued by the solution).

There is a thread here with a similar scenario;

And in here they discuss;

That got me thinking along the right track and it ALL came clear 
 the current variables CAN’T be shared with the mock server cause they aren’t serialized or stored on the postman servers.

Ok, that’s clear
. very unfortunate.

Is there really no script that passes the value of a Current variable to an Initial varibale?