Delete Orphaned Workflow Status Columns from SharePoint List Views

Recently I been working on the SharePoint Designer Workflows associated with the site content type which used in the SharePoint list. During the development phase, as I have been republishing and reassociating multiple versions of workflow to the site content type, somehow I have ended up having multiple workflow status columns on the SharePoint List Views. As you can see from the following screen, there are two Project Approval Workflow Status columns.

As many of us knows, whenever you publish the SharePoint workflow to the list or content type, workflow status column automatically added as a SharePoint List Internal column and available to configure in the SharePoint Views. Just like many things in the SharePoint, if you ever delete the workflow association to the content type or list and reassociate later to the content type or list, workflow status columns created by the previous association gets left behind. These orphaned workflows status columns or many of the site columns created by workflows shows up in the configuration page of the SharePoint views causing headaches for the end user.

One of the most critical aspect of this issue is there is no easy way to delete these workflow status columns from the browser interface. You can’t manage (or delete) work flow status columns from the list settings page, site columns gallery, or site content type gallery.

Thanks to the wonderful free utility called SharePoint Manager 2010 (http://spm.codeplex.com/) available on the codeplex, you can view the internal details of the SharePoint List, Site Columns, and their GUIDs which we can use with the SharePoint Object Model to cleanup these orphaned columns. For MOSS 2007 environments, look for the link for the SharePoint Manager 2007 on the above link.

To Delete the Orphaned Site Columns, please follow following steps.

1 – In our scenario, I would like to delete the workflow status column “Project Approval Workflow (Previous Version..)” from the Modify SharePoint View Pages.

2 – Open the SharePoint Manager 2010 and browse to the SharePoint_Config -> Content Service -> Web Applications -> Your Web Application .> Site Collection -> Your Site Collection -> Your Site -> Lists -> Your List -> Fields, Look for the “Project Approval Workflow (Previous Version..)” field and note the Id and InternalName column.

3 – To delete this site column, unfortunately you have to write a custom code. Open the Visual Studio 2010 and create the Console Application, Target the project to Microsoft.NET 3.5 framework, and “Any CPU” build. Please be careful with this step because Visual Studio 2010 defaults to Microsoft.NET Framework 4.0 and 32-bit runtime. Reference the Microsoft.SharePoint.dll in the console application, Import the Microsoft.SharePoint.dll in the class, and copy the following code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace DeleteSPListColumns
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite spSite = new SPSite("<a href="http://sp2010vm">http://sp2010vm</a>"))
            {
                using (SPWeb spWeb = spSite.RootWeb)
                {
                    SPList isoDocs = spWeb.Lists["Trainings"];
                    SPField field = isoDocs.Fields[new Guid("acf50d04-fa75-4917-a4f3-1bd6ea4f1810")];
                    Console.WriteLine("Field Name:" + field.InternalName);

                    field.Hidden = false;
                    field.ReadOnlyField = false;
                    field.Update();
                    isoDocs.Fields.Delete(field.InternalName);
                    Console.WriteLine("Field deleted - Done!");
                }
            }
            Console.WriteLine("Press any key...");
            Console.Read();
        }
    }
}

4 – Modify the code by replacing your Site URL, List Name, and Field GUID

5 – Run the console Application and verify that Field InternalName is valid and program runs successfully.

6 – If Console App ran successfully, Open the Site Manager 2010 and verify that “Project Approval Workflow (Previous Version..)” field is deleted.

7 – Refresh the browser interface to modify the SharePoint Views and deleted column shouldn’t be available as a configurable column.

Please note that you can use this method to delete any lingering site columns or list columns using this approach in the SharePoint 2010 and MOSS 2007.

About these ads
This entry was posted in SP2010 DEV General. Bookmark the permalink.