0

So I'm using CMAL and SPServices to query a custom Events List to an HTML table. It works just fine with just a SortBy tag with the following code:

function getEventList() 
{
        var method = "GetListItems";                 
        var webURL =  $().SPServices.SPGetCurrentSite() ;                     
        var list = "UpcomingEvents";                      
        var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Title' />" +"</ViewFields>"; 
        var query = "<Query>" +
                    "<OrderBy>" + 
                        "<FieldRef Name='ID' Ascending='TRUE'/>" +
                    "</OrderBy>" +
                    "</Query>";

        $().SPServices({
                operation: method,
                webURL: webURL,
                listName: list,
                CAMLViewFields:  "<ViewFields Properties='True' />",
                  CAMLQuery: query,
                  CAMLRowLimit: 5,
                    completefunc: function (xData, Status) { 
                        $(xData.responseXML).SPFilterNode("z:row").each(function() { 
                            var name = ($(this).attr("ows_Title")); 
                            var desc = ($(this).attr("ows_Description"));
                            var date = ($(this).attr("ows_Date"));

                            $("#upcomingEventsTable").append(
                            "<tr align='middle'>" + 
                                "<td>" + name + "</td>" +
                                "<td>" + desc + "</td>" +
                                "<td>" + date + "</td>" +
                            "</tr>");
                        });                
                    }
        });
}

What I want to do is show just the upcoming 5 items starting from today's date. I've tried using the Today and TodayISO tags to compare it to the items' date, but the query doesn't show up all together (indicating a query error) whenever I put the Where conditions. I have no access to U2U, so I can't identify what the problem in my query is. This is what I'm trying;

var query = "<Query>" +
                "<Where>" +
                    "<Geq>" +
                            "<FieldRef Name='Date' />" +
                            "<Value IncludeTimeValue='FALSE' Type='DateTime'>"+"<TodayISO/>"+"</Value>"+
                    "</Geq>" +
                "</Where>" +
                "<OrderBy>" + 
                    "<FieldRef Name='ID' Ascending='TRUE'/>" +
                "</OrderBy>" +
           "</Query>";

I'm assuming there's a problem with date format missmatch. The result on the table shows that it's using an ISO-like format. I'm not sure if it has the exact same format as TodayISO tag. result table

0

It seems your query is being malformed, can you please put error message..

Also can you try below things to troubleshoot.

  1. First try to add Date field in your view fields also...
  2. Next try to just put a simple query where condition based on ID(other they date type of column)
  3. Next try to filter based on Date Field by giving static date in value...
  4. Then try to put <Today /> in your query,

Above options will eliminate that there is syntax error in your query or something wrong with date format value.

  • I'm face palming so hard now. I just missed including the other fields on the view field var, so it simply had nothing to compare to. Thanks for pointing that out! The queries are working just fine, I just couldn't see what was wrong because I'm working on a browser on SP, so there was no error message relating to the queries.. – Akhmad Agosto Nov 3 '16 at 8:32
  • :) np...please mark it as answer :) – Siddharth Vaghasia Nov 3 '16 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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