Years ago when Microsoft released it’s latest version of SharePoint Designer, it came with a few enhancements that really made building workflows with Designer more robust and efficient. One efficiency enhancement was the ability to copy actions, steps and even entire stages within the same workflow or even between workflows. Microsoft also allowed for the ability to move back and forth between stages instead of continuing down a parallel path (called a state machine workflow). While the addition of state machine workflows to Designer (previously only available in Visual Studio workflows) is great; in my opinion the best (by a very small margin) addition to Designer is the ability to call web services. As your queries get more and more complex however, knowing what is coming back into the workflow can be filled with frustration as you try to determine how to get the data from the response content. While I it isn’t a new concept, I wanted to discuss handling REST responses in SharePoint Designer workflows. Or at least how I do it. The method I use is pretty straight forward and very easy to implement.
So recently at my client site we had a report that was running incredibly long. This was a while ago, so unfortunately I can’t remember the run time, but I believe it was greater than 12 hours. The report was pretty basic, just a determination of which documents were created within the month and an output that displayed things like location, file name, created date and creator.
When reviewing the code I noticed the original solution had been coded to loop through each site in the web and then grab all the documents within a particular date range. The line in particular that scanned the documents was as follows:
[code language=”csharp”]
var listAddedItems = listItems.Where(x => ((DateTime)x["Created"] >= reportManager.ReportStartDate && (DateTime)x["Created"] <= reportManager.ReportEndDate) || ((DateTime)x["Modified"] >= reportManager.ReportStartDate && (DateTime)x["Modified"] <= reportManager.ReportEndDate));
[/code]
Pretty straight forward, but what it’s actually doing is going through and gathering all the data and throwing out what you don’t need. Not a big deal unless you are working with a lot of data. Right now we are sitting at around 1 million items in our SP farm. I think I found the culprit.