Skip to content

Instantly share code, notes, and snippets.

@MartinBodocky
Last active March 10, 2020 17:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinBodocky/7984439 to your computer and use it in GitHub Desktop.
Save MartinBodocky/7984439 to your computer and use it in GitHub Desktop.
Get Calendar recurrent events by CSOM from SharePoint 2013.
GetItemsFromCalendarAsmx = function (webUrl, calendarGuid) {
wsURL = webUrl + "_vti_bin/Lists.asmx";
var xmlCall =
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body>" +
"<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" +
"<listName>" + calendarGuid + "</listName>" +
"<query>" +
"<Query>" +
"<Where>" +
"<DateRangesOverlap>" +
"<FieldRef Name=\"EventDate\" />" +
"<FieldRef Name=\"EndDate\" />" +
"<FieldRef Name=\"RecurrenceID\" />" +
"<Value Type='DateTime'><Year/></Value>" +
"</DateRangesOverlap>" +
"</Where>" +
"</Query>" +
"</query>" +
"<queryOptions>" +
"<QueryOptions>" +
"<ExpandRecurrence>TRUE</ExpandRecurrence>" +
"</QueryOptions>" +
"</queryOptions>" +
"</GetListItems>" +
"</soap:Body></soap:Envelope>";
var result = [];
$.ajax({
url: wsURL,
type: "POST",
dataType: "xml",
async: false,
data: xmlCall,
complete: function (xData, status) {
Core.LogMessage("Core.GetItemsFromCalendarAsmx-> url: " + wsURL + " status: " + status);
if (status === "success") {
var root = $(xData.responseText);
root.find("listitems").children().children().each(function () {
$this = $(this);
var ids = $this.attr("ows_UniqueId").split(";");
var rec = $this.attr("ows_fRecurrence");
result.push({
"StartTime": $this.attr("ows_EventDate"),
"EndTime": $this.attr("ows_EndDate"),
"Title": $this.attr("ows_Title"),
"Recurrence": (rec === "1" ? true : false),
"Description": Core.HtmlDecode($this.attr("ows_Description")),
"Guid": ids[1],
"Id": ids[0],
});
});
}
},
contentType: "text/xml; charset=\"utf-8\""
});
return result;
};
@alancejacob
Copy link

I'm getting below error while executing above code - SharePoint Online! Any idea?
HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request.
(XHR)POST - https://xxxx.sharepoint.com/_vti_bin/Lists.asmx
Please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment