1

I am trying to use the javascript object model to retrieve multiple lists from the current web.

I am able to get them all and then filter out through an if condition, but ideally I would like to build up a query so I can only get the lists I want right out of the returned query (like Linq in C# or CAML in GetListItems).

var context = new SP.ClientContext.get_current();
var web = context.get_web();
var lists = web.get_lists();

context.load(lists, 'Include(RootFolder, Title, BaseTemplate, Hidden)');
context.executeQueryAsync(
   ...
   if(list.get_baseTemplate() === 101)
   {
      //do stuff
   }
)

So is there any way I can do something like this in javascript?

context.loadQuery(lists.Where(l => l.BaseTemplate == 101));

I've found an example using REST, I'm just not sure it this makes sense as I was hoping to stick with csom. Anyway, I'd like to hear some thoughts on how to best tackle this, as I'm sure retrieving all lists will bring an additional unecessary overhead.

Is it possible to retrieve lists with specific template?

  • 1
    Sadly there is no CSOM interface that has an option to filter like that. You could use the search but then you would loose real time results. Im sure though that even getting a huge amount of lists (5000+) should be quite performant if you include only the ID and the BaseTemplate. That way you can identify the desired lists and load the missing properties afterwards. – Mx. Oct 19 '16 at 11:58
2

Sadly there is no CSOM interface that has an option to filter like that. You could use the search but then you would loose real time results.

But Im sure though that even getting a huge amount of lists (5000+) should be quite performant if you include only the ID and the BaseTemplate. That way you can identify the desired lists and load the missing properties afterwards.

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.