Friday, August 23, 2013

SharePoint Workflow Triggers - Email Item Does Not Exist

I made a valuable discovery when troubleshooting a VS2010 sequential workflow. I had created a document library in SharePoint 2010 to receive email, then implemented an override on the event receiver SPEmailReceived to capture other facets of the email, as well as catch and wipe colons (For example "FW:"), as "odd" characters, such as ": . / \". I had designed the workflow to be triggered when a new item was "created" or added to the document library, and this is where the trouble started - it would complete ~75% of the time when fired, producing an error that the email object did not exist. I realized that the receiver override was still invoking changes and collecting information when the "created" trigger would fire. To fix this, I set the workflow trigger to "on change", which does not begin to fire until after the item has been created with the event receiver override steps completed.