0

If I have a SharePoint 2010 workflow with an initiation form which contains several fields/ parameters.

Example: Name, Address, Email, is it possible to get a list of the parameters using C# and CSOM?

I can get the name and description of the workflow using the following code:

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

string SharepointURL = "https://testSharepointSite.com/sites/Test";

//Name of the List to which the Workflow is Associated
string targetListName = "Documents";

//connect to Sharepoint URL with Windows Credentials
ClientContext clientContext = new ClientContext(SharepointURL);

Web web = context.Web;

// Guid of the List to which the Workflow is Associated
Guid targetListGUID = new Guid("b89e266c-5f20-4b83-9f95-10a42c629e84");

// Workflow Services Manager which will handle all the workflow interaction 
WorkflowServicesManager workflowServicesManager = new WorkflowServicesManager(context, web);

// Return all Workflow Associations which are running on the SharePoint 2010 Engine
WorkflowAssociationCollection workflowAssociations = list.WorkflowAssociations;
context.Load(workflowAssociations);
context.ExecuteQuery();

// Get the required Workflow Association
WorkflowAssociation workflowAssociation = workflowAssociations.GetByName(workflowName);
context.Load(workflowAssociation);
context.ExecuteQuery();

Console.WriteLine(workflowAssociation.Name); // <-- Name
Console.WriteLine(workflowAssociation.Description); // <-- Description
0

The code snippet above WorkflowServicesManager is used for SharePoint 2013 workflow platform.

For SharePoint 2010 workflows, use the code snippet below:

        ClientContext ctx = new ClientContext("http://sp/sites/dev/");
        List list = ctx.Web.Lists.GetByTitle("currency");
        WorkflowAssociationCollection workflows = list.WorkflowAssociations;
        ctx.Load(workflows);
        ctx.ExecuteQuery();
        foreach (WorkflowAssociation workflow in workflows)
        {
            Console.WriteLine(workflow.Name);
        }

enter image description here

enter image description here

  • Hi @Jerry_MSFT. Yes, you are right, I do not need WorkflowServicesManager, copied it there by mistake. I can actually get the name and description of the workflow, basically it is the same code as yours. I'm having difficulty in finding the name of the fields from an existing initiation form using C#/CSOM. While your answer is not the one I'm looking for, still thank you for taking the time to reply. – MegaMegaOwl Aug 8 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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