4

I need to run a workflow on all items in a library. This SPServices example seems like a good plan but I'm running into problems.

The library has folders and the CAML query returns only the folders, not the individual items. I have tried CAML - How to filter folders from result set but I can only use the Where clause in the SPServices call and cannot set the scope to recursive.

Another option is the HarePoint Workflow Scheduler. If I run it on a list view that shows only the documents, nothing happens. If I set the CAML query in the tool itself, I can again only use the Where clause.

The library has way over 5000 items, hence the folders. I was planning to use view filters to work on batches of less than 5000, so the view threshold is not breached. Maybe there is a way to use SPServices to iterate over a subset of items that does not breach the view threshold?

Ideas welcome, as long as they don't involve Visual Studio. I'm fine with SPD and JavaScript.

6

The trick is to set the CAMLQueryOptions so that you get all the items regardless of what folder they are in. It's sort of like the "folderless" option in a view's settings.

CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope='RecursiveAll' /></QueryOptions>";

The GetListItems documentation on MSDN is a little light on these options. Take a look at the docs for GetListItemChangesSinceToken, which spells them out more clearly.

If you get folders back in the results (usually because your other filters haven't excluded them), the filter to remove them is:

<Neq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Neq>

You can either add that to the CAMLQuery or just filter out those items in the results when you are looping through them.

  • Thank you so much. That did the trick and saved my weekend. I ended up using 'UpdateListItems' instead of 'StartWorkflow'. Cripes! I can't believe how much faster that is. – teylyn Aug 22 '14 at 4:52
0

Why can't you set the scope to recursive? Because of the amount of items you're retrieving or because it's not supported in CSOM (Not sure about this)? Have you tried filtering by a set amount. For example, retrieving the top 5000, then the next 5000, etc.

Quick CAML Designer result:

ClientContext clientContext = new ClientContext("your site"); 
Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("documents"); 
clientContext.Load(spList); 
clientContext.ExecuteQuery(); 

if (spList != null && spList.ItemCount > 0) 
{
   Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery(); 
   camlQuery.ViewXml = 
      @"<View>  
            <Query> 
               <Where><And><Geq><FieldRef Name='ID' /><Value Type='Counter'>1</Value></Geq><Lt><FieldRef Name='ID' /><Value Type='Counter'>5000</Value></Lt></And></Where> <QueryOptions><ViewAttributes Scope='Recursive' /></QueryOptions>
            </Query> 
             <ViewFields><FieldRef Name='FileLeafRef' /></ViewFields>
      </View>";  

   ListItemCollection listItems = spList.GetItems(camlQuery);
 } 
  • Thanks for your answer. Unfortunately, I could not get this to run at all. – teylyn Aug 22 '14 at 4:54

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.