Forums - C# Corner

Forum guidelines
Carlos Santos

Carlos Santos

  • 1.5k
  • 7
  • 162

get internal status workflows

Jun 19 2017 7:01 AM
Hi, im trying to get the internal status from all workflows in a sharepoint site. I asked this here:
 
https://sharepoint.stackexchange.com/questions/217585/get-workflow-status-sharepoint-2013/217591#217591 
 
but the answer did not help me. I dont understand why I get always 0 Workflows if I have workflows running. I created a list, added the workflows. They start automatically when I create a new item. The workflow is showed with a column "wflow" ( so the name my workflow ). But when I use the code above or other snippets with a SPWorkflowManager I always get 0 workflows... Any ideas? Thanks in advance.
 
  1. foreach (SPWorkflow workflow in manager.GetItemWorkflows(item))  
  2.   {  
  3.           if (workflow.ParentAssociation.Name == "wflow")  
  4.           {  
  5.               foreach (SPField field in workflow.ParentList.Fields)  
  6.               {  
  7.                   if (field is SPFieldWorkflowStatus)  
  8.                   {  
  9.                       SPFieldWorkflowStatus statusField = (SPFieldWorkflowStatus)field;  
  10.                       if (statusField.Title == "wflow")  
  11.                       {  
  12.                          int statusValue = int.Parse(item[statusField.StaticName].ToString());  
  13.   
  14.                          // display the status however you want  
  15.                          System.Diagnostics.Debug.WriteLine(statusField.GetFieldValueAsHtml(statusValue).ToString());  
  16.   
  17.                       }  
  18.                   }  
  19.               }  
  20.           }                     
  21.    } 
 

Answers (4)