Creating a workflow with postman.setNextRequest("..");

Hi all,

In the following Topic Improve postman.setNextRequest() suggestions were made to improve the postman.setNextRequest() function. I am yet to find any documentation on improvements that have been made ( I might have not used the right search terms). Anyhow I have stumbled upon a problem of my own using the postman.setNextRequest() function.

Problem encountered
In my collection I have made several folders with one or multiple requests. When I want to run the postman runner not all the folders have to be run. To save time and having to take folders out or comment everything I have tried using the function to build a workflow. I have placed the function in the pre-request Script of the folder in order to have the folder after the one containing the function to be skipped, like following:
folder A request A1, A2
folder B {pre-req: postman.setNextRequest(“req d1”}, request B1, B2
folder C, request C1, C2
folder D, request D1, D2

I expect the requests in folder B to be executed then to have folder C and his requests to be skipped and the workflow to continue with the first request in folder D.

However in my case
postman executes request B1
skips B2 unexpected
skips folder C and his request and continues in folder D with request D1 as expected

Screenshots and workflow
See following screenshots for the acts I preformed.

This is the first folder where I have applied the setNextRequest function with a simple log so I can read in the console which folders are not executed.

This is the second folder where I have applied the same as explained at the first screenshot.

This is the workflow I get due to the use of the setNextRequest function. In the pre-req of the folder ‘Webshop retrieval’ I have the setNextRequest(“alle artikelgroepen”); The ‘Swagger webshop ophalen’ gets executed and the two folders aanbod and artikel are skipped and the workflow enters the folder Artikelgroep.

In this folder (Artikelgroep) I have the setNextRequest(“Alle fusten”). The first request in the folder gets executed as set, but the second one (Specifieke artikelgroep) gets skipped and the workflow continues as draw.

I need the second request within the folder to get executed as well. Does anyone has a solution on how to achieve that?

I hope it is clear enough to follow!

Hi, Palmju.

Yes, the way you have it set up, B2 will be skipped.

Folders are a great way to sort your calls into workflows, but it doesn’t effect the setNextRequest() flow. So imagine you had no folders and your setNextRequest() call was in the pre-request script of B1. Then of course you would expect D1 to be called after B1. With the setNextRequest() in the folder, you are telling postman you want D1 to be called after every call in that folder.

In fact, the way you have it now, I would expect this sequence:
B1 -> D1 -> B2 -> D1 -> C1 -> C2 -> D1 -> D2

To get B1 -> B2 -> D1, you will need to place the setNextRequest() call to D1 either in the pre-request of B2 or at the end of B2’s tests. Either place. Then, this will be your sequence.
B1 -> B2 -> D1 -> C1 -> C2 -> D1 -> D2

Makes sense?

Hi @wendy.cook ,

Thank you for your reply! I have tried both your suggestions, however in both scenarios the setNextRequest script doesnt get executed.
Also within the sequence the folder C and its request should not be executed.

Folder A holds setNextRequest (D1), Folder D holds setNextRequest(F1)
Expected sequence:
A + A1 -> D + D1 + D2 -> F + F1 + F2

Actual sequence:
A+ A1 -> D + D1 -> F + F1 +F2

In the last screenshot you will see the sequence/workflow and it should be read as ‘Webshop retrieval’ = A, ‘Swagger webshop ophalen’ = A1.
This should make it more readable!

Hi @Palmju,

Hope I am understanding this correctly, but you wish to execute B1, B2 and then skip to request D1.
If that is the case, you would need to add the postman.setNextRequest("req d1") command in the Tests tab of B2 as you want the B2 request to be executed.
A postman.setNextRequest("req d1") in the pre-request script of B2 is executed before the B2 request which is why the runner skips the B2 request.
To clarify the flow of each request in a collection
Pre-Request Script -> Request -> Tests

Here is further documentation for building workflows:

Hi @aamir.ahmed ,

Thank you for your reply! With my understanding of the link you have provided, the setNextRequest command is limited to the requests within the folder. In other words, if I add the setNextRequest command in the Test tab of B2 it will not be executed. I have tried your suggestion but with no succes.

Extra note, the setNextRequest is added in the pre-request script tab of the folder containing B1 and B2. The command gets executed after request B1 is executed, and then moves on towards D1. Excluding B2 from execution.

Hi @Palmju - As you said, setNextRequest() will set the next request to be called and does not affect the current request, so placing setNextRequest() under the Tests tab is typical, especially if the next request to call is dependent on the response of the current call.

And as @wendy.cook said, adding the pre-request script at the folder-level will execute that script prior to every request within that folder - not just before the folder runs as I believe you’re assuming. Since you’ve set the pre-request script on folder B, B2 will never get called because you’ve already set the order to call D1 whilst running B1 in the folder-level pre-request script. As @aamir.ahmed suggested, you can set your next request in the Tests tab of B2 (instead of a folder-level script on Folder B).

See docs about script execution order.

Hi @joyce ,

Thank you for your reply! With your extra explanation I now have better understanding of what @wendy.cook was explaining. That is exactly what I was assuming because B1 was running, i had thought that B2 would also be called. However that is not the case.

I have given the suggestion of @aamir.ahmed server tries but to no succes. With the command to set my next request in the Test tab of B2, B2 does get called but request D1 that I have set to be the next request doesn’t because the runner continues with C1 instead of skipping that request.

If the sequence I want to run needs more explanation just let me know!

Hi @Palmju,

If you wish to move from request ‘Swagger webshop ophalen’ to request ‘Alle artikelgropen’, as @joyce suggested you would add the following test script in the Tests tab of ‘Swagger webshop ophalen’ request
postman.setNextRequest(“Alle artikelgropen”)

There is no limitation in terms of moving across folders, you can move and skip across any number of folders as long as they are in the same collection. Attached screenshots for further clarification.

As you can see I have skipped across the branches folder in the collection using postman.setNextRequest command. Hope that helps


hi @aamir.ahmed,

I have added the test script to the Tests tab of the ‘Swagger webshop ophalen’ request as you said and in the collection runner I can see that it doesn’t provide the desired effect. This because the folders that are supposed to be skipped are being executed.
However if I add the test script in the pre-request script tab of the folder containing the ‘Swagger webshop ophalen’ request I do get the desired effect as the folders ‘Aanbod’ and ‘Artikel’ are not executed and the folder ‘Artikelgroep’ containing the ‘Alle artikelgroepen’ is executed. See screenshots.

In the above screenshot I have done what you suggested and added the testscipt to the Test tab of the ‘Swagger webshop ophalen’ request.

That led to this result (as seen above) where the two folders and requests that are not supposed to be executed get ran.

However if the test script gets added to the pre-request script tab of the folder ‘Webshop retrieval’ (containing the ‘Swagger webshop ophalen’ request), I can achieve the desired effect.

For as you can see here, the ‘Swagger webshop ophalen’ request gets executed, the pre-request script in his parent folder ‘Webshop retrieval’ gets ran and the two folders ‘Aanbod’ and ‘Artikel’ do not get executed. And the collection runner executes ‘Alle artikelgroepen’ how I want.

The issue arises when at the folder ‘Artikelgroep’ (B) with the requests ‘Alle artikelgroepen’ (B1) and ‘Specifieke artikelgroep’ (B2) need to be ran. Folder ‘Betaalevent’ © has to be skipped and folder ‘Fust’ (D) with requests ‘Alle fusten’ D1 and ‘Specifieke fust’ D2 need to be ran. See screenshot below.

I hope this clears things up as to what I already have done, the suggestions in the replies I have tried and what I want to achieve.

Hi @aamir.ahmed,

Regarding your last reply i would like to inform that it worked! Due to my focus on getting my problem fixed I payed little attention to the fact that i had to save my request after adding the test script to the Tests tab.
Because i added the setNextRequest to the Tests tab and send it without saving, the changes were not registered and therefor were not executed. A simple save and send showed me the succes i was looking for.

Thank you very much for your help!

Glad to hear :smiley: @Palmju

Do you know how I can skip a row in csv if the a specific row cell is null