Is there a "generic" way to do a postman.setNextRequest() without knowning the request name or ID?

Hi, I’m writing some tests and am also writing some common javascript “helper” functions to use across the tests. One thing we’d like to be able to do is catch errors that occur during the test setup, and skip to the end of the tests where we’ll run some cleanup.

For instance, assume there is a folder that we want to run, and it has requests like the following:

  • setup.createOrganization
  • setup.createTeamWithinOrganization
  • test.updateOrganization
  • test.updateTeam
  • assert.updatedOrganizationInfo
  • assert.updatedTeamInfo
  • tearDown.deleteOrganization

In the “setup." requests, if either of those fails, I’d like to be able to skip the "test.” and “assert.*” requests, and go right to the “tearDown.deleteOrganization” request. I know we can do something like this in the “Tests” of the setup requests:

  if (pm.response.code != 201) {

But we are writing some utility functions, so want to be able to have a function that does this, and would really like for it to be generic, something like tearDownIfResourceCreationFailed(), looking something like this:

function tearDownIfResourceCreationFailed() {
  // Want to find the first request named tearDown.* in the current folder...
  const tearDownRequest = ???;
  if (pm.response.code != 201) {

So the question is, does an api exist in the sandbox that will give me a list of all requests in the currently-executing folder? I know we can use the request object to get properties of the current request, but is there anything available to give an array/object of ALL requests?

There are other ways to make this work - the function could accept a request name, or we could even just standardize and always call the first “tear down” request (there may be many, in some cases) “tearDown”. But I liked the idea of being able to just list the requests, and find the first one named “tearDown.*”.