I'm encountering an issue while attempting to transfer a variable from JSON using Postman to an environment variable.
The variable is successfully extracted, but there seems to be an obstacle in storing it in the environment variable. Here's the current state of my code:
var allGazette = JSON.parse(responseBody);
if(allGazette.total_count!==0){
for (i = 0; i < allGazette.total_count; i++) {
var dateUse=allGazette.items[i].date;
console.log(dateUse);
postman.setEnvironmentVariable('jsonGazetteDate', dateUse);
console.log(jsonGazetteDate);
}
}
else(postman.setEnvironmentVariable('jsonGazetteDate',''));
The problem arises at the line where postman.set... is used. According to the console logs provided below, the dateUse is successfully retrieved as 2018-05-01. Despite my attempts with different combinations of stringify/parse methods, I have been unable to resolve this issue. Any suggestions or ideas?
GET https://api.companieshouse.gov.uk...
2018-05-01
ReferenceError | jsonGazetteDate is not defined
GetGazette: ReferenceError: jsonGazetteDate is not defined