Sharepoint 2010 start workflow programmatically error
        Posted  
        
            by 
                user522429
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user522429
        
        
        
        Published on 2010-12-30T18:49:31Z
        Indexed on 
            2010/12/30
            18:54 UTC
        
        
        Read the original article
        Hit count: 223
        
c#
|sharepoint2010
I have a workflow associated with a content type. I try to kick it off from code from within the event receiver on the same content type, so when an item is updated, if there is a certain condition (status = ready for review) I start it.
//This line does find the workflow association
var assoc = properties.Web.ContentTypes["Experiment Document Set"].WorkflowAssociations.GetAssociationByName("Experiment Review Workflow", ultureInfo.CurrentUICulture);
//I had tried to use this line from something I found online, but it would return null
//var assoc = properties.Web.WorkflowAssociations.GetAssociationByName("Experiment Review Workflow", CultureInfo.CurrentUICulture);
var result = properties.Web.Site.WorkflowManager.StartWorkflow(properties.ListItem, assoc, string.Empty, SPWorkflowRunOptions.Synchronous);
//The line above gives me this error:
System.ArgumentException: Workflow failed to start because the workflow is associated with a content type that does not exist in a list. Before re-starting the workflow, the content type must be added to the list.
To check this, I was looking at the content type of the list item being updated and it is correct
properties.ListItem.ContentType.Name "Experiment Document Set"
So basically I have a workfow associated with the content type "Experiment Document Set". When I try to start a workflow from an event receiver in "Experiment Document Set", I get an error saying the content type "Experiment Document Set" does not exist in the list which doesn't make sense.
© Stack Overflow or respective owner