Hello Everyone,
im trying to run a collection that has several requests inside it. I will explain more or less how it works:
Get request β just get a index
Post Request β Create a file on a data base
Patch Request β Update the status of the file
My problem is on the patch request, it runs every time. This βIFβ is not working at all.
Im using this:
There are a couple of things to bear in mind from the Building request workflows help (scroll to the βStop workflow executionβ section).
Firstly, you need to specify null for the value of the next request - i.e. postman.setNextRequest(null);
Secondly, you need to bear in mind this note:
postman.setNextRequest() is always executed at the end of the current request. This means that if you put this function before other code blocks anywhere in pre-request or test script, these blocks will still execute.
So if you have other code after this if statement, it will still be executed regardless of status - you might want to put the remaining code into an else block if you donβt want it to run further.
Okay, i kind of understand. So how can i run a collection and make a statement to check before running a specific request like this:?
1- Run
2- Check if it is to run or not, dont run
3- run
4- β¦
Itβs difficult to give a definite answer without seeing a screenshot of your requests, or a bit more context of your scripts, but if you have three requests:
Get Request
Post Request
Patch Request
β¦and you want to skip Patch Request according to status, then you could insert the following script at the bottom of the Tests tab for Post Request:
If you have a fourth request, and you just want to skip Patch Request and move onto the next request in the collection, you can specify the request name instead:
if(pm.collectionVariables.get("status") !== "draft"){
postman.setNextRequest("Name of next request");
}
If this is creating confusion then please share as much information as you are able