Quantcast
Channel: Question and Answer » json
Viewing all articles
Browse latest Browse all 148

Getting an ItemCount with filtering in SP2013 using REST api

$
0
0

I am attempting to return an integer (itemcount) of the items within a SP2013 list. I have done this easily using the stock standard json method. However I have a need of counting the splist items which contain a certain value. My silly knowledge immediately lead me to try and use filtering with the ItemCount parameter only to find out that it will always still return the count for all items and it will completely ignore the filter. I have searched for a way of doing this but have found absolutely nothing other than a single page with a comment stating that it is not possible with the REST api and that it can ONLY be done using CSOM.

My question is, firstly, is it true that there is NO way to filter itemcount with REST? If so, how else can I obtain my item count using this type of filtering? (Examples or sources will help vastly)
Thanks.

Below is my attempted request:

var itemid = item.id;
          MyService.ensureFormDigest(function (fDigest) {
              $http.get(
                  MyService.appWebUrl + '/_api/web/Lists/getbytitle('Items')/ItemCount?$filter=SubjectsID eq' + itemid,
                  {
                      headers: {
                          'Accept': 'application/json; odata=verbose',
                          'X-RequestDigest': fDigest
                      }
                  }).success(function (d) {
                      item.itemcode = d.d.ItemCount;
                      alert(item.itemcode);
                      callback();
                  }).error(function (er) {
                      alert("Error getting List Item Count: " + er);
                  });
          });
      }

On another note, I was advised to try it as such: /Items?$filter=SubjectsID eq 3&$select=Id

Then in the JS, in my success method:

data.d.results.length

Viewing all articles
Browse latest Browse all 148

Trending Articles