2

I used SPServices to create and get a list of custom DocSets. There were some problems with that, so I wrote the code to create them with REST services. And that works properly.

I'm trying to rewrite the get a list part and running into troubles. I'm selecting the ID, Title and ItemChildCount like so...

 url: webURL + "/_api/web/lists/getbytitle('" + listName + "')/items?$select=ID,Title,ItemChildCount&$filter=FSObjType eq 1"

But I get an error.

The field or property 'ItemChildCount' does not exist.

When I use SPServices I get the expected values for ItemChildCount. The same thing with ProgID -- works with SPServices, but not with REST.

I found this list which confirms the internal names.

And this one post about ItemChildCount not showing up.

I did create a new library, added some OOTB Document sets--not the custom one I'm using in my other library. I created them using the regular UI--not SPService nor REST. Added some children to them. And I get the same error.

So how would I go about getting ItemChildCount for a DocumentSet using REST services?

5

You have to expand folder with $expand=Folder property and use ItemCount property of the folder like this:

/_api/web/lists/getbytitle('your_list')/?items$select=ID,Title,Folder/ItemCount&$expand=Folder/ItemCount&$filter=FSObjType eq 1
  • Thank you, that is genius. I'm totally new to the REST api. I had seen $expand, but didn't understand the documentation or how I would figure it out. Do you have any pointers or tutorials I should look at? – Rothrock Jun 5 '15 at 15:37
  • You can try to look through the MSDN, which I believe you did. And this map is really helpful. And one good article – ECM4D Jun 5 '15 at 18:31
0

Ah I think I found it. I was using the wrong end point.

According to this way down the page in the folder collection resource section.

http://<site url>/_api/web/getfolderbyserverrelativeurl('/<folder name>')/folders

That does return all the "folders" (and the DocSets are folders). And they all have an ItemCount property. But now I can't seem to $select any other properties...I can even make ones up and it just happily goes along with it, but doesn't return anything other than the built in ones described on that page.

There is also a "Forms" folder in there that must be some hidden background something or other. I wonder if other hidden folders will appear from time to time....

-1

I don't think that is available as a Property in 2013 REST end point. URL you posted is related to 2010 REST EndPoint ListData.svc. Also SPServices uses Web Service interface and not REST interface.

I would recommend you get the item count OnSuccess method

url: webURL + "/_api/web/lists/getbytitle('" + listName + "')/items?$select=ID,Title&$filter=FSObjType eq 1"

function onSuccess(data) {
    var stringData = JSON.stringify(d);
    var jsonObject = JSON.parse(stringData);
    var results = jsonObject.d.results;
    alert(results.length);
}
  • Thanks for the suggestion. Eventually I'll have hundreds of docsets returned and each will have zero to many children. I'm not sure this approach would work for that. It seems like I would have to do a lot of iterations of iterations of items... – Rothrock Jun 4 '15 at 23:59

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.