I’ve been pouring through google and and the documenation for days but I can’t get this to work.
This is my most simple example. In my Post-response block I have only these lines:
console.log(“CALLING pm.execution.setNextRequest(null);”);
pm.execution.setNextRequest(null);
I run my collection and set the iterations to 3, and when it runs it outputs the console message but all 3 iterations execute, even though they should stop.
The official documentation says:
To stop a workflow, add the following code on the Scripts > Post-response tab of a request:
pm.execution.setNextRequest(null);
The collection run will stop after Postman completes the current request.
However it just doesn’t stop.
My actual goal here is to have the collection run 10 times with an variable incrementing from 1 to 10, but if we have a status code that is not 201 I want the collection to stop executing. The example above is a very simplistic one, showing that Postman just isn’t working as per the docs.
Am I missing something? Are collection runs not the right way to do it - should I run the collection once and instead have a for loop in the script or something?
Log snippet from 3 runs:
GET https://community.postman.com/?test=1
CALLING pm.execution.setNextRequest(null);
GET https://community.postman.com/?test=1
CALLING pm.execution.setNextRequest(null);
GET https://community.postman.com/?test=1
CALLING pm.execution.setNextRequest(null);
I’ll attach a screesnhot if I can.
Thanks