SPFieldWorkflowStatus.GetFieldValueAsText method

Converts the field value to a text string.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Overrides Function GetFieldValueAsText ( _
    value As Object _
) As String
'Usage
Dim instance As SPFieldWorkflowStatus
Dim value As Object
Dim returnValue As String

returnValue = instance.GetFieldValueAsText(value)
public override string GetFieldValueAsText(
    Object value
)

Parameters

  • value
    Type: System.Object

    An object that represents the field value.

Return value

Type: System.String
A string representation of a 32-bit integer.

Remarks

When you access a field directly, the field value is returned as type Object. You can use the GetFieldValueAsText method to convert the raw field value to corresponding status text.

A WorkflowStatus field is a multichoice field, and each choice represents a status as defined in the workflow template. You can get a list of status choices by calling the template's GetStatusChoices method or by accessing the Choices property of the SPFieldWorkflowStatus object.

The status choices for the three-state workflow are listed in the following table.

Field Value

Status Text

0

Starting

1

Failed on Start

2

In Progress

3

Error Occurred

4

Canceled

5

Completed

6

Failed on Start (retrying)

7

Error Occurred (retrying)

Examples

The following example is a console application that takes an item from a list, accesses the WorkflowStatus field of the item, and prints both the raw value of the field and the corresponding status text.

The application assumes that the Web site has a list named "Test List" and that the list has at least one workflow association and one list item.

Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Workflow

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")
         Using web As SPWeb = site.OpenWeb()

            Dim listName As String = "Test List"

            Dim list As SPList = web.Lists(listName)
            Dim association As SPWorkflowAssociation = list.WorkflowAssociations(0)
            Dim fieldName As String = association.Name

            Dim statusField As SPFieldWorkflowStatus = _
               CType(list.Fields.GetField(fieldName), SPFieldWorkflowStatus)

            ' Get the first item in the list.
            Dim item As SPListItem = list.Items(0)

            ' Get the value of the WorkflowStatus field.
            Dim value As Object = item(fieldName)

            ' Print the field value and corresponding text.
            Console.WriteLine("The value of the field is {0}, which means '{1}'.", _
                               value.ToString(), statusField.GetFieldValueAsText(value))
         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub
End Module
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               string listName = "Test List";

               SPList list = web.Lists[listName];
               SPWorkflowAssociation association = list.WorkflowAssociations[0];
               string fieldName = association.Name;

               SPFieldWorkflowStatus statusField = 
                  list.Fields.GetField(fieldName) as SPFieldWorkflowStatus;

               // Get the first item in the list.
               SPListItem item = list.Items[0];

               // Get the value of the WorkflowStatus field.
               object value = item[fieldName];

               // Print the field value and corresponding text.
               Console.WriteLine("The value of the field is {0}, which means '{1}'.",
                                 value.ToString(), statusField.GetFieldValueAsText(value));
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

The application prints something like the following text to the console. (Output varies depending on the status of the workflow on the first list item.)

The value of the field is 2, which means 'In Progress'.

Press ENTER to continue...

See also

Reference

SPFieldWorkflowStatus class

SPFieldWorkflowStatus members

Microsoft.SharePoint namespace

GetFieldValueAsHtml(Object)