I have created a custom reusable workflow in SharePoint Designer. I am facing an issue after deployment of workflow. I have to activate the workflow feature with CSOM but I am not able to get that feature with CSOM code. I have tried code but this code is not showing that custom workflow feature id. I have tried on web & site level also :

public static void GetAllWebFeatures(ClientContext ctx, Web web)
{

try
{
var webFeatures = web.Features;
ctx.Load(webFeatures, fcol => fcol.Include(f => f.DisplayName, f => f.DefinitionId));
ctx.ExecuteQuery();
foreach (var f in webFeatures)
{
Console.WriteLine(f.DisplayName);
}
}
catch(Exception ex)
{
Helper.WriteException("Error in GetAllFeatures", ex);
}


}

Reusable workflows are not created for specific list or library but as the name suggests, they can be associated to any list or library. If you create a reusable workflow from SharePoint designer, you need Associate the workflow to a List to make it works.

The following article for your reference.

SharePoint 2013: Create Reusable Workflow on Content Type using SharePoint Designer 2013

If you want to get the workflow from the list, for SharePoint 2010 workflow, we can use the code below.

List list = web.Lists.GetByTitle("TestList");
clientContext.Load(list);
clientContext.ExecuteQuery();
var workflows = list.WorkflowAssociations;
clientContext.Load(workflows);
clientContext.ExecuteQuery();
for (int i = 0; i < workflows.Count; i++)
{
    Console.WriteLine(workflows[i].Name);
    Console.WriteLine(workflows[i].Id);
}

For SharePoint 2013 workflow, we can use this.

WorkflowServicesManager workflowServiceManager = new WorkflowServicesManager(clientContext,web);
clientContext.Load(workflowServiceManager);
clientContext.ExecuteQuery();
var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
clientContext.Load(workflowSubscriptionService);
clientContext.ExecuteQuery();
Guid listId = new Guid("{9AA28BEC-8195-4355-B933-C4BFC753647E}");
var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(listId);
clientContext.Load(subscriptions);
foreach (var sub in subscriptions)
{
    Console.WriteLine(sub.Id);
    Console.WriteLine(sub.Name);
}
  • Thanks for reply but I want to activate the feature of custom workflow. I am not able to find custom workflow feature id. – Gaurav Goyal Dec 5 at 12:29
  • The reusable workflow like a workflow template, it is not run as a feature, you need associate the reusable workflow to a list to make it works. – LZ_MSFT Dec 6 at 1:21

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.