Error when adding workflow to more than one list - Exception from HRESULT: 0x80131904

Hi,

I'm trying to add a feedback workflow to several lists with the BaseTemplate 101 via feature activated event receiver.

My problem is, that the first list works fine, but the second fails with the error:

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

Additional information: Exception from HRESULT: 0x80131904

If I leave the first list out, add the workflow to the second it will still fail at the third list and so on...

This is the code that I'm using in the EventReceiver. I marked the point at the end where the error happens.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            string taskListTitle = "WorkflowTasks";
            string historyListTitle = "Workflow History";
            
            SPWorkflowTemplate collectFeedbackWorkflowTemplate = null;

            //Initializing with workflow template IDs 
            Guid collectFeedbackWorkflowTemplateID = new Guid("3bfb07cb-5c6a-4266-849b-8d6711700407");

            //Get Lists
            SPListCollection lists = web.Lists;

            //Getting workflow template based on workflow id
            foreach (SPWorkflowTemplate template in web.WorkflowTemplates)
            {
                string templateName = template.Name;
                if (template.Id.Equals(collectFeedbackWorkflowTemplateID))
                {
                    collectFeedbackWorkflowTemplate = template;
                    
                }
            }
            //--------------------------- Create collect feedback workflow association.--------------------------------------

            SPWorkflowAssociation collectFeedbackWorkflowAssociation = SPWorkflowAssociation.CreateWebContentTypeAssociation(collectFeedbackWorkflowTemplate,
                                                                                             collectFeedbackWorkflowName,
                                                                                             taskListTitle,
                                                                                             historyListTitle);
            
            //setting to specify that workflow can be started manually
            collectFeedbackWorkflowAssociation.AllowManual = true;

            //setting to specify that manage lists permissions is required for starting a workflow
            if (collectFeedbackWorkflowAssociation.AllowManual)
            {
                SPBasePermissions emptyMask = SPBasePermissions.EmptyMask;
                emptyMask |= SPBasePermissions.ManageLists;
                collectFeedbackWorkflowAssociation.PermissionsManual = emptyMask;
            }

            //setting to specify that workflow will be automatically started whenever a new item is added
            collectFeedbackWorkflowAssociation.AutoStartCreate = false;
            //setting to specify that workflow will be automatically started whenever an item is changed/edited
            collectFeedbackWorkflowAssociation.AutoStartChange = false;

            //Adding workflow association to list
            foreach (SPList list in lists)
            {
                if ((int)list.BaseTemplate == 101)
                {
					// Here is the point where it fails
                    list.WorkflowAssociations.Add(collectFeedbackWorkflowAssociation);
                }
            }
        }

Does anyone have an idea why I can add the workflow to one list but fails at the next?

August 21st, 2015 11:14am

I guess this error message is related to SQL server upgrade

https://social.technet.microsoft.com/Forums/sharepoint/en-US/8296548f-a936-4386-aa0d-0d845f3ce187/error-exception-from-hresult-0x80131904?forum=sharepointgeneralprevious

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 1:06pm

I already checked if the content database is full, but this isn't the case
August 21st, 2015 3:53pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics