-
Hi, I'm trying to set a variable in the global script, and then use it in a response event, but sometimes I want to override it in the request scope. Example code: {{
update='true';
console.log(`global - update: ${update}`);
}}
{{@response
console.log(`response - update: ${update}, code: ${response.statusCode}`);
if (update == 'true' && response.statusCode == 200) {
$global.counter+=1
}
}}
###
// initial set
GET https://postman-echo.com/get
{{
$global.counter=1
}}
###
// increment
GET https://postman-echo.com/get
###
// not increment
@update='false'
GET https://postman-echo.com/get First I call the "initial set" request, this will set the counter. {{
update='false'
}}
GET https://postman-echo.com/get I assume it's working because the global and the request script is using the same scope, but it's unnecessarily noisy just to set a variable. What is the scope of the inline variable when set using the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Sorry it took so long to reply. I seem to have accidentally clicked away the notification.
|
Beta Was this translation helpful? Give feedback.
Sorry it took so long to reply. I seem to have accidentally clicked away the notification.
The way via
update = 'true' is not intended and surprisingly works. Here the variable is set at the global object. But
@update = "false"sets it in my variable context which wins in the following runs. The correct way would be to use
exports.update` but then you run into an error that you could work around.httpyac.useRegionScopedVariables
in vscode{{@request
to setexports.update="true"