I'm in a loop here, for each iteration I'm calling _checkExistingDefaultTimes to check if a record exists.
The problem is, the code in loop is not ran until I'm outside the for loop....
Is there any way I can use Promise so that it forces the .then code (pushing oOpeningTimes) before the loop finishes?
var oOpeningTimes = [];
for (var i = 0; i < numberOfDays; i++) {
this._checkExistingDefaultTimes(test.SiteInfo.SiteId,test.EffectiveDateFrom,
test.EffectiveDateTo)
.then(function (bResult) {
oOpeningTimes.push({
temporaryDate: oDate,
startTime1: oModelData[oWeekday].startTime1,
endTime1: oModelData[oWeekday].endTime1,
});
});
oStoreData.OpeningTimes = oOpeningTimes;
oModel.setData(oStoreData);