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.
In the below screenshot we can see that the code returns 2, which means workflow status is in-progress.
Feel free to contact me if you have any doubts and queries through comments.
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
LikeLike
Hi Obul,
Using above code logic, we can’t get approver name. hope you try to find from workflow task list. I haven’t tried so I’m not sure
LikeLike
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
LikeLike
Hi Pratikghumre,
If you want to update workflow status then you have to set some more values to the workflow. Check below URL for your reference.
http://sharepoint.stackexchange.com/questions/142356/approving-workflow-programaticaly
LikeLike