I have a site workflow that makes a web request to SharePoint's Search API using the REST interface. When I manually execute the workflow it works every time, but when running it as a scheduled workflow I am getting random errors, once it was SearchServiceException, then it was EndPointNotFound, then a generic timeout. Has anyone else seen this or can point me in the direction of what may be the culprit?
Solved! Go to Solution.
Who published and set the schedule of the workflow? Was is a farm account/system account? That may be the issue. But when it manually ran it ran under a different user context. I always check permissions first before troubleshooting logic.
Put those query actions within an action set and in the common tab settings have it set to run as owner. I believe action set has this setting, if not you can do this in a run if.
Thank you! So far that seems to have done the trick. I'm a bit confused as to why though since I was setting the credentials to a service account in my Web Request action so expected the request to execute using those credentials. Assuming there is some other layer in between that I don't know about yet.
It's actually a difference in context, more than the request permission. When a scheduled workflow starts, it is executed from the SharePoint workflow timer service, a part of the OWStimer which is running most times as the system account. This is running the application services layer instead of the app pool user layer. When I write code that operates the same way I have to specify RunWithElevatedPrivileges to get the app pool context first, then execute the action with my impersonation. This would work in the same way, first get the user context with running as owner, then use the web request credentials to do the actual query. Hope that makes sense.
That explanation makes perfect sense to me and helps clarify how scheduled workflows are executed. Unfortunately, I spoke too soon regarding this one, when I scheduled it yesterday it completed successfully, but failed again this morning. It is very odd because I have other things going on in this workflow like a SQL Request and a few list updates and those all complete successfully, it's just when I throw the Web Request in the mix that it starts failing.