# setNextRequest is undefined?

**URL:** <https://community.postman.com/t/setnextrequest-is-undefined/67817>\
**Category:** Help Hub\
**Tags:** setnextrequest\
**Created:** [September 2, 2024, 7:53am UTC](https://community.postman.com/t/setnextrequest-is-undefined/67817 "2024-09-02T07:53:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aviation-observer-43](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/aviation-observer-43/32/9862_2.png) [@aviation-observer-43](https://community.postman.com/u/aviation-observer-43)\
**Post date:** [September 2, 2024, 7:53am UTC](https://community.postman.com/t/setnextrequest-is-undefined/67817/1 "2024-09-02T07:53:27Z")

</div>

There is a strange issue I’m getting when running a collection using newman.

This one request has a retry mechanism in its post-script

```auto
if (response.id == null)
{
    let retryCounter = pm.environment.get("retryCounter")
    let currentRun = pm.environment.get("currentRun");

    if (parseInt(currentRun) <= parseInt(retryCounter))
    {
        pm.execution.setNextRequest("userTask - personal data 1")
    }
    else{
        
        pm.execution.setNextRequest(null)
        throw new Error("Polling unsucessful. ID is null or same as in previous step")
    }
    pm.environment.set("currentRun", parseInt(currentRun) + 1)
}
else
{
    
    pm.execution.setNextRequest("Submit - personal data")
}

```

But the problem I’m getting is that newman reports a “type-script error in test script”  
Upon looking at the newman report I see

```auto
Cannot read properties of undefined (reading 'setNextRequest')

```

Seems setNextRequest is not available from an if loop? So it seems…why?

---

<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:** [September 2, 2024, 8:42am UTC](https://community.postman.com/t/setnextrequest-is-undefined/67817/2 "2024-09-02T08:42:43Z")

</div>

Hey @aviation-observer-43 👋

Which version of Newman are you running this against?

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [October 2, 2024, 8:43am UTC](https://community.postman.com/t/setnextrequest-is-undefined/67817/3 "2024-10-02T08:43:11Z")

</div>

Closed on October 2, 2024, 8:43am UTC

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