1

This is the chunch of code that I am working with. I am trying to get only the events (normal/all day/recurring) to show, and it is returning all items for the whole week. Any ideas?

            $(document).ready(function(){
            $().SPServices({
                operation: "GetListItems",
                async: false,
                listName: "Calendar",
                CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
                CAMLQuery: '<Query>' +
                            '<Where>' +
                                '<DateRangesOverlap>' +
                                '<FieldRef Name="EventDate" />' +
                                '<FieldRef Name="EndDate" />' +
                                '<FieldRef Name="RecurrenceID" />' +
                                '<Value Type="DateTime">' +
                                    '<Today />' +
                                '</Value>' +
                                '</DateRangesOverlap>' +
                            '</Where>' +
                            '</Query>',
                completefunc: function (xData, Status){
                    $(xData.responseXML).SPFilterNode("z:row").each(function(){
                        var lihtml = "<li>" + $(this).attr("ows_Title") + "</li>";
                        $("#calendarItems").append(lihtml);
                    });
                }
            });
        });

3 Answers 3

5

Sorry for not getting back to you sooner. I was in training and then extremely ill the last 30ish hours.

Take a look at this post by Josh McCarty: http://joshmccarty.com/2011/11/sharepoint-jquery-and-fullcalendar%E2%80%94now-with-spservices/, wherein he followed some details I posted in this discussion on the SPServices codeplex site: http://spservices.codeplex.com/discussions/254560

I'm still not feeling 100% and have lots of catchup to do on my own job. If you're still struggling with this on Monday, let me know and I'll try to take a deeper look.

Blessings,

Jim Bob

Update: There are a couple option Query Options you need to add to get the expanded data from recurrent dates. Give the following a try and let me know how close you get.

<script type="text/javascript">

    $(document).ready(function(){
        $().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "Calendar",
            CAMLViewFields: "<ViewFields>" +
                    "<FieldRef Name='Title' />" +
                    "<FieldRef Name='EventDate' />" +
                    "<FieldRef Name='EndDate' />" +
                    "<FieldRef Name='Location' />" +
                    "<FieldRef Name='Description' />" +
                    "<FieldRef Name='fRecurrence' />" +
                    "<FieldRef Name='RecurrenceData' />" +
                    "<FieldRef Name='fAllDayEvent' />" +
                "</ViewFields>",
            CAMLQuery: "<Query>" +
                    "<Where>" +
                        "<DateRangesOverlap>" +
                            "<FieldRef Name='EventDate' />" +
                            "<FieldRef Name='EndDate' />" +
                            "<FieldRef Name='RecurrenceID' />" +
                            "<Value Type='DateTime'>" +
                                "<Today />" +
                            "</Value>" +
                        "</DateRangesOverlap>" +
                    "</Where>" +
                    "<OrderBy>" +
                        "<FieldRef Name='EventDate' />" +
                    "</OrderBy>" +
                "</Query>",
            CAMLQueryOptions: "<QueryOptions>" +
                    "<RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>" +
                    "<ExpandRecurrence>TRUE</ExpandRecurrence>" +
                "</QueryOptions>",
            completefunc: function (xData, Status){
                    $(xData.responseXML).SPFilterNode("z:row").each(function(){
                        var lihtml = "<li>" + $(this).attr("ows_Title") + "</li>";
                        $("#calendarItems").append(lihtml);
                    });
                }
            });
        });

</script>
3
  • Jim, To no avail.... I followed that tutorial for a bit, but didn't integrate the fullcalendar plugin because we don't need that. I am still not able to get this to function correctly. Commented Apr 16, 2012 at 13:11
  • Right. The fullcalendar implementation isn't as important as how to pull the dates. Updating answer above. Commented Apr 17, 2012 at 14:35
  • How can I change <Today /> to another date?
    – Carlos
    Commented May 11, 2016 at 18:10
1

The last example code is missing the CAMLOptions option that tells SharePoint to expand recurring events. Otherwise it should produce the desired results. I tested this and it showed all events that overlap today or start today. It also showed an all day event for tomorrow, which is probably a time zone setting issue.

$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Calendar",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='Location' /><FieldRef Name='Description' /><FieldRef Name='fRecurrence' /><FieldRef Name='RecurrenceData' /><FieldRef Name='RecurrenceID' /><FieldRef Name='fAllDayEvent' /></ViewFields>",
    CAMLQuery: "<Query><CalendarDate><Today /></CalendarDate><Where><DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'><Today /></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name='EventDate' /></OrderBy></Query>",
    CAMLOptions: "<QueryOptions><CalendarDate><Today /></CalendarDate><RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion><ExpandRecurrence>TRUE</ExpandRecurrence><DateInUtc>FALSE</DateInUtc></QueryOptions>",
    completefunc: function (xData, Status){
        $(xData.responseXML).SPFilterNode("z:row").each(function(){
            var lihtml = "<li>" + $(this).attr("ows_Title") + "</li>";
            $("#calendarItems").append(lihtml);
        });
    }
});
0

None of the solutions above worked for me in SP 2013 but this did.

<Where>
<Or>
    <Or>
        <And>
            <Eq>
                <FieldRef Name='fAllDayEvent' />
                <Value Type='AllDayEvent'>1</Value>
            </Eq>
            <Geq>
                <FieldRef Name='EndDate' />
                <Value Type='DateTime'>
                    <Today />
                </Value>
            </Geq>
        </And>
        <DateRangesOverlap>
          <FieldRef Name='EventDate' />
          <FieldRef Name='EndDate' />
          <FieldRef Name='RecurrenceID' />
          <Value Type='DateTime' IncludeTimeValue='TRUE'>
            <Today />
          </Value>
        </DateRangesOverlap>
    </Or>
   <Geq>
      <FieldRef Name='EventDate' />
      <Value Type='DateTime' IncludeTimeValue='TRUE'>
         <Today />
      </Value>
   </Geq>
</Or>
</Where>

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.