function checkDoubleBooking(formModeEdit, listId, currentItemId, startDate, endDate) {
var results = [];
var liHtml = "";
var checkOverlappingQueryArray = [];
checkOverlappingQueryArray.push("<And>");
checkOverlappingQueryArray.push("<Leq>");
checkOverlappingQueryArray.push("<FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>" + moment(endDate).format() + "</Value>");
checkOverlappingQueryArray.push("</Leq>");
checkOverlappingQueryArray.push("<Geq>");
checkOverlappingQueryArray.push("<FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>" + moment(startDate).format() + "</Value>");
checkOverlappingQueryArray.push("</Geq>");
checkOverlappingQueryArray.push("</And>");
if (formModeEdit) {
checkOverlappingQueryArray.unshift("<And>");
checkOverlappingQueryArray.push("<Neq>");
checkOverlappingQueryArray.push("<FieldRef Name='ID' /><Value Type='Integer'>" + currentItemId + "</Value>");
checkOverlappingQueryArray.push("</Neq>");
checkOverlappingQueryArray.push("</And>");
}
checkOverlappingQueryArray.unshift("<Where>");
checkOverlappingQueryArray.push("</Where>");
checkOverlappingQueryArray.unshift("<Query>");
checkOverlappingQueryArray.push("</Query>");
jQuery().SPServices({
operation: "GetListItems",
async: false,
listName: listId,
CAMLViewFields: "<ViewFields>" +
"<FieldRef Name='ID' />" +
"<FieldRef Name='Title' />" +
"<FieldRef Name='EventDate' />" +
"<FieldRef Name='EndDate' />" +
"<FieldRef Name='PeoplePickerField1' />" +
"</ViewFields>",
CAMLQuery: checkOverlappingQuery,
CAMLQueryOptions: "<QueryOptions>" +
"<ExpandUserField>True</ExpandUserField>" +
"</QueryOptions>",
CAMLRowLimit: 10,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
countOverlappingEvents++;
results.push({
title: $(this).attr("ows_Title"),
eventDate: $(this).attr("ows_EventDate"),
endDate: $(this).attr("ows_EndDate"),
peoplePickerField1: userToJsonObject($(this).attr("ows_PeoplePickerField1"))
});
}
}
});
return results;
}
function userToJsonObject(userObj) {
if (userObj.length === 0) {
return null;
} else {
var thisUser = userObj.split(";#");
var thisUserExpanded = thisUser[1].split(",#")
if (thisUserExpanded.length == 1) {
return {
userId: thisUser[0],
userName: thisUser[1]
}
} else {
return {
userId: thisUser[0],
userName: thisUserExpanded[0].replace(/(,,)/g, ","),
loginName: thisUserExpanded[1].replace(/(,,)/g, ","),
email: thisUserExpanded[2].replace(/(,,)/g, ","),
sipAddress: thisUserExpanded[3].replace(/(,,)/g, ","),
title: thisUserExpanded[4].replace(/(,,)/g, ",")
}
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>