About Me

Having 12 years experience in Microsoft technologies.Since more than 7 years working in SharePoint technologies. Expert in providing consultation for SharePoint projects. Hands on with development and administration.

Wednesday, 22 May 2013

Update sharepoint 2010 workflow tasks with current logged in user name

Problem:

By nature, SP workflows runs with 'System Account' and all workflow related tasks have been created & modified by system account. What if, task should be created/modified with current login user who initiated workflow? There is no answer and I searched in a google and no luck.. finally i tried my self with the help of old MSDN article and found a solution.

Solution:

How to capture current login name of the user and assign into workflow propertis?

Here is the code snippet

string username = string.Empty;
private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
{
username = e.Identity;
SPUser user = workflowProperties.Web.SiteUsers[username].ID;
 workflowProperties.Item["Checked by"] = user.Name;
 workflowProperties.Item.Update();
}

That's it...

Happy programming......
 

No comments:

Post a Comment