Is there a possibility to add iterations in Monitor

I have a collection that has 4 folders in it, each folder needs a different set of iteration to be set. is there a possibility to set it? Kindly help.

You can do this in the prerequest and test scripts for each folder. You can initialize a loop counter in the prerequest script and in the test script increment the counter?

What does your layout look like? Do you change the requests in each folder regularly?

Hi Allen, image

this is my layout, in this I need Step 1 and Step 2 to be triggered for 1 iteration and Step 3 to be triggered for 10 iterations.

You can add a prerequest script to Step 3 to be a loop counter:

let counter = pm.variables.get('loopCounter');
  counter = 0;

pm.variables.set('loopCounter', counter++);

In your test scripts of the Step 3 request you can add

const counter = pm.variables.get('loopCounter');
if(counter < 10) {

This will cause just that request to loop 10 times.

It’s the same problem/solution we discussed in this thread

1 Like

Hi Allen thanks for the reply, yes this will loop in through but after 10 iterations I need to exit.

I tried to put postman.setNextRequest(null); in the prerequest by setting condition as:
// //exit from pgm

let counter_end = parseInt(pm.environment.get(“counter”));

if (counter_end == 10)


but that’s not working;

On further checking how to stop execution using a command in the Pre-request, got to see the post

which is what I wanted, this is in-progess if I’m not wrong based on the commnets

if Step 3 is the last request in your collection, the monitor should just stop after that 10th iteration. Can you show me a screenshot of what you have in the prerequest and test script tab?

Hi @allen.helton

In the pre-request I have this

In the Test I have this

You’re pulling from local variables in your test scripts. You should be pulling counter out of the environment since that’s where you’re setting it in the prerequest script.

That was my bad Allen I pasted the wrong part, here is the correct script below:


Still pgm is not exiting, after counter 10 its incrementing to 11 and since my logic after that is not valid it hits error at 11

You need to make the if condition only less than, not less than or equal to. Since the prerequest script is the one that is incrementing the counter, your test scripts are going to “be one ahead”. So your problem should resolved if you change your script to:

const counter = pm.environment.get('counter');
const numberOfLoops = 10;
if(counter < numberOfLoops) {
  postman.setNextRequest('Testing-UCI Check - Baed on latest 10 Entity fetched from Step3');

Hi Allen, thank you so much it worked, that was a great help indeed :slight_smile:

1 Like

Hi @allen.helton need your help in this same topic again, the above same logic when executed in newman is going in infinte loop not sure why is it so, could you please help on this.

That one has me puzzled, it shouldn’t matter where it’s being executed from. It possibly has to do with the environment variable.

You could try to switch the counter environment variable to a collection variable instead.

So anywhere you see pm.environment.get('counter') or pm.environment.set('counter', value)
replace it with pm.collectionVariables.get('counter') or pm.collectionVariables.set('counter' value)

Hi @allen.helton thanks for the help that worked :slight_smile:

But I’m curious why the environment variables are not getting reflected during runtime :frowning:

My thought process behind the solution was:

“If you aren’t explicitly passing in an environment to newman, there are no environment variables to manipulate”