setNextRequest function not working

The

setNextRequest() function doesn’t seem to be working. The documentation doesn’t explain how to use it (args etc), but the changelog says to use the request name, or null. I’ve tried calling it using a request name which didn’t respond. I’ve tried using the name hard coded, and pulled using pm.info.requestName . No response either time. I’ve also tried calling it with null to prevent the next step running, and again it does nothing. I’ve tried calling it using $.setNextRequest and using postman.setNextRequest, again no response.

I contacted your technical support chat which said you usually reply in a few minutes, but so far I’ve had no response in nearly 24 hours.

Full after script, it’s a simple UUID format validation and then polling an endpoint until a task is complete. The function is used to set the same request as the next one, so it calls itself until complete or retry count exceeded:

::javascript
pm.test("Validate id UUID format", function() {
  const response = pm.response.json();
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
  
  pm.expect(response).to.have.property('id');
  pm.expect(response.id).to.match(uuidRegex);

});

const response = pm.response.json();

if (response.status === "in_progress") {
console.log("Task still in progress, sleeping 3 seconds before retry");


// Add a counter to prevent infinite loops
const retryCount = parseInt(pm.environment.get("forensic_retry_count"));
console.log("Retries:", retryCount)
pm.environment.set("forensic_retry_count", retryCount + 1);

// Maximum retries (adjust as needed)
const maxRetries = 10;

if (retryCount < maxRetries) {
  // Sleep and retry
  console.log("retrycount:", retryCount, "max:", maxRetries, "?", retryCount < maxRetries)
  $.sleep(1000);
  console.log("requestName:", pm.info.requestName, "requestId:", pm.info.requestId)
  postman.setNextRequest("Get results of forensic analysis task"); 
} else {
  console.log("Max retries reached. Stopping polling.");
  pm.environment.set("forensic_retry_count", 0);
}
} else {
// Reset retry counter for next test run
pm.environment.set("forensic_retry_count", 0);
console.log("Task completed with status: " + response.status);
}

Please authenticate to join the conversation.

Upvoters
Status

In Review

Board

💡 Feature Request

Date

About 2 months ago

Author

David Brooks

Subscribe to post

Get notified by email when there are changes.