none
Get expanded recurrence for calendar list RRS feed

  • Question

  • How can I get the expanded recurrence for a calendar list on SharePoint 2013 (on-premise)?

    I don't have SharePoint on my machine, and the other features I have implemented were using the REST api, however it doesn't offer many features that the ASMX service provide. I were trying to use the ASMX web service with a CAML query and it doesn't allow me to add fields to the result.

    How can I achieve this?

    Friday, January 6, 2017 1:33 PM

Answers

  • Hi,

    If you want to get the two months ahead, please change <Today/> to

    <Today OffsetDays="-60" />

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, January 10, 2017 2:28 AM
    Moderator

All replies

  • Hi,

    We can use SPService to achieve it. Check the code below:

    // Calendar rollup
    var calendars = [];
    var events = [];
    var calendarPromises = [];
    
    // For each calendar, go and get the events
    for (var i = 0; i < calendars.length; i++) {
    
      var thisCalendar = calendars[i];
      var today = moment().format();
    
      calendarPromises[i] = $().SPServices.SPGetListItemsJson({
          listName : thisCalendar.title,
          webURL : thisCalendar.listUrl,
          CAMLViewFields : "<ViewFields>" +
    			  "<FieldRef Name='ID' />" +
    			  "<FieldRef Name='Title' />" +
    			  "<FieldRef Name='EventDate' />" +
    			  "<FieldRef Name='EndDate' />" +
    			  "<FieldRef Name='Location' />" +
    			  "<FieldRef Name='Description' />" +
    			  "<FieldRef Name='Category' />" +
    			  "<FieldRef Name='fRecurrence' />" +
    			  "<FieldRef Name='RecurrenceData' />" +
    			  "<FieldRef Name='fAllDayEvent' />" +
    		"</ViewFields>",
          CAMLQuery : "<Query>" +
    			  "<Where>" +
    				  "<And>" +
    					  "<DateRangesOverlap>" +
    						  "<FieldRef Name='EventDate' />" +
    						  "<FieldRef Name='EndDate' />" +
    						  "<FieldRef Name='RecurrenceID' />" +
    							  "<Value Type='DateTime'>" +
    							  "<Year />" +
    						  "</Value>" +
    					  "</DateRangesOverlap>" +
    					  "<Or>" +
    						  "<Eq>" +
    							  "<FieldRef Name='HomePageHide' />" +
    							  "<Value Type='Bool'>False</Value>" +
    						  "</Eq>" +
    						  "<IsNull>" +
    							  "<FieldRef Name='HomePageHide' />" +
    						  "</IsNull>" +
    					  "</Or>" +
    				  "</And>" +
    			  "</Where>" +
    			  "<OrderBy>" +
    				  "<FieldRef Name='EventDate' />" +
    			  "</OrderBy>" +
    		"</Query>",
          CAMLQueryOptions : "<QueryOptions>" +
    			  "<CalendarDate>" + today + "</CalendarDate>" +
    			  "<ExpandRecurrence>TRUE</ExpandRecurrence>" +
    			  "<RecurrenceOrderBy>TRUE</RecurrenceOrderBy>" +
    			  "<ViewAttributes Scope='RecursiveAll'/>" +
    		"</QueryOptions>",
          mappingOverrides : {
            "ows_fAllDayEvent" : {
              "mappedName" : "fAllDayEvent",
              "objectType" : "Boolean"
            },
            "ows_fRecurrence" : {
              "mappedName" : "fRecurrence",
              "objectType" : "Boolean"
            }
          }
        });
    
    }
    
    $.when.apply($, calendarPromises).then(function () {
    
      var calendarEvents = this;
    
      // For each calendar, go and get the items and push them into an array
      for (var i = 0; i < calendars.length; i++) {
    
        $(calendarEvents[i].data).each(function () {
          events.push({
            calendar : calendars[i].title,
            id : this.ID,
            title : this.Title,
            location : this.Location != null ? this.Location : "",
            category : this.Category,
            eventDate : moment(this.EventDate),
            endDate : this.EndDate,
            fAllDayEvent : this.fAllDayEvent,
            fRecurrence : this.fRecurrence,
            RecurrenceData : this.RecurrenceData
          });
        });
    
      }
    
      events.sort(function (a, b) {
        return a.eventDate.isAfter(b.eventDate) ? 1 : (a.eventDate.isBefore(b.eventDate) ? -1 : 0);
      });
    
      ko.applyBindings(new calendarViewModel(), document.getElementById("calendar-rollup"));
    
    });
    
    

    More information:

    http://sympmarc.com/2015/07/07/retrieving-expanded-calendar-events-with-rest-vs-soap/

    http://www.casvaniersel.com/2012/01/inconvenient-recurrence-data-from-a-sharepoint-calendar-using-client-om-js/

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, January 9, 2017 7:30 AM
    Moderator
  • Hi Dennis,

    Thanks for your answer, however the sample/first link are JavaScript based and I'm building a Windows Service with C#. And the second link seems to return just the events for today. I need to return for up to two months ahead.


    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    Se achou este post útil, por favor clique em "Votar como útil". Se por acaso respondeu sua dúvida, lembre de "Marcar como Resposta".

    Monday, January 9, 2017 3:45 PM
  • Hi,

    If you want to get the two months ahead, please change <Today/> to

    <Today OffsetDays="-60" />

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, January 10, 2017 2:28 AM
    Moderator