postman.setEnvironmentVariable no longer supported?

After updating to the latest version of Postman my method of capturing a value from a response no longer seems supported. I’m trying to capture a GUID value from module that has been created from server response.

This is what I had been using in the Tests tab before Postman changed it to the “Scripts” tab and it was working:

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("ProposedInsuredGUID", jsonData.modules["Life Parties RM"].moduleIndexes[0].moduleGuid);

After the update when making this call I’m getting this error in the Console:

“Using “postman.setNextRequest” is deprecated. Use “pm.execution.setNextRequest()” instead.”

I thought .setNextRequest() was used to change the order of the calls not set a variable?

Hey @IFS-QA :wave:

Welcome to the Postman Community! :postman:

This syntax had been replaced by the pm.* set of functions in version 5. This older syntax was supported but will be removed from the sandbox in the upcoming major versions.

Your code would look like this with the newer syntax:

var jsonData = pm.response.json();
pm.environment.set(“ProposedInsuredGUID”, jsonData.modules[“Life Parties RM”].moduleIndexes[0].moduleGuid);

Same with the postman.setNextRequest function. It’s the same function name, it’s just being called from a different location.


Thank you Danny but when running the new syntax Postman is flagging me for something using that syntax see the circled red bar and the console is complaining about all kinds of deprecated stuff.

You’ll need to ensure that you’re using the correct quotes. The copy and paste from here more than likely changes the formatting.

From the warnings in the console, it looks like you have multiple places that will need bringing up to date to use the new syntax.

Thx Danny you’re right should have known better on copy and paste! Thx for the help - kind of a bummer they deprecated that syntax - I’ve got it all over the place :grimacing:

No worries. Happy to help.

The syntax was out of date from version 5 which is 5+ years ago. It was always going to be deprecated.

The warnings seen in the console are exactly that, they are warning to make people aware well in advance that those older functions will stop working and migrating to the newer syntax is the way forward.

I would recommend creating a fork and possibly using find and replace in the app to make the changes before testing that out and merging your changes back.

The functionality hasn’t changed it’s just the names are slightly different.

1 Like