AnsweredAssumed Answered

How to speed up For Each action

Question asked by amccollough on Nov 21, 2014
Latest reply on Dec 8, 2014 by amccollough

I have (had!) a nightly scheduled site NW2010 workflow which would empty a SharePoint list, and populate it with data from an external list. I did this by first grabbing the IDs of the records in the external list into a workflow variable scoped as a collection. I then did a For Each loop over that variable, and for each instance, it would do a query to get the entire row of data from the external list for the current item, and insert that data into a a new row in the SharePoint list.


This worked great in theory. In practice, though, the workflow takes almost 12 hours to run, because there are 145 items, and the For Each is adding an unwelcome 5 minute delay for each iteration of the loop! I searched here and saw the culprit is apparently the "Safe Looping" enabled in Central Admin. I turned Safe Looping off in Central Admin, republished, and the next day, well, the script is still running. Apparently, turning off "Safe Looping" doesn't stop the comically unacceptable 5-minute delay per loop iteration.


So my question is, is there a way to disable that delay in each iteration of the For Each action?


(side note: I rewrote the whole thing as a PowerShell script, and it now takes about 20 seconds to run)