How to set initial value of variable using pm API

I am trying to use the variable set in environment/Collections as variables in Collection documentation. but i have observed when you set using

pm.environment.set("some_key", "some_value")

sets only the current value field, but the docs section when we use variable as {{some_key}} , it always reads from initial value, how to set that without the UI programmatically

Hello @Ra_Na
You can put a condition in the folder’s pre-request in case it doesn’t have a value you define, I’ll put the example below for you to see if it applies to your case:

if (!pm.environment.get("some_key"))
    pm.environment.set("some_key", "Opa isso é um teste");

Note: I talked about putting the test in the folder’s pre-request because it will always run on every request that is inside the folder