Compartir a través de


del método SPFieldWorkflowStatus.GetFieldValueAsText

Convierte el valor del campo en una cadena de texto.

Espacio de nombres:  Microsoft.SharePoint
Ensamblado:  Microsoft.SharePoint (en Microsoft.SharePoint.dll)

Sintaxis

'Declaración
Public Overrides Function GetFieldValueAsText ( _
    value As Object _
) As String
'Uso
Dim instance As SPFieldWorkflowStatus
Dim value As Object
Dim returnValue As String

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

Parámetros

  • value
    Tipo: System.Object

    Un objeto que representa el valor del campo.

Valor devuelto

Tipo: System.String
Representación de cadena de un entero de 32 bits.

Comentarios

Cuando tiene acceso a un campo directamente, se devuelve el valor del campo como un tipo Object. Puede usar el método GetFieldValueAsText para convertir el valor del campo sin formato al texto de estado correspondiente.

Un campo de WorkflowStatus es un campo de una o varias y cada opción representa un estado tal como se define en la plantilla de flujo de trabajo. Puede obtener una lista de opciones de estado, llamando al método GetStatusChoices de la plantilla o mediante el acceso a la propiedad Choices del objeto SPFieldWorkflowStatus .

En la siguiente tabla, se enumeran las opciones de estado del flujo de trabajo de tres estados.

Valor de campo

Texto de estado

0

Iniciar

1

Error al inicio

2

En curso.

3

Se produjo el error

4

Cancelado

5

Finalizado

6

Error al inicio (reintentando)

7

Error detectado (reintentando)

Ejemplos

En el siguiente ejemplo es una aplicación de consola que toma un elemento de una lista, tenga acceso al campo WorkflowStatus del elemento y a continuación, imprime tanto el valor sin formato del campo y el texto de estado correspondiente.

La aplicación se supone que el sitio Web tiene una lista denominada "Lista de prueba" y que la lista tiene asociación de al menos un flujo de trabajo y un elemento de lista.

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();
      }
   }
}

La aplicación imprime algo como el siguiente texto en la consola. (Salida varía según el estado del flujo de trabajo en el primer elemento de lista.)

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

Press ENTER to continue...

Vea también

Referencia

clase SPFieldWorkflowStatus

Miembros SPFieldWorkflowStatus

Espacio de nombres Microsoft.SharePoint

GetFieldValueAsHtml(Object)