I got one of those “red alert”, “all hands on deck” emails this morning. Someone was trying to find all of the Document Libraries in a Site Collection with a certain name that had at least one item. They were trying to solve some specific client problem (I know not what!) and it was a numero uno emergency.
It would seem that this would be a simple question, but there’s no easy way to do this in SharePoint out of the box. They thought of the Content Query Web Part but weren’t sure if it would help them. I wasn’t sure, either.
Being the Middle Tier guy that I am, I thought of two potential ways to get a solution: a DVWP with DataSourceMode=”CrossList” or SPServices. They had one more rule: no SharePoint Designer, so the former was out. SPServices seemed like a perfect way to get a fast answer.
The basic solution is pretty simple:
- Call GetAllSubWebCollection to find all of the sites in the Site Collection
- For each site, call GetListCollection
- For each list in the site, check to see if it is the right list, and if the ItemCount is non-zero, pop up an alert
At least this was a good start to solving the problem. I tossed together the script below in about 20 minutes (I forgot some of the syntax and had to read the docs!). In this example, I look for lists where Title=”Announcements”.
Just dropping this script into a Content Editor Web Part somewhere would let them know where these pesky lists were. No fuss, no muss, no server-side code. Sure, it’s not pretty, but it’ll get the job done. The point is that SPServices and jQuery can be used for little quick stuff like this pretty easily when you need a fast answer.