Collection driven by csv - how to skip to end of collection

Collection driven by csv - how can I skip to end of an iteration and continue onto the next row in csv?

For illustrative purposes, I am simplifying the actual logic of the collection.

I have a collection with a bunch of requests. The csv file has a column called “Flow” with 3 potential values:
A - execute the first 5 requests and then skip to the end (move on to the next row in the csv and start the next iteration)
B - execute the first 5 requests (the ones run in Flow A) PLUS the next 6 requests, and skip to the end (move on to the next row in the csv and start the next iteration)
C - execute all the requests

It’s the “skip to the end (move on to the next row in the csv and start the next iteration)” that I’m having trouble with. This particular collection has cumulative flows - you can do flow A, A+B, or A+B+C. It would be very convenient to be able to skip to the end based on the selected flow.

I use postman.setNextRequest() throughout the collection for skipping a request here and there as needed. But is there a way to force skipping to the the next iteration of the collection with the next row in the csv?

I have considered the possibility of adding in an extra harmless request at the very end of the collection and naming it “final” so that I can do postman.setNextRequest(“final”). Thoughts on this as a solution?

  • Platform Details: Postman for Windows
    Version
    11.9.2
    UI version
    11.9.2-ui-240822-1348

Desktop platform version
11.9.0

Architecture
x64

I think I may have found the answer:
pm.execution.setNextRequest(null);

Hi @tzirel613.

pm.execution.setNextRequest(null) will terminate the workflow and no request will be ran after it. We have a pm.execution.skipRequest() API that skips the current requests and you can use that to skip specific request based on certain conditions.

Thank you so much for your reply! I didn’t want to have to put in the “if” in the script of every single request Which was why I thought that pm.execution.skipRequest() might not be a good solution for me.

pm.execution.setNextRequest(null) sounds like the correct method to achieve your goal. It will terminate the current workflow\iteration, and your next iteration should start.

You would need one in the post-response script for the 5th request for scenario A. If flow=a then setNextRequest(null). The condition doesn’t need to mention B or C.

Another one in request 11 to cover scenario B. If flow=b. The condition doesn’t need to mention A or C. If scenario A was triggered on request 5, you would never get to this request.

You don’t really need conditional checks for C, as that is going to execute all requests.

1 Like

Thank you so much! I am glad that this will work the way I had hoped! Trying it out now.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.