Tuesday 29 September 2015

SharePoint 2013 Filter Items Using Rest API

 function GetProjects() {
                var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + projectListName + "')/items?" + "$filter=((substringof('" + user.get_title() + "',Members)) and (ProjectStatus+eq+'Open'))";
                $.ajax({
                    url: url,
                    type: "GET",
                    headers: { "accept": "application/json;odata=verbose" },
                    success: function (data) {
                       for (var i = 0; i < data.d.results.length; i++) {
                            var project = data.d.results[i].Title;
                          
                        }
                      
                    },
                    error: function (xhr) {
                        alert(xhr.status + ': ' + xhr.statusText);
                        console.log(xhr.status + ': ' + xhr.statusText);
                    }
                });
            }

-----------------------------------------------------------------
Filter on Date Fields
------------------------------------------------------------------




    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl +
            "/_api/lists/getbytitle('TimesheetEntry')/items?$filter=Date+gt+'" + FromDate + "' and Date+le+'" +ToDate + "'",
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            if (data.d.results.length > 0) {
                $.each(data.d.results, function (i, item) {
                  var a=  data.d.results[i].Date;
                  var b=  data.d.results[i].User;
                });


            }
        },
        error: function (err) {
            console.log(JSON.stringify(err));

        }
    });