Removing Extra Workflow Status Column in Default View

When SharePoint starts a workflow on a list for the first time, it has this annoying behavior of adding a workflow status column to the default view of the list.  Often times, this information is of no practical use for end users.  Unfortunately, there appears to be no way of getting rid of this behavior.  So instead, you have to either remove it by hand after the first instance has started, or write custom code.  Luckily the code is fairly simple and can be placed anywhere you want, including inside of a custom code activity within the workflow that is started.

Here's the type of code you need:

 // In our case, the internal column name is the first 8 characters of the
// list name followed by " Workflow"
string colName = (WorkflowItemList.Title + " Workflow").Substring(0, 8);
SPView defaultView = YourList.DefaultView;
if (defaultView.ViewFields.SchemaXml.Contains("\"" + colName + "\""))
{
    defaultView.ViewFields.Delete(colName);
    defaultView.Update();
}

Note that I think the internal column name is always the first 8 characters of the list name, but if you have multiple workflows on the same list, it may be different (you may need to export your list and look at the manifest.xml to find the internal field name).  If you find it is different,  you could either hard code the column name or you could loop through all the FieldsRefs in the view and remove any that have a type of "WorkflowStatus".  In any case do not remove the Field from the SPList (this will crash your workflows!); just remove the FieldRef from the SPView.  Once it's gone, SharePoint won't try and add it back unless you remove the workflow association and add it back in.

UPDATE: the internal column name is actually the first 8 characters of the workflow name, which in our case was using the list name followed by " Workflow", but is not always the case. Change the first line in the sample code to retrieve the workflow name, or hard code the name if it is always the same in your case.

Also, one other thing I tried after this was to explicitly add the workflow status field into the list definition, copying the Field definition directly from the exported list definition manifest file, thinking that we would just preempt SharePoint and add the field ourselves, leaving it out of the default view. Alas, this did not work as SharePoint, once again, outsmarted us by adding its own field to the column and the default view.

Comments

  • Anonymous
    March 04, 2010
    Great tip!! Please note that note only the ColName is cut down to 8 chars, also spaces have to be removed (before substring) if your workflow name contains these. Hope this helps... ;)

  • Anonymous
    February 10, 2011
    Thanks for this, very useful

  • Anonymous
    March 01, 2011
    This looks nice, but how would I remove this extra column when I create a SharePoint (so not in Visual Studio) workflow ? Can I easily remove this extra column automatically as well in that case?

  • Anonymous
    March 02, 2011
    This code is not specific to how the workflow is created or installed.  It will remove the workflow status column from the default view.  I don't know of any way to do that automatically without writing code.

  • Anonymous
    March 02, 2011
    Oh ok, so this code can be used in a script that gets scheduled eg every night to make sure none of the default views contain the status column ?

  • Anonymous
    March 03, 2011
    It could be done through a scheduled script or a SharePoint timer job, but the assumption would be that you have people adding workflows to lists on a frequent basis and you never want the status column in the default view.  Removing the status column from the default view is not a hard thing to do manually through the UI or with SharePoint Designer if those assumptions are not correct.

  • Anonymous
    March 03, 2011
    Hi Valdon, Yes the assumptions are correct, we create background workflows on a regular basis, and we don't want any of the workflow status columns to be added automatically in default views. For the few where users want to see the status, we can create a seperate view or they can manually check the workflow status in the workflow settings. Thanks for the additional info, I'll try to work this code into a timer job :)

  • Anonymous
    August 05, 2012
    I wanna use this code, but haven't a clue as to how to engage it / run it at W/F start up.   How can i use the code above? What do i put it in?   Thanks.

  • Anonymous
    August 13, 2012
    You'll need to create a custom workflow in Visual Studio and add a Code Activity.  Use the code from above in the ExecuteCode handler method.  See msdn.microsoft.com/.../ms734415(v=VS.90).aspx for an overview and pointers to samples for using Code Activities.

  • Anonymous
    November 19, 2012
    Very helpful. Thank you.