Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have an event receiver, and I'm capturing the "ED" events (Added, Edited). I also have a Workflow on the list that is triggered on Item Added and Updated. Does the workflow get called before the event receiver or after?

share|improve this question
    
I have wondered this too. Thanks for asking! –  James Grizzle Nov 6 '12 at 14:15
    
Hi kurtnelle, just leaving a notice here. I have retagged your question with some more specific tags - we prefer to leave the 2010 tag only for question that are really specific to that SharePoint version. Fell free to re-add it if you belive it is the case (for example because you have evidence that the behaviour has changed from SP2007), otherwise is enough to reference the SharePoint version in the question. If the need arise, you could just add the tag later. –  SPArchaeologist Nov 6 '12 at 14:41
    
Also notice that more specific tag will help to draw more people to the question, and improve search for any user with the same problem in the future. –  SPArchaeologist Nov 6 '12 at 14:44
    
@SPArchaeologist, makes sense. Thanks much –  user2903 Nov 6 '12 at 15:07
    
possible duplicate of Execution order of event receivers and workflow on a list –  Vikalp Kapadiya Jul 1 '13 at 7:01

3 Answers 3

up vote 3 down vote accepted

I found the following answer by Chris O'Brien

If a list has workflows defined which are set to auto-start, these will always execute before any other 'ItemUpdated' or 'ItemCreated' event receivers by default. It is possible to re-order these in code however - I needed to do this once as for some reason I needed a receiver to fire before the workflow did it's processing. To re-order, simply get the SPList.EventReceivers and modify the Sequence property of each one you want to change (and call .Update()).

Remember though, that if someone disables workflow and then configures it again (with auto-start), SharePoint will add the SPWorkflowAutostartEventReceiver back in as Sequence=1, meaning the re-ordering would need to happen again.

share|improve this answer
2  
In addition check Synchronization property. Set it to Synchronous to guarantee your code run before workflow. msdn.microsoft.com/en-us/library/… –  Dmitry Kozlov Nov 6 '12 at 14:34
1  
So, its more about determining when the SPWorkflowAutoStartEventReceiver, EventReceiver executes. That makes perfect sense. –  user2903 Nov 6 '12 at 15:08

If you want the -ed ending events to be executed before the workflow, you should set them as synchronous events and not as asynchronous which is the default value. If so (synchronous), the events will always be executed before the workflow.

share|improve this answer

Events Added and Updated run asynchronously by default. So workflow can run before your event handler as well as after. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverdefinition.synchronization.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.