How to get the name of the user changing a Task in a Custom workflow code

I was asked by one of my colleagues on how to have access to the name of the user who is modifying a task programmatically within the Workflow code. Every time a task gets modified by a user (SPTaskProperties.AssignedTo) the OnTaskChanged activity populates the OnTaskChanged.ExecutorProperty and the name of the user can be retrieved by referencing this property.

SPWorkflowActivationProperties.Web.CurrentUser.Name has "System Account" as value as by design all custom Workflow instances (Implemented by Visual Studio 2005/2008) run under that account.

Next post: Setting Workflow related properties in MOSS/WSS 3.0 using stsadm.exe


Comments (5)

  1. Nitin Rastogi says:


    Are you able to successfully update a task, I am struggling to do the same. This is what I have tried with nothing working

    1. UpdateTask Activity
    2. SPWorkflowTask.AlterTask

    3. ListItem.Update

    4. ListItem.SystemUpdate

    It would be great if you could help me as I am tired of hitting the wall.


    Nitin Rastogi

  2. Ali Mazaheri says:

    For updating a task you should be able to use SPWorkflowTaskProperties to update the task.

  3. says:

    Hi Ali,

    Thanks for the response. I used the same but it is giving me a weird error : "Correlation value has not been initialized on declaration updateReviewersTask for activity docApprovalActivity.UpdateReviewersTask"

    UpdateReviewersTask is an activity of type UpdateTask and it has its own corelation token separate from the CreateTask.

    This is the code snippet of what I am trying inside the UpdateTask’s method that I am invoking

    Dim spworkflowprops As New SPWorkflowTaskProperties

    Dim ctask As CreateTask = DirectCast(SequenceActivityForReviewers.Activities(0), CreateTask)

    Dim spTaskProps As SPWorkflowTaskProperties = ctask.TaskProperties

    m_guidReviewerTaskStatus = Guid.NewGuid()

    spworkflowprops.DueDate = DateTime.Today

    spworkflowprops.StartDate = DateTime.Today

    spworkflowprops.TaskItemId = spTaskProps.TaskItemId

    spworkflowprops.TaskType = spTaskProps.TaskType

    UpdateReviewersTask.TaskProperties = spworkflowprops

    UpdateReviewersTask.TaskId = ctask.TaskId

    Is there anything that I am missing ?

  4. Ali Mazaheri says:

    Is onWorkflowActivated the first activity in the design mode, also I’d double check the correlation token setting for all the activities, all the task related activities should use the same token.

  5. says:

    Hi Ali,

    Thanks a lot for quick response.

    Yeah OnWorkflowActivated is the first activity. As you mentioned "all the task related activities should use the same token" I thought so that could be the problem. But then how will I update a task based on TaskChange on some other task ?

    I have to update something on Task A from Task B.


    Nitin Rastogi

Skip to main content