SharePoint 2013 Running workflow programmatically StartWorkflow error FAILED hr detected (hr = 0x8102008a)

Hello,

Just want to share something in regards to starting workflow using the Workflow Manager in code.

I have built a SPD reusable workflow for a content type.
I then add this workflow to my list in my site.

As I want to be able to trigger this workflow anonymously, I have to run the workflow using WorkflowManager instead of the standard auto start from UI (Otherwise the workflow will be created but will not run)

Originally I used the ItemAdded event receiver, then use this piece of code:


StartWorkflow function:


But my workflows only get triggered for some records (intermittently). When I run the debugging, I can see that a weird error is thrown:

An exception of type 'Microsoft.SharePoint.SPException' occurred in Microsoft.SharePoint.dll but was not handled in user code

FAILED hr detected (hr = 0x8102008a)
in the log : COMException: 0x8102008a


Looking around for solution I couldn't find the answer.


After some trials and errors, I noticed that my code doesn't throw that error when I call item.Update() before my StartWorkflow function.


However it sometimes throws Save Conflict Your changes conflict with those made concurrently by another user when I tested creating my list items in a quick manner.


I soon realised that it is because ItemAdded receiver is by default running asynchronously.


Since I also use my custom save functionality on my list item, I moved my code to be part of it. After the attachment functionality (described in my previous post), I just call my workflow.


Completed code:




If you still want to use ItemAdded receiver you should be able to make it work as well. Just make it run as a synchronous event rather than asynchronous.


Hope this helps,
Andreas

Comments

Popular posts from this blog

SharePoint 2013 anonymous access add attachments to list item

CRM Plugin - Parent and Child Pipeline

Sitecore custom publish agent from specific node and at a specific time