Copy collection and automatically apply new request ID in pm.execution.setNextRequest

I have few collections that have a lot of sub-folders and requesrs. Each of them uses pm.execution.setNextRequest to generate loops if needed based on specific logic.

Each time I copy the collection (or make a fork) then, the old ID remains from the collection I just copied. I have not found a way to automatically replace it with new request id.

Just to provide example:
collection1 has two requests:

  • request1 (id “111-111-111”)
    -* It has in post-request a code pm.execution.setNextRequest(“222-222-22”);
  • request2 (id “222-222-2”)
    -* It has in post-request a code pm.execution.setNextRequest(“111-111-111”);

when I copy collection1 , it persists the old id, and not the new one:

  • request1 (id “333-3333-3333”)
    -* It has in post-request a code pm.execution.setNextRequest(“222-222-22”);
  • request2 (id “4444-4444-444”)
    -* It has in post-request a code pm.execution.setNextRequest(“111-111-111”);

The result of the collection copy should be as follows:

  • request1 (id “333-3333-3333”)
    -* It has in post-request a code pm.execution.setNextRequest(“4444-4444-444”);
  • request2 (id “4444-4444-444”)
    -* It has in post-request a code pm.execution.setNextRequest(“333-3333-3333”);

Is there any settings or a way to make it happen and not manually fix ids in every request after copy?

Hey @material-operator-35 :wave:

Welcome to the Postman Community! :postman:

Are you hardcoding the id’s in the sendNextRequest commands or was that example to show what it would look like?

Or are you using pm.info.requestId in those?

That would obvious only be the request that it’s in but you can capture the other request id’s in a variable and use that too.