How to reset variables to initial value from script

Add this to first request’s pre-request script:

 pm.environment.set("resetValue",pm.collectionVariables.toJSON().values)

This wiil store all initial value to resetValue variable

And in the last request’s test script use

pm.environment.get("resetValue").forEach((a)=>pm.collectionVariables.set(a.key,a.value))

Now we are resetting all collectionVariables to the initially saved value

1 Like