How to execute only "pre-request Script"? That would be enough for me!

Hello all!

My question:
I would like to assign my variables, nothing more.

Details (like screenshots):
I do: Create a new request (there is no other place in the application to work in):

var uuid = require('uuid');
pm.collectionVariables.set("transactionId", uuid.v4().toString("B"));
console.log(pm.collectionVariables.get("transactionId"));
throw new Error("enough"); //read https://community.postman.com/t/stop-request-from-sending-if-pre-request-test-fails/

How I found the problem:
Collection variable retains old value. If this variable was not existing, this variable is not created.
The Console logs a new GUID always, but seemengly after throw, variables are reset to pre-run state.

What I tried else
I tried to specify urls:
GET https://example.com
GET https://httpstat.us/201
But it is slower, and I want to avoid bothering these folks with senseless calls.

What I want
Assign GUID to my variable to have it available through several sequential scripts.

Thank you!

The scripts are asynchronous in nature.

This means that the whole script is evaluated first before its run and as you’ve found out you can’t guarantee that the throw new error will run after the other lines of code.

There are various topics in the forum in relation to the async nature of Postman with various workarounds using IF statements to enforce the running order which may or may not work for you.

I am amused that printing the collection variable (to console) really displays the NEW value, as if the new value is really assigned, done.

But after throw, the variable has the OLD value.

Can you point me at any topic that explains “only script, no request” solution, please?

Version 10.20 finally delivered pm.execution.skipRequest();
But it must be put at the end of pre-script, because this instruction seems to stops it.

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