1

How Get Calendar recurrent events by CSOM from SharePoint 2013.

Hi I am Going to Explain you here how to get Recurrence Event From your Sharepoint Calender List Using Client Object model(CSOM) Getting Recurrence Event From List using Server OM  is bit eassy as Below

SPQuery query = new SPQuery();
query.ExpandRecurrence = true;

query.Query = String.Format(
"" +
"" +
"" +
"",
Fields.StartDate,
Fields.EndDate,
Fields.RecurrenceId,
orderBy);

Now Coming on CSOM-

  • The problem with recurrence is that there is only a single list item. The recurrence information is stored inside a hidden field of that list item called ‘RecurrenceData’ as XML that gets calculated out. Unfortunately Microsoft.SharePoint.Client.CamlQuery doesn’t have the properties that SPQuery does in the server object model to transform this information.
  • What is a little more frustrating is that the new OData operations through REST do not support the DateTimeRangesOverlap operator or “querying as to whether a date time falls inside a recurrent date time pattern

But Nothing is impossible…….. Final way is call old-fashion List.asmx.

  • There was a way to call Lists.asmx in versions before 2013 using SOAP and pass an entire XML message which would allow you to use the DateRangesOverlap filter in the query, and allow you to pass QueryOptions that would include ExpandRecurrence and CalendarDate, but it was flaky trying to pass an actual datetime value for CalendarDate as the value to check if the event overlaps with.
  function GetItemsFromCalendarAsmx () {
wsURL = webUrl + “_vti_bin/Lists.asmx”;
var xmlCall =
“<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;
};

hope you GET expected Solutions

Happy Coding Thanks SPS

Advertisements