How to show task creator’s & modifier’s name instead of "System Account" in the Task Library


Whenever we create a SharePoint site we will get a default list called “Tasks”. This is one of great features available in SharePoint. Tasks list is being used to track workflow tasks in SharePoint. So, whenever we start a workflow and assign a task to somebody, and if he or she approve or reject it all those task activities will track and log in to the Task list.


That is all about the Task list. Now we can come to the reason why I am writing this blog post. We all know that whenever a task item added to a Task list, the “created by” and “modified by” columns will show the value “system account” always!


Once I got cool requirement from one my customers, he doesn’t want to display the “System account” as the default creator or the modifier in his task list. He want to show the name of the user who has created the task, in the “created by” column and if somebody modify that task by approving/rejecting that workflow task, then that person’s name has to show in the “modified by” column.




As a work-around what I did that, I have created an event handler – ItemAdded & ItemUpdated, which will capture the event whenever a new task Item added to the Task List and whenever we modify that task by approving/rejecting the workflow task.


And whenever we add or edit a task item, I just tried to update the “created by” and “modified by” columns using SPWeb.CurrentUser property. But, then I have found that, though a different user log in to the application, in the event handler that property returning the current user as “System Account”.


More info on how to update the “created by” and “modified by” columns, please  see this post.


After digging into the workflow task creation process, I have found that all the tasks are creating and adding to the Task list under the Application pool identity and that is why we are getting SPWeb.CurrentUser value as “System account”.


I was really upset because of this and in one point I had felt that we can’t update the “created by” and “modified by” columns L. But I believed that there will be some hidden treasure in SharePoint which will help us really to accomplish our customization requirements.


I just checked the fields available for the Tasks list then I have found that, there were 2 fields:


Workflow List ID    =  which will return the GUID of the List from which workflow task has been created.

Workflow Item ID  =  which will return the list item from which workflow task has been created.


Cooool! Once we get those 2 fields then no need to worry anymore!


I just modified my existing custom event handler code as like below and it worked like charm!


   1: using System;
   2: using System.Collections.Generic;
   3: using System.Text;
   4: using Microsoft.SharePoint; 
   6: namespace UpdateTaskColumns
   8: {
   9:     public class UpdateColumns : SPItemEventReceiver
  11:     {
  13:         public override void ItemAdded(SPItemEventProperties properties)
  15:         {
  16:             UpdateUserColumns(properties,false);       
  18:         } 
  20:         public override void ItemUpdated(SPItemEventProperties properties)
  21:         {
  22:             UpdateUserColumns(properties,true);
  24:         } 
  26:         private void UpdateUserColumns(SPItemEventProperties properties,bool IsUpdate)
  28:         {
  30:             SPWeb oWeb = properties.OpenWeb();
  32:             Guid oSourceListID = new Guid(properties.ListItem["Workflow List ID"].ToString());
  34:             SPList oSourceList = oWeb.Lists.GetList(oSourceListID, true);
  36:             SPListItem oSourceListItem = oSourceList.GetItemById(Convert.ToInt32(properties.ListItem["Workflow Item ID"]));
  38:             if (IsUpdate)
  40:                 properties.ListItem["Editor"] = oSourceListItem["Editor"];
  42:             else
  43:             {
  44:                 properties.ListItem["Author"] = oSourceListItem["Editor"];
  46:                 properties.ListItem["Editor"] = oSourceListItem["Editor"];
  48:             } 
  50:             properties.ListItem.Update(); 
  52:         }
  54:     }
  56: }


Code is self explanatory J


Happy coding!

Comments (4)

  1. Kan says:


    I tried changing the "Modified By" field using this code but it dint worked.

    properties.ListItem["Editor"] = oSourceListItem["Editor"];


    I checked out that it throws an exception saying – "The field you are trying to update may be read only".

    It would be really helpful if you could tell how to proceed further.

  2. Jordan says:

    Where is the event handler that I am changing?

Skip to main content