Skip to main content

SharePoint 2010 State Machine Workflow error: "Failed to Start Workflow"

I've been working on a custom state machine workflow for a specific content type. I've associated the workflow to the content type like this:

<AssociationCategories>ContentType;0x01........</AssociationCategories>

This workflow has a custom initiation form, in which I'm passing some options to the workflow.

After doing the association to the content type I started getting the following error: "Failed to Start Workflow"

After doing a bit of debugging and head scratching I found that in the StartListWorkflow() method inside the initiation page in which the workflow association is retrieved from the workflowList.WorkflowAssociations list and it does not take into consideration the ContentType workflow associations.

private void StartListWorkflow()
{
 SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];
 
        this.Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData());
 SPUtility.Redirect(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current);
}

So I replaced this line:

SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];

with this line:

SPWorkflowAssociation association = this.workflowList.ContentTypes[workflowListItem.ContentTypeId].WorkflowAssociations[new Guid(this.associationGuid)];

in which I'm getting looking for the association in the WorkflowAssociations of the list content type of the workflowListItem.

Comments

Popular posts from this blog

Emmet in Visual Studio Code | cheat sheet link

Support for   Emmet   snippets and expansion is built right into Visual Studio Code,   no extension required .   Emmet 2.0   has support for the majority of the   Emmet Actions   including expanding   Emmet abbreviations and snippets .   Emmet is a web-developer’s toolkit that can greatly improve your HTML & CSS workflow   Links: Emmet in Visual Studio Code   Cheat Sheet (emmet.io)  

How to deloy InfoPath 2010 "Administrator-approved form template" to SharePoint 2010 programaticaly

Scenario: you've developed and InfoPath 2010 form. This form contains code that requires full trust, so you need to deploy it as a administrator-approved form template. This requires an farm administrator to check, upload and activate the form for the site collection. Solution:  to automate this operation I  created a farm level feature - w hen the feature is activated upload the form  programmatically and w hen the feature is deactivated remove the form  programmatically. Here is how I did it: 1. Create an Empty SharePoint Project and set it to be deployed as a farm solution 2. Add an Empty element item - EmptyElement1 . This will also generate a feature - Feature1 3. Delete the Elements.xml file of the EmptyElement1 4. Copy/Paste the InfoPath 2010 form into the EmptyElement1 5. Right click on the added form and click Properties:  - Deployment Type: ElementFile  - Deployment Location> Path: set it to blank 6. Open the generated featu...

Creating SharePoint 2010 Calculated Field from code in sites with different regional settings

Say you need to create the following calculated column in different sites that have different regional settings: English, French, etc. to format the DateTime [Start Time] filed to  "dd-mm-yyyy". The following formula would look list this in English - with a comma separator: = TEXT ([ Start Time ] , "dd-mm-yyyy" ) Like this in french - with a semicolon separator: = TEXT ([ Start Time ] ; "dd-mm-yyyy" ) When creating the column from from code  behind to treat this  the SP Web . Locale . TextInfo . ListSeparator  property must be used to get the correct list separator: SPList spList = SPContext . Current . Web . Lists [ "List Title" ]; string newFieldName = spList . Add ( "CalculatedField" , SPFieldType . Calculated , false ); SPFieldCalculated newField = ( SPFieldCalculated ) spList . GetField ( newFieldName ); newField . Formula = String . Format (@ "=TEXT([Start Time]{0} ""dd-mm-yyyy"")...