Scenario:
We created a visual studio workflow which contains initiation form. Workflow was associated with multiple content types. Workflow works well when deployed using visual studio. When workflow deployed using WSP, it was crashed showing “Failed on Start (retrying)” or “Error Occurred” status.
Resolution:
When we add “Workflow Initiation Form” using “Add” -> “New Item”, following method is responsible for running workflow:
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);
}
In the above method, following method looks for workflow association with the list:
SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new
Guid(this.associationGuid)];
But we have associated workflow with the content types, not with the list. This results in null value in the SPWorkflowAssociation type variable “association”. When “StartWorkflow” is called, it resulted in exception.
We changed the above line of code with following line:
SPWorkflowAssociation association = this.workflowList.ContentTypes[this.workflowListItem[“Content Type”].ToString()].WorkflowAssociations[new
Guid(this.associationGuid)];
In the above code, instead of finding association from list, workflow looks association using content type as workflow is associated with content type not list. This did the trick.