Sometime back we developed a SharePoint 2013 Visual Studio Workflow to one of our clients. The workflow association to a document library was also implemented in the code inside a feature activation. Recently, I was deploying this solution to a new site collection in my development environment and I got an exception while activating the workflow association feature.
The issue was because the workflow definition id returns 0 when retrieving the workflow definitions deployed to the site.
WorkflowServicesManager workflowServicesManager = new WorkflowServicesManager(currentWeb);
WorkflowDeploymentService workflowDeploymentService = workflowServicesManager.GetWorkflowDeploymentService();
WorkflowDefinitionCollection workflowDefinitions = workflowDeploymentService.EnumerateDefinitions(true);
foreach (WorkflowDefinition workflowDefinition in workflowDefinitions)
{
if (workflowDefinition.DisplayName.Equals("Document Workflow"))
{
WorkflowSubscription workflowSubscription = new WorkflowSubscription();
workflowSubscription.DefinitionId = workflowDefinition.Id;
workflowSubscription.Enabled = true;
workflowSubscription.EventSourceId = documentLibraryList.ID;
workflowSubscription.Name = workflowDefinition.DisplayName;
workflowSubscription.EventTypes = eventTypes;
workflowSubscription.SetProperty(
OnlineSubmissionWorkflowAssociationFeatureEventReceiver.TaskListId,
documentWorkflowTaskList.ID.ToString());
workflowSubscription.SetProperty(
OnlineSubmissionWorkflowAssociationFeatureEventReceiver.HistoryListId,
workflowHistoryList.ID.ToString());
workflowSubscription.SetProperty(
OnlineSubmissionWorkflowAssociationFeatureEventReceiver.FormData,
string.Empty);
WorkflowSubscriptionService workflowSubscriptionService = workflowServicesManager.GetWorkflowSubscriptionService();
if (workflowSubscriptionService.EnumerateSubscriptionsByList(documentLibraryList.ID).Count == 0)
{
workflowSubscriptionService.PublishSubscriptionForList(workflowSubscription, documentLibraryList.ID);
}
}
}
As the workflow definition Id is not defined, the workflow subscription Id is also becomes undefined. Therefore, the exception was thrown when trying to publish the subscription without a definition id, to the list.
Following are the steps followed to resolve this issue.
- Activate the Workflow Task Content Type site feature if not already activated.
- Activate the “Workflow service store” hidden feature.
In the SharePoint 2013 Management shell, run the command,
Enable-SPFeature
-Identity "workflowservicestore" -url "<sub site url>"
- Make sure the Service Bus Gateway, Service Bus Message Broker and also Workflow Manager Backend services are up and running in the WFE server. Also, all these services should be logged on using the same service account. Restart the services.
- Go to IIS Manager and check whether the Workflow Management Pool is running under Application Pools using the same service account. Restart the application pool.
Now the issue should be gone away.
No comments:
Post a Comment