I am trying to create one SP hosted app which will read all events (includes recurring) from SharePoint calendar list. I tried but am enable to reach to it.
my code is as below.
function retrieveListItems() {
var appContextSite;
ListName = "MyList";
web = context.get_web();
context.load(web);
var myList = web.get_lists().getByTitle(ListName);
var query = new SP.CamlQuery();
query.set_viewXml(
"<ViewFields>"
"<FieldRef Name='EventDate' />"+
"<FieldRef Name='EndDate' />"+
"<FieldRef Name='RecurrenceData' />"+
"<FieldRef Name='fRecurrence' />"+
"</ViewFields>"+
"<Query><Where>" +
"<DateRangesOverlap>" +
"<FieldRef Name='EventDate' />" +
"<FieldRef Name='EndDate' />" +
"<FieldRef Name='RecurrenceID' />" +
"<Value Type='DateTime'>" + currentDate + "</Value>" +
"</DateRangesOverlap>" +
"</Where>" +
"<queryOptions>" +
" <QueryOptions>" +
"<ExpandRecurrence>TRUE</ExpandRecurrence>" +
"</QueryOptions>" +
" <QueryOptions>" +
"<CalendarDate>" + currentDate + "</CalendarDate>" +
"<RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>" +
"</QueryOptions>" +
"</queryOptions>" +
"<OrderBy>" +
"<FieldRef Name='EventDate' Ascending='True' />" +
"</OrderBy></Query>");
var items = myList.getItems(query);
context.load(items);
debugger;
context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nID: ' + oListItem.get_id() +
'\nTitle: ' + oListItem.get_item('Title') +
'\nBody: ' + oListItem.get_item('Body');
}
alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
}
getByTitle('Events')/items('7')/RecurrenceData
. This will return you xml string. from there you can write your logic