I've got an api call that retrieves some JSON data and I want to set a variable if there is a column called result that is blank.
When I run the code it sets UncompletedProcesses = true if it meets this condition but when I check it at the end it says it's undefined on line.
if ((URMajIssues == true) && (URDeviation == false) && (UncompletedProcesses == true))
This is the code i'm using, what am I doing wrong please:
//Check to see if all processes have been completed on all stages
var UncompletedProcesses
var request = new XMLHttpRequest()
var stage = 0;
var ModuleIdent = '@HttpContext.Session.GetString("sesMIdent")'
// Open a new connection, using the GET request on the URL endpoint
request.open('GET', 'https://xxxxxxx.azurewebsites.net/api/rou/' + stg + '/' + MIdent +'/5317dba3', true)
request.send = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response)
data.forEach((data) => {
if (data['result'] == '')
{
UncompletedProcesses = true;
}
})
}
// Send request
request.send()
alert(UncompletedProcesses)
if ((URMajIssues == true) && (URDeviation == false) && (UncompletedProcesses == true)) {
document.getElementById('lblWarningMsg').innerText = 'A Major issue has been identified. This needs to be repaired'
$('#modal-warning').modal({ backdrop: 'static', keyboard: false })
}
Many thanks for your help.
URMajIssuesandURDeviationdefined?