Sharepoint 2010 Launches Workflow with Software Error

I have a workflow related to the content type. I try to disconnect it from the code from the event receiver in the same content type, so when the item is updated, if there is a certain condition (status = ready for review), I run it.

// This line finds the association of workflows

var assoc = properties.Web.ContentTypes["Experiment Document Set"] .WorkflowAssociations.GetAssociationByName("Experiment Review Workflow", ultureInfo.CurrentUICulture); 

// I tried to use this line from what I found on the Internet, but it will return null

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

The following line gives an error:

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

System.ArgumentException: The workflow could not be started because the workflow is associated with a content type that is not in the list. Before starting the workflow again, a content type must be added to the list.

To check this, I looked at the content type of the updated list item and correctly.

 properties.ListItem.ContentType.Name "Experiment Document Set" 

So, basically, I have a workfow related to the content type "Experiment Document Set". When I try to start the workflow from the event receiver in the "Experiment Document Set", I get a message that the content type "Set of experimental documents" does not exist in the list, which does not make sense.

+4
source share
2 answers

Make sure assoc.Enabled = true.

0
source

It may be too late to be useful, but I just found out that you cannot 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 will work for a simple workflow without any configuration options.

I can't verify this (yet) because I am stuck a step earlier, perhaps it seems like the problem mentioned in the first two code examples.

-1
source

Source: https://habr.com/ru/post/1333828/


All Articles