Stop Collection Runner with pre-request script

I have a collection with a single request in it. Iā€™m using a .csv with collection runner to execute the request once per line in the .csv. The first column in the .csv is ā€œDocument IDā€, and thatā€™s the only variable Iā€™m using from the .csv.

However, at the bottom of the .csv is a blank line followed by a few lines that arenā€™t pertinent to the running of the collection.

Iā€™d like the collection to see the blank line (pm.collectionVariables.get(ā€˜Document IDā€™) == ā€˜ā€™) and stop executing.

Any suggestions on the best way to do that?

Not sure this is possible, as setNextRequest(null) only sets the request that will run next.

It doesnā€™t trigger immediately.

Therefore, you can check if the element is empty in a pre-request but its still going to run that request.

My suggestion would be to transform the CSV file so its in the correct format to start with. (This is always my suggestion for this type of task, as Postman is not an ETL tool).

I know its another language, but Iā€™d probably do this in PowerShell first as it has native cmdlet support for CSV files. Import the CSV, filter out blank lines and the other lines and then Export-CSV.

Get PowerShell to pick up the file from the source, and then save it to the folder that Postman will pick it up from.