0

I'm trying to get recurring items for a specific month from a list.

Using the following, I can get the events for the current month:

<Query>
    <Where>
        <DateRangesOverlap>
            <FieldRef Name="EventDate" />
            <FieldRef Name="RecurrenceID" />
            <Value Type="DateTime">
                <Month />
            </Value>
        </DateRangesOverlap>
    </Where>
</Query>

I've looked through the prototype of JSOM's SP.CamlQuery(), but it doesn't offer a property similar to C#'s SPQuery.CalendarDate.

Is there a way to specify a date relative to which to fetch items from the JSOM?

1 Answer 1

1

I solved this by invoking a webservice call using SPServices library.

I got the CAML query from this site

For reference I am copying code below

GetItemsFromCalendarAsmx = function (webUrl, calendarGuid) {

    wsURL = webUrl + "_vti_bin/Lists.asmx";

    var xmlCall =
        "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body>" +
        "<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" +
        "<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;
};
1
  • While it isn't a beautiful solution, it works. Thanks a lot for this.
    – Etheryte
    Jan 15, 2015 at 17:31

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.