pm.execution.skipRequest() does not work in my scripts

I am trying to control a request execution based on the condition I set in "pre-request script. while i run the collection manually, an error is thrown as “TypeError: Cannot read properties of undefined (reading ‘skipRequest’)”

This feature only works with the Collection Runner.

However it shouldn’t error like that, so can you share your code please?

It will work at the individual level too - This one isn’t just in the Collection Runner like sendNextRequest().

I think that as they have added the a Newman label is that their version of Newman isn’t up to date and that’s causing the error here.

But yeah, without more details, it’s difficult to tell either way.

this is the code in pre-request

var utriId= pm.environment.get(“utriId1”);
if(!utriId || utriId==null){
pm.execution.skipRequest();
}

the request is triggered successfully if it does not satisfy the if condition. the postman version is 10.12.13

I am running the collection in postman app itself manually from the collections run option

That is working fine for me.

I’ve added a few console logs.

let utriId = pm.environment.get("utriId1");
console.log(utriId); // undefined

if (!utriId || utriId == null) {
    console.log("skip"); // skip
    pm.execution.skipRequest();

}

You can see from the console logs, that the IF condition is being met but no request is sent.

image

How is your null variable being stored. Is it actually an boolean like your example, or perhaps its being stored as a string.

Console log the variable like I have in my example script to see what is actually being returned.

This will be your problem. This feature was released in November 2023 (v10.20)

okay, then its the version issue

i upgraded the postman version. Now its working. But, I have a question. Will the collection with skipRequest run in newman pipeline?

There is a pull request on Github that relates.

Updated dependencies by KiraElric007 · Pull Request #3183 · postmanlabs/newman · GitHub

I can’t actually tell if this is live. I guess I would just try it and see if it errors.

Make sure you are on an up-to-date version of node, as the pull request mentions some performance issues on previous versions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.