Get Workflow Status Programmatically in SharePoint Using Client Side Object Model C#

This post explains how to get SharePoint list item’s workflow status using Client Side Object Model programming, using the below code we can find workflow status id. Because workflow status field internally save the workflow status id only not as name,


List oList = clientContext.Web.Lists.GetByTitle("Documents");
ListItem item = oList.GetItemById(14);
clientContext.Load(item);
clientContext.ExecuteQuery();
Field workflowStatusField = item.ParentList.Fields.GetByTitle("WorkflowName");
clientContext.Load(workflowStatusField);
clientContext.ExecuteQuery();
var workflowStatusValue = item[workflowStatusField.InternalName];

In that code workflowStatusValue receive a status id as a list item workflow status. Here I’ve listed workflow status code and their status,

NotStarted = 0
FailedOnStart = 1
InProgress = 2
ErrorOccurred = 3
StoppedByUser = 4
Completed = 5
FailedOnStartRetrying = 6
ErrorOccurredRetrying = 7
ViewQueryOverflow = 8
Canceled = 15
Approved = 16
Rejected = 17

for testing I have created a workflow, named as “WorkflowName” and assigned to one document.

2016-02-12_0-37-37

In the below screenshot we can see that the code returns 2, which means workflow status is in-progress.

workflow

Feel free to contact me if you have any doubts and queries through comments.

4 thoughts on “Get Workflow Status Programmatically in SharePoint Using Client Side Object Model C#

  1. thanks good solution,but im new to sharepoint, i need to get the from whom it is pending with person name also. could you please help on this ., Advance thank you

    Like

  2. Hi Ravi,
    I am trying to update the workflow status from status 2 to status 4 through $item.update(),But after update i am not getting the updated value of the column

    Like

Comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s