How to retrieve list of installed Workflows in SharePoint 2013 Office 365 site using CSOM

Home | SharePoint 2013 | How to retrieve list of installed Workflows in SharePoint 2013 Office 365 site using CSOM

In this article, I’d be articulating on how to retrieve list of installed workflows in SharePoint 2013 Office 365 site using Client Side Object Model (CSOM). Just to give a background the workflow framework in SP 2013 has undergone a major revamp, there are new WorkflowServicesManager and WorkflowDeploymentService objects, we’d also be leveraging the new APIs accordingly to retrieve

Create a console application and name it as ‘RetrieveInstalledWorkflows’.

Add references to the following dll’s.

Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.WorkflowServices.dll

Import the following namespaces

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.WorkflowServices;
using Microsoft.SharePoint.Client.WorkflowServices;
using Microsoft.SharePoint.Client.Workflow;

Create a static method by name ‘RetrieveInstalledWorkflows’ and implement the following snippet of code.

public static void RetrieveInstalledWorkflows()
{
    Uri oUri = new Uri(“
https://yoursite.sharepoint.com”);
   
  
    Office365ClaimsHelper claimsHelper = new Office365ClaimsHelper(oUri, “userid@yoursiter.onmicrosoft.com”, “your password”);
    using (ClientContext oClientContext = new ClientContext(oUri))
    {      

        oClientContext.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
       
        //Get the instance of Workflow Services Manager
        WorkflowServicesManager oWorkflowServicesManager = new WorkflowServicesManager(oClientContext,oClientContext.Web);

        //Hook to WorkflowDeploymentService
        WorkflowDeploymentService oWorkflowDeploymentService = oWorkflowServicesManager.GetWorkflowDeploymentService();

        //Fetch all the installed workflows
        var oWorkflowDefinitionCollection = oWorkflowDeploymentService.EnumerateDefinitions(true);
        oClientContext.Load(oWorkflowDefinitionCollection);

 
        oClientContext.ExecuteQuery();

        foreach(var oWorkflowDefinition in oWorkflowDefinitionCollection)
        {
            Console.WriteLine(“Workflow”+oWorkflowDefinition.DisplayName);
        }

        Console.ReadLine();

    }

}

To know more about Office365ClaimsHelper class, please refer to Wictor Wilen’s article on active authentication

 Subscribe to my blog

Leave a Reply