Hi experts,
I am experiencing weird issue. Sometimes my workflows run, sometimes they don't.
I have built a SPD reusable workflow for a content type.
I then created a list, and add this workflow to my list.
There is an ItemAdded receiver with the following code:
Guid siteID, webID, listID;
int itemID;
listID = properties.ListId;
itemID = properties.ListItem.ID;
using (SPWeb web = properties.OpenWeb())
{
siteID = web.Site.ID;
webID = web.ID;
}
//Use elevated permission
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb(webID))
{
web.AllowUnsafeUpdates = true;
SPListItem item = web.Lists[listID].GetItemById(itemID);
if (item != null)
{
StartWorkflow(item, contentTypeName, workflowName);
}
web.AllowUnsafeUpdates = false;
}
}
});
private static void StartWorkflow(SPListItem listItem, string contentTypeName, string workflowName)
{
SPWorkflowAssociation wfAssoc = listItem.ContentType.WorkflowAssociations.GetAssociationByName(workflowName, System.Globalization.CultureInfo.CurrentCulture);
listItem.Web.Site.WorkflowManager.StartWorkflow(listItem, wfAssoc, wfAssoc.AssociationData, true);
listItem.Update();
}
When I debug it, my receiver is called every time a new item is created. However, sometimes the StartWorkflow line throws error
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: <nativehr>0x8102008a</nativehr>
I tried the recommended solution from this article :
http://social.technet.microsoft.com/forums/sharepoint/en-US/53db57ac-c4b5-448e-9b2d-c8e17b8055df/workflow-intermittently-does-not-start
but it doesn't help.
Any ideas?
Thanks,
Andreas