# postman.setNextRequest not working

**URL:** <https://community.postman.com/t/postman-setnextrequest-not-working/14820>\
**Category:** Help Hub\
**Tags:** collections, scripts, collection-runner\
**Created:** [August 7, 2020, 5:20pm UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820 "2020-08-07T17:20:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![CryptoAngel](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@CryptoAngel](https://community.postman.com/u/CryptoAngel)\
**Post date:** [August 7, 2020, 5:20pm UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/1 "2020-08-07T17:20:47Z")

</div>

Hello,

I have this GET and POST in same collection and even in the same folder.  
At the end of GET tests I call the POST using this postman.setNextRequest(“EmailNotifier”);  
but nothing happen, it doesn’t run the POST for sure (just to make clear, when I manually run it is working fine).

What I am missing here using the setNextRequest ?

Thank you

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 7, 2020, 5:28pm UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/2 "2020-08-07T17:28:34Z")

</div>

Hey @CryptoAngel

Unfortunately, without the rest of the code that you have, that line alone is a bit meaningless.

Could you provide the rest of the script and details of the rest of the collection please. The raw code would be better than a picture of it.

Before doing that, could you confirm that that you have no unsaved changes in the requests that you have open for that collection? The collection Runner won’t know about changes to the request unless you save it before the run.

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [August 7, 2020, 6:15pm UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/3 "2020-08-07T18:15:21Z")

</div>

In addition to what @danny-dainton said, if you’re just running the request out of the app, setNextRequest isn’t going to do anything.

`postman.setNextRequest ` is going to tell the _collection runner_ what the next request is to execute. If you’re not running a collection, it will do nothing.

Also, make sure that the value you have as the argument in setNextRequest is the name of the request you want to run.

---

<div class="post-metadata">

**Author:** ![CryptoAngel](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@CryptoAngel](https://community.postman.com/u/CryptoAngel)\
**Post date:** [August 7, 2020, 11:55pm UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/4 "2020-08-07T23:55:19Z")

</div>

Thank you for your comment

> [@allenheltondev](#):
>
> f you’re just running the request out of the app, setNextRequest isn’t going to do anything

I am the request from MacOS app but still it doesn’t work. I’m not using the Runner just manually click on the button to run it.

The setNextRequest is the only thing on the Tests and the name is correct.

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [August 8, 2020, 12:59am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/5 "2020-08-08T00:59:28Z")

</div>

Then that is your problem. If you run a request manually it will run one and only one request.

pm.setNextRequest is a collection runner command.

---

<div class="post-metadata">

**Author:** ![CryptoAngel](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@CryptoAngel](https://community.postman.com/u/CryptoAngel)\
**Post date:** [August 8, 2020, 1:16am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/6 "2020-08-08T01:16:39Z")

</div>

Oh I see. Alright.  
There’s no command line to call another request without the runner?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [August 8, 2020, 12:53pm UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/7 "2020-08-08T12:53:23Z")

</div>

No there isn’t. You could possibly call another request via the javascript in the tests section, but I don’t think that’s a very good workaround because the collection runner does this for you already.

---

<div class="post-metadata">

**Author:** ![CryptoAngel](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@CryptoAngel](https://community.postman.com/u/CryptoAngel)\
**Post date:** [August 8, 2020, 1:25pm UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/8 "2020-08-08T13:25:42Z")

</div>

But to check if it’s working I need to run the Runner instead of clicking the button.  
And anyhow, I added single line postman.setNextRequest(“EmailNotifier”); in the first request “Tests” and I ran the Runner but still nothing happened, it did not run the second request “EmailNotifier”

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 8, 2020, 7:06pm UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/9 "2020-08-08T19:06:43Z")

</div>

Are you able to show us an image of what that flow looks like, what those requests look like, the names of the requests and what is the saved state of each one.

By not _showing_ people what you have in front of you - saying “I doesn’t work” is not going to help 🙂

Worth reading this doc from our learning center and the points at the bottom as some might be relevant to what you’re seeing here.

[https://learning.postman.com/docs/running-collections/building-workflows/](https://learning.postman.com/docs/running-collections/building-workflows/)

---

<div class="post-metadata">

**Author:** ![ngeeta123](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@ngeeta123](https://community.postman.com/u/ngeeta123)\
**Post date:** [November 24, 2023, 6:49am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/10 "2023-11-24T06:49:19Z")

</div>

Can anyone please help me to do this  
I want to run 1 common request after each request but here only 1st request followed by common req is running.

I want `Req_1` then common, then `Req_2` then common then `Req_3` then common, then `Req_4` then common.

Inside test of Req\_1/2/3/4 I have below:

```auto
if(Success){
postman.setNextRequest('Common');
}
else{
postman.setNextRequest(null);
}

```

but after running collection I got output as Req\_1 and Common (2 req)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 24, 2023, 7:00am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/11 "2023-11-24T07:00:02Z")

</div>

Hey @ngeeta123 👋

Welcome to the Postman community! :postman:

Can you provide your actual code and images of what you have in the app, please?

Without all the information, it’s difficult for anyone to suggest what might be the problem.

Ensure that all requests are saved as unsaved changes wouldn’t reflect in an existing Collection Run.

---

<div class="post-metadata">

**Author:** ![ngeeta123](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@ngeeta123](https://community.postman.com/u/ngeeta123)\
**Post date:** [November 24, 2023, 7:36am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/12 "2023-11-24T07:36:17Z")

</div>

Hey danny,  
Check below image,

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/b/bb17d8f5007d72f17fa51a9c1899cfd530077db9.png)

and below script in all Req

```auto
let jsonData=pm.response.json();

if(jsonData){
    postman.setNextRequest('Common');
}
else{
     postman.setNextRequest(null);
}

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 24, 2023, 7:51am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/13 "2023-11-24T07:51:06Z")

</div>

What’s not working?

Your conditional statement is evaluated to true in the first request (because it’s basically checking that you have a response body) and then it’s going to the Common request.

---

<div class="post-metadata">

**Author:** ![ngeeta123](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@ngeeta123](https://community.postman.com/u/ngeeta123)\
**Post date:** [November 24, 2023, 7:54am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/14 "2023-11-24T07:54:30Z")

</div>

Correct but I want Req\_2 also execute followed by common.then req\_3 followed by common and then req\_4 followed by common.  
this is working on only Req\_1

Inshort after running collection, I want 8 request should execute

Req\_1  
Common  
Req\_2  
Common  
Req\_3  
Common  
Req\_4  
Common

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 24, 2023, 7:57am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/15 "2023-11-24T07:57:30Z")

</div>

It’s working that way because it’s going to the Common request and then, as that’s the final request in the Collection, it’s ending the run.

You would need to add logic to the Common request to direct it back to the other requests if that’s what you want to do.

Without something telling it to go to the other requests, how would it know to do that.

---

<div class="post-metadata">

**Author:** ![ngeeta123](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@ngeeta123](https://community.postman.com/u/ngeeta123)\
**Post date:** [November 24, 2023, 8:23am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/16 "2023-11-24T08:23:21Z")

</div>

thats the logic I want how to implement

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 24, 2023, 9:15am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/17 "2023-11-24T09:15:46Z")

</div>

What have you tried so far?

Do you need to do it that way or would having an async call using `pm.sendRequest()` to that Common request, from the Tests tab work here?

Basically, it’s all example code at the moment and I have no idea what those requests are actually doing and why you need to keep hitting that Common request each time.

I’ve removed your same comment/question on the other topic, that was last active 3 years ago and you created this one for the same thing. Your question should have ideally been it’s own topic and not piggybacking on something that’s not exactly related.

---

<div class="post-metadata">

**Author:** ![ngeeta123](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@ngeeta123](https://community.postman.com/u/ngeeta123)\
**Post date:** [November 24, 2023, 9:26am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/18 "2023-11-24T09:26:43Z")

</div>

I want the logic to run common request after each request thats it.  
any method or logic will be ok.  
If you can help me with any other option plz help.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 24, 2023, 10:19am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/19 "2023-11-24T10:19:00Z")

</div>

I will take a closer look today and create a reusable solution.

This is a common question that pop up a lot and should have it’s own demo Collection in the [Postman Answers Workspace](https://www.postman.com/postman/workspace/postman-answers).

I know that @michaelderekjones might have a quick solution around this in the short term and he’s very familiar with the `setNextRequest()` logic.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [November 24, 2023, 11:40am UTC](https://community.postman.com/t/postman-setnextrequest-not-working/14820/20 "2023-11-24T11:40:27Z")

</div>

I can think of two options.

Put the four requests in a folder or collection, and then add the common request into the tests tab of the folder or collection using sendRequest(). It’s more code, but isn’t that the essence of why you have a tests tab/pre-request scripts at the collection, folder and request level.

No setNextRequest involved. This will run after every request in the folder.

Option 2 would be to track the next request to be run after the common request in the tests tab of each of the requests.

So in Req-1, you would save an collection variable with the value of the Req\_2 name and then use setNextRequest in Req-1 to call the common request.

In Req-2, you would update the value to show the Req-3 name.

In the tests tab of the common request, you would retrieve the previously saved variable and use that to drive the setNextRequest().

For request 4, you would set the value of this variable to “null” to end the flow.

Personally, I would recommend an update to setNextRequest() or a new feature that allows you to set the next two requests. Or a flag, that if set will allow you to call another request once and then continue running the tests in the current folder or collection. The first option would probably be easier to implement but the second would be more user friendly.

The idea here is that re-usable code or requests is a key factor for a lot of automated testing frameworks. If you have dozens of collections that use the same request\feature. You only need to update it in one place. Its one thing that Postman is missing as a concept.

[Next page](https://community.postman.com/t/postman-setnextrequest-not-working/14820.md?page=2)
