SharePoint Workflow Status: how to use the workflow status in a workflow (or a view)?

Recently I had to configure a SharePoint workflow where an item had to be copied to another list when the Approval Workflow status is approved. It was ok to start the workflow manually. The workflow had to be created in SharePoint Designer 2007, since no other specialized workflow software is/was available.

The problem I had was that when I assigned a condition that would check if the Approval Status equals Approved. But this doesn’t work when you use this condition, it will be skipped, because internally SharePoint uses a number for the workflow status.

Also, if you Edit in Datasheet (your list or Library) you can see the numbers is stead of the text.

Here is an overview:

Status

Value

Not Started

0

Failed on Start

1

In Progress

2

Error Occurred

3

Canceled

4

Completed

5

Failed on Start(Retrying)

6

Error Occurred (Retrying)

7

Canceled

15

Approved

16

Rejected

17

So, I need to modify my workflow like : If Approval Status Equals 16, ….

The same policy applies when you would like to have a view where you display items based on their Approval Workflow Status.

This list is partially copied from David Wise blog

About Patrick Sledz

Patrick works as a consultant. He assists organizations to deliver SharePoint business value and create the awareness in these organizations that only a strong technical team is not sufficient to deliver this added value.

Tagged , , . Bookmark the permalink.
  • Tyler

    What do you do if you use custom names for your workflow status?

  • Tom

    You can check the field of your workflow status by getting your SPListItem and calling its field.
    using (SPWeb myWeb = SPContext.Current.Site.OpenWeb())
    {

    SPList myList = myWeb.GetList(“/Lists/MyList”);
    SPQuery qry = new SPQuery();
    string caml = @”1;
    SPListItemCollection myItemColl = myList.GetItems(qry);
    SPListItem myItem = myItemColl[0];
    object wfStatus = null;
    wfStatus = myItem[“WorkflowOnNew”] != null ? myItem[“WorkflowOnNew”] : null;
    if (wfStatus != null)
    {
    switch (wfStatus.ToString())
    {
    case “0”:
    wfStatus = “Not Started”;
    break;
    case “1”:
    wfStatus = “Failed on Start”;
    break;
    case “5”:
    wfStatus = “Completed”;
    break;
    }
    // Now do what you want with wfStatus, just remember you’ll have to do “.ToString()”
    // on it because it’s an object.

    P.S. I didn’t do all the possible combinations of status numbers, this was just an
    example to get you started. Find those at
    http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/f5de7947-f49b-420a-b8d8-d44ad6b7769f/
    and various other places around the ‘net.

    }

  • Tom

    That CAML query above didn’t come out right because of the tags you have to use. I’ll attempt to write it again here:
    string caml = @”<Where><Eq><FieldRef Name=’ID’ /><Value Type=’Integer’>1</Value></Eq></Where>;

  • Bharat

    Hi,
    When I attempt to use the Approval Status in a workflow, using “If Approval Status equals 0;#Approved” it doesn’t recognise the approval status change after a document has been approved – so status changes from Pending to Approved.

    I need to be able to determine when an item is approved so a task can be assigned to various people to review it.

    How can this be done?
    Cheers,

    • Patrick Sledz

      Hi Bharat,

      I’m don’t understand the (business)logic in your question. You have an approval workflow, which updates the Approval status of an item or document. Why do you want people to review that item or document AFTER it has been approved?
      In a normal review/collectfeedback/Approval process, you would do the review before you do the approval.

      If you want people to be informed when an item has been approved, Alerts on a view might help you out. (the view would be a filtered view on all approved documents, and the alert might be ‘Alert when new items are added in combination with ‘Someone changes an item that appears in the following view’)

      Hope this helps you

      Patrick