Ignoring a request from the runner based on iteration

I have to run my collection on two different Country levels so I have my iteration set up as one iteration for one country, but some of the end points are not country specific and need not have to run twice.

Is there a way I can avoid running certain end points only once in the runner based on iteration.

You can use postman.setNextRequest(<request name>) to skip over requests in the collection runner. As long as you know what data triggers a different workflow you can skip over requests that way.

I’m happy to provide you an example if you provide some more details on what your flow is and what data would cause you to skip over some requests.

So I have about 40 requests in my runner but out of which about 15 are generic ones and not country specific. I cannot group them together as they are spread across in specific order and need to be in that way.

The iteration is based on country level so for example one iteration is for UK and the second one is for US.

So using postman.setNextRequest() as it is doesnt help , I will need to make it specific for iteration count if possible. Like run this request if the iteration count is 1 or something like that.

Hi @Usivaram7,

Welcome to the community! :clap:

Given the criteria you mentioned, and @allen.helton’s recommendation, what you can do is create an iteration counter in your pre-request script (or test script if thats better), and store that count as a Postman Variable (global or environment).

Then, you can check for the iteration count variable in your test script, and depending on that count, you can execute the pm.setNextRequest(<request name or request ID>) to execute the request that should follow.

Best,
Orest

Yes I think that would work ,Are you able to suggest a example code for it ?

I tried this way as well by adding a Iteration Count column in my data.csv

if (pm.iterationData.get(“Iteration Count”) === 1) {

postman.setNextRequest(‘request name1’);

} else {

postman.setNextRequest(‘request name2’);

}

1 Like

@Usivaram7 nice, this should also suffice as a means to get an iteration count.

Let us know if that works!

Orest

no sadly it didnt work. Hence asking if there is anything else I could try.

Can you try using the request ID instead of the request name? I have had better luck there. You can get the request ID by exporting the collection, and searching for the request ID in the collection json file.

Also, try a “==” instead of a “===”. If my memory serves me correctly, === implies object equality, but not value equality.

1 Like

if(“value” == pm.iterationData.get(“fieldname”))

{

postman.setNextRequest("Next request");

}

Try this in pre req tests.

2 Likes

All looking good now. Thank you so very much.

You are welcome :heart_eyes: