简体   繁体   中英

Sharepoint 2010 start workflow programmatically error

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

assoc = properties.Web.WorkflowAssociations
     .GetAssociationByName("Experiment Review Workflow",
      CultureInfo.CurrentUICulture);

The next line gives an error:

var result = properties.Web.Site.WorkflowManager
                       .StartWorkflow(properties.ListItem, assoc,string.Empty,
                                      SPWorkflowRunOptions.Synchronous);

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.

确保 assoc.Enabled = true。

Probably too late to be helpful, but I just learned that you can't use String.Empty (or null ) in the StartWorkflow method.

From http://www.tonytestasworld.com/post/Howto-Start-a-Sharepoint-Workflow-Programmatically.aspx , it looks like assoc.AssociationData would work for a simple workflow without any configuration parameters.

I can't test this (yet), because I'm stuck a step earlier, possibly similar to the issue you mentioned in your first two code examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM