public Sub SendRegistrationsWait()
Dim Results As List
Results = SQL.ExecuteWait($"SELECT dtitscan, dtgrpscan, dtid, dttype, dtdatetime, dtstop, dtstart, dtextra FROM tData WHERE dtstatus=2"$, Null)
If Results.Size = 0 Then
SKTools.ShowToast("Niets om door te sturen", "info", 3000, True)
Return
End If
Dim now As Long = DateTime.Now
Dim RecList As List
RecList.Initialize
For i = 0 To Results.Size - 1
Dim dataSend As Map
dataSend.Initialize
Dim m As Map = Results.Get(i)
Dim resM As Map
resM.Initialize
resM.Put("ic", m.Get("dtitscan"))
resM.Put("gc", m.Get("dtgrpscan"))
resM.Put("va", 0)
resM.Put("ri", m.Get("dtid"))
resM.Put("rt", m.Get("dttype"))
RecList.Add(resM)
Next
dataSend.Put("da", RecList)
dataSend.Put("tp", 100)
Dim fetch As BANanoFetch
Dim fetchOptions As BANanoFetchOptions
Dim fetchResponse As BANanoFetchResponse
Dim data As Map
Dim Error As String
Dim JsonG As BANanoJSONGenerator
JsonG.Initialize(dataSend)
fetchOptions.Initialize
fetchOptions.Method = "POST"
fetchOptions.Body = JsonG.ToString
fetchOptions.Headers = CreateMap("Content-type": "application/json; charset=UTF-8", "api_key": APIKey)
fetch.Initialize("https://api.xxxxxxxxxxxxxxxxxx/v1/registration/uploadxxxxxxxxxxx", fetchOptions)
fetch.Then(fetchResponse)
' we got a response, but as the Json() method returns a Promise, we will need to process it in the next 'then' so we return it to this Fetch
fetch.Return(fetchResponse.Json)
fetch.ThenWait(data)
If data.get("status") = "OK" Then
SQL.ExecuteWait($"UPDATE tData SET dtstatus=99 WHERE dtstatus=2"$, Null)
SKTools.ShowToast("Alles doorgestuurd.", "info", 3000, True)
Else
SKTools.ShowToast("Doorsturen niet gelukt.", "info", 3000, True)
End If
fetch.ElseWait(Error)
SKTools.ShowToast(Error, "info", 3000, True)
fetch.End
End Sub