I have some code in my PreSaveItem event that checks to see if there is a conflict on the calendar with the item being created. The code itself executes just fine and properly checks the calendar for conflicts. Where the problem occurs is when there is no conflict - the success happens, but then it does not submit the form, just returns you to the open form.
function PreSaveItem(){
var d = new Date(startDate);
startDate=d.toISOString();
startMinute = handleMinute(startMinute);
d.setHours(startHour);
d.setMinutes(startMinute);
startDate=d.toISOString();
var e = new Date(endDate);
endDate=e.toISOString();
endMinute = handleMinute(endMinute);
e.setHours(endHour);
e.setMinutes(endMinute);
endDate=e.toISOString();
conflictFlag = false;
var calendarUrl = theCalendarURL;
$.getJSON(calendarUrl,function(data,status,xhr){
if(data.value.length>0){
for (var i = 0; i < data.value.length;i++){
var b= new Date(data.value[i].EventDate);
var s= new Date(data.value[i].EndDate);
b=b.toISOString();
s=s.toISOString();
//if ( b.getFullYear()==d.getFullYear() && b.getMonth()==d.getMonth() && b.getDate() == d.getDate() ){
if(b<startDate && s>startDate){ conflictFlag=true; }
if(b<endDate && s>startDate){ conflictFlag=true; }
if(b>startDate && s<startDate){ conflictFlag=true; }
//}
}
}
if (conflictFlag==true){
alert("You have selected a date/time/line that is already in use. Please select a different date/time or line.");
return false;
} else {
alert("Congrats!");
return true;
}
});
}
(I have removed some code in the name of efficiency here, but the missing variables are populating properly)