# Executing postman.setNextRequest from collection tests

**URL:** <https://community.postman.com/t/executing-postman-setnextrequest-from-collection-tests/18103>\
**Category:** Help Hub\
**Tags:** tests, collections, folders\
**Created:** [November 30, 2020, 7:30am UTC](https://community.postman.com/t/executing-postman-setnextrequest-from-collection-tests/18103 "2020-11-30T07:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shodhansave](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@shodhansave](https://community.postman.com/u/shodhansave)\
**Post date:** [November 30, 2020, 7:30am UTC](https://community.postman.com/t/executing-postman-setnextrequest-from-collection-tests/18103/1 "2020-11-30T07:30:55Z")

</div>

Hello there,

I have a collection in which i need to abort the entire run when any test fails. While searching about this, I came across the `postman.setNextRequest(null)` hack. Instead of adding this in each test, I thought of having a function in the collection’s test and simply call that function each time.  
Accordingly, I wrote the below:

```
utils = {
    check_abort: function(is_failure){
        if (is_failure){
            postman.setNextRequest(null);
        }
    }
};

```

And in each test, I set the `is_failure` and call `utils.check_abort`. Now the call goes into the function, but the execution does not stop on that request, it goes ahead.

On the other hand, if I write this in the request’s test itself, the execution stops:

```
if (is_failure){
    postman.setNextRequest(null);
}

```

I am not sure what am i missing here.  
I just need an elegant way of stopping runs when even a single test fails.

Thanks you.

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 2, 2021, 7:43am UTC](https://community.postman.com/t/executing-postman-setnextrequest-from-collection-tests/18103/2 "2021-01-02T07:43:12Z")

</div>

Are you using newman ? If so there is a --bail flag

Could you also add your code on how you are callign the function from the script

---

<div class="post-metadata">

**Author:** ![shodhansave](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@shodhansave](https://community.postman.com/u/shodhansave)\
**Post date:** [January 12, 2021, 3:55pm UTC](https://community.postman.com/t/executing-postman-setnextrequest-from-collection-tests/18103/3 "2021-01-12T15:55:09Z")

</div>

Yes I came across the `--bail` flag… originally i wanted to do it in Postman instead of Newman. But nevermind, i will be using Newman itself, so this works!

Thanks! ✌🏼
