Welcome to MSDN Blogs Sign in | Join | Help

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.

Note:
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

 

Published Sunday, January 27, 2008 11:13 PM by AMazaheri

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

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

Hi,

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.

Thanks,

Nitin Rastogi

Friday, February 29, 2008 1:46 AM by Nitin Rastogi

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

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

Sunday, March 02, 2008 1:45 PM by AMazaheri

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

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 ?

Tuesday, March 04, 2008 11:21 PM by nitin_karan

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

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.

Tuesday, March 04, 2008 11:37 PM by AMazaheri

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

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.

Thanks,

Nitin Rastogi

Wednesday, March 05, 2008 7:58 AM by nitin_karan

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker