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');
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:
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.
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.
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
But it must be put at the end of pre-script, because this instruction seems to stops it.