0

I have a list which contains an end date, I want to query this list and only collect the items which end date have not passed todays date. Once this has happened I want to count the new queried table. Here is my code, this does not work.

function retrieveCurrentListProperties() {
    clientContext = new SP.ClientContext.get_current();
    web = clientContext.get_web();
    var list = web.get_lists().getByTitle("Urgent Alerts");
    var camlQuery = new SP.CamlQuery();
    var q =  "<View><Query><Where><Leq><FieldRef Name='End_x0020_Date' /><Value Type='DateTime' IncludeTimeValue='FALSE'><Today /></Value></Leq></Where></Query></View>";
    camlQuery.ViewXml(q);
    this.listItems = list.getItems(camlQuery);
    clientContext.load(this.listItems);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onCListItemsLoadSuccess), 
    Function.createDelegate(this, this.onQueryFailed));

}

function onCListItemsLoadSuccess(sender, args) {

    var count = 0;
    var listEnumerator = this.listItems.getEnumerator();
    //iterate though all of the items

count = this.listItems.get_count();
var allAlerts = document.getElementById('allAlerts');
allAlerts.innerHTML = 'Total Alerts : ' +count;


}
0

In the CAML Query, you need to set the view XML as:

 camlQuery.set_viewXml(q);
  • if I replace ViewXml with set_viewXml I get the error request failed one or more field types are not installed properly. go to the list settings to delete these fields undefined – dave Mar 31 '14 at 15:39
  • The FieldRef you're using 'End_x0020_Date' is that the correct one? Try replacing that with '_EndDate' if you're using OOTB fields. – Aveenav Mar 31 '14 at 15:50
  • I named the field 'End Date' which didn't work, so I've been trying numerous ways to include the space in the search – dave Mar 31 '14 at 15:54
  • Did you try "_EndDate" ? – Aveenav Mar 31 '14 at 15:55
  • That gives me the same error as before – dave Mar 31 '14 at 15:56

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.