Friday, October 24, 2008

Removing or Hiding workflow column from View of list or document library

Hi All,

Every time i work with workflow and everyday i got new challenge in that. well, of course without challenge, There is no point to work. isn't it? OK, so let's get started.

When you attach a workflow to the list and when workflow gets triggered, you can observe one thing. the workflow name that you have given in the list will come in to the picture. this will appear as one of the field in AllItems.aspx. Woh!!! where did it come from??? Well, answer is, it comes automatically.

Our main aim is to Remove or Hide workflow column from View of list or document library.

See the steps below :

Step 1 : Attach a workflow and name it. make it auto start when new item added.



Step 2: Observe the column appearing automatically in view when new item is added.




So , now you have this column appearing in AllItems.aspx or which actually most of the people do not want to see. yes that is true that you can always go to modify this view and hide that column. but what if there is a scenario where there is no direct access to Modifying view or AllItems.aspx.

Let's say you make webpart which fetches data from AllItems but filtered data and filtration in such a way that it cannot be done by simply applying the filtration in View. so we make separate webpart for it. now even in that new webpart the new column (workflow column) starts appearing. Note one thing, you will not see this column in Fields Collection of that list or document library, is automatically generates and attaches to the view. so forget about this. After this workflow field gets generated, you can see it in View settings but not in the field.

Hiding that column also has some importance is that you do not want to allow the people to go on a page where they can see that task is assign to which person, or they can just simply go there and perform anything. Ultimately, there should not be an access to the column, so better to hide that. but simple it cannot be done.

All you need to do is play with Viewfield of the SpView. you do not have to do anything with the SPList here. because SPList Fields do not contain this workflow column. Now interesting thing is how will you get the name of that column in the code so that you can hide it from the ViewFields? Well , if you are thinking that name that you have given to the Workflow while attaching it with the List or document Library, then let me tell you, this is totally wrong.

Yes, even i was surprised to see this. but then i had to work on it, so i just took a look on ViewFields of the View and i come to know an interesting thing that the column name of that workflow in the ViewFields is first 8 characters, first 8 letters of the name that you have given. Even if you give space in between. for Example, the name that you have given while attaching the workflow is "Custom Workflow:, then that field in the ViewFields will be named as "CustomWo", see no space in between and same case as you have given. means if you have given "cUsTOm wOrkflow", then the name of the field in Viewfiels will be "CUsTOmwO". so be aware of it. to be on safer side, compare by applying .ToUpper() both the side and then perform the task.

Here is a way to remove the workflow field that appears automatically when workflow is triggered. Keep in mind of allowing unsafe updates on Web to true and false respectivly after finishing your job done.

First take a SPView object referring your list.

SPView objView = web.Lists["List_Name"].Views["View_Name"];
SPList objList = web.Lists["List_Name"];

if (objView.ViewFields.Exists("8_character_name_of_workflow_column"))
{
objView.ViewFields.Delete("8_character_name_of_workflow_column");
}

objView.Update();

Step 3 : Demonstrating from figure



Step 4 : Time to see the result...



See, now that field which was automatically generated is no more available in that View.

Let me brief you about the other way to get the Name which you have to place in the code to remove it from the View. to be on safer side, follow this pattern, even what i mention is very correct.

All you need to do is generate the schema file of the list or document library and search for the following Tag lines.



You can follow this approach as well.

I hope this will make the whole picture clear. This will be very helpful when you do not deal directly with List but uses them in some webpart and uses the views of that list. example to give is ListViewWebPart.

That's it. your job is done. now that column will not appear in the view.

7 comments:

dtandukar said...

where do i find spview? which files i have to update?

dtandukar said...

which file do i have to edit?

dtandukar said...

which files do i need to modfiy?

Miguel I. said...

Hello,

Do you know any means of preventing a custom workflow from appearing in the workflow.aspx where the list of workflows of a list item are shown? I have a custom workflow that does not have any user interaction and would like to hide it from this page or even better show it only for users that have administrative privileges?

Thanks,
Miguel

SharePoint Kings said...

DT,
over here file mentioned that is the schema file of list definition.

SharePoint Kings said...

Isidoro,
you can give permission to list only so that only admin can go to workflow page.

and if your business want something like only some workflow can be available to user then as workflow.aspx is the application page which we can not modify.

so one way you can check that on workflow page check user and show message that you do not have permission.

Anonymous said...

Hi

Great article.

My own gripe is that this column also appears on Alert Me emails.

I had hope this would not be the case with 2010 but alas the issue remains.




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com