2

I have a SP Service call which uses GetListItems from a calendar list in SharePoint. I'm using it with the FullCalendar plugin. The events render fine that is not my question, my question is this:

Is there a way to identify what months you want to extract data from via caml query or something? When I go into debugging, I can see that the only info that is being returned is from the current month, even though in the ShraePoint list, there is info in every month.

Here is the code:

function getHolidayCalenderEvents(){

        var events = [];
        //var holidayEvents = [];

        $().SPServices({
              operation: "GetListItems",
              listName: "Holiday",
              completefunc: function(xData, Status) {
                console.log(xData.responseText);
                //$(xData.responseXML).find("Fields > Field").each(function() {
                $(xData.responseXML).SPFilterNode("z:row").each(function() {
                    var $node = $(this);

                    var fADE = $( this ).attr( 'ows_fAllDayEvent' );
                    var thisADE = false;
                    var thisStart;
                    var thisEnd;


                    if ( typeof fADE !== "undefined" && fADE !== "0" ) {
                        thisADE = true;
                        var thisStart = $( this ).attr( 'ows_EventDate' );
                        var thisEnd = $( this ).attr( 'ows_EndDate' );
                    }
                    else {
                        // Get the start and end date/time of the event. FullCalendar will parse date strings in local time automagically, so we need to convert the UTC 
                        //date strings from SharePoint into local time. The formatDateToLocal() function above will take care of this. See comments in that function for more information.
                        var thisStart = $( this ).attr( 'ows_EventDate' );
                        //thisStart = thisStart.substring(0,9);
                        var thisStartDate = moment(thisStart);
                        var thisEnd = $( this ).attr( 'ows_EndDate' );
                        //thisEnd = thisEnd.substring(0,9);
                        var thisEndDate = moment(thisEnd);
                    }
                    var thisID = $( this ).attr( 'ows_ID' ).split( ';#' ).join( '.' );

                    // FullCalendar documentation specifies that recurring events should all have the same id value when building the events array (the id is optional, 
                    //but I'm including it for completeness). We can get the list item ID (which is the same for all instances of recurring events) without the recurrence 
                    //information by simply splitting thisID.
                    var eventID = thisID.split( '.' )[0];

                    // Get the event title. This is displayed on the calendar along with the start time of the event.
                    var thisTitle = $( this ).attr( 'ows_Title' );

                    // Get the event description. I don't use it in this example, but you could use it for something, perhaps as a tooltip when hovering over the event.
                    var thisDesc = $( this ).attr( 'ows_Description' );

                    // Add the event information to the events array so FullCalendar can display it.
                    events.push({
                        title: thisTitle,
                        id: eventID,
                        description: thisDesc,
                    });

                    $('#calendar').fullCalendar('addEventSource', {
                        events: events,
                        color:'#66CCFF',
                        allDay: true

                        });

                    events = [];

                });


            }


        });


    }

The code works as it renders all events in the current month, I just would like to know how to make it return data from all months if anybody has experienced any personal problems like this.

Thank you in advance for all the help.

4 Answers 4

0

You can use the property defaultView: "month". This will display the calendar in Month View.

Take a look at http://joshmccarty.com/2011/11/sharepoint-jquery-and-fullcalendar%E2%80%94now-with-spservices/

For changing month, first you need to calculate the start. Then you can use that value in camlQuery and camlOptions.

1
  • I have the defaultView: "month" declared in my rendering of the main calendar already, so that isn't it. Thank you for the link I have not yet stumbled across this source!
    – BesaseB
    May 12, 2015 at 13:20
0

I recommend this counter trick for returning all records from a list. You're probably only getting the current month because you haven't declared a view or a CAML query, so you're getting data from the default view, which is probably the current month.

Alternatively, you could create a list-style view of all events in your Calendar list.

0

You have to add some specifics to the CAML request to have a calendar expand out everything. When I get a calendar using SPServices I use the following - it expands recurring items and gets a full year.:

var queryOptions = "<QueryOptions><ExpandRecurrence>TRUE</ExpandRecurrence></QueryOptions>";
var query = "<Query><Where><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\" /><Value Type='DateTime'><Year/></Value></DateRangesOverlap></Where></Query>";

$().SPServices({
              operation: "GetListItems",
              listName: "Holiday",
              CAMLQueryOptions: queryOptions,
              CAMLQuery: query,
   // etc.... 
0

I would recommend REST API instead of SPService to get the list items from calendar list. In SharePoint REST API 2010 you can filter the items using month or you can data for all month.

1
  • The REST API is great, except you cannot retrieve recurring events as single events. It will show for every single day throughout its duration instead of each recurring date.
    – dcclassics
    Apr 20, 2018 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.