Posted by: R Manimaran | July 16, 2012

SharePoint Workflow: System Accout in Modified By column

Showing “System Account” while updating using Workflow

I used to work mostly in the Visual Studio workflow than the SharePoint Designer workflow.

While doing so, I used to update the ListItem to do some status change in the metadata.

If we change the metadata we get the value of the modified By column as System account instead of the workflow initiator.

Below is the Workflow which do an update. Here I placed only one activity (onWorkflowActivated).

In the Workflow activated invoke event I placed the following code.

SPListItem item = workflowProperties.Item;
item["Status"] = "In Progress";

When the workflow gets activated, the Status column gets the value of “In Progress”. But the value of the Modified By column will have the value of “System Account”

To resolve this with the actual user we need to rewrite the code as below.

 SPUser orginatingUser = workflowProperties.OriginatorUser;
 Guid webID = workflowProperties.WebId;
 Guid siteID = workflowProperties.SiteId;
 using (SPSite site = new SPSite(siteID, orginatingUser.UserToken))
 using (SPWeb web = site.OpenWeb(webID))
 SPList myList = web.Lists[workflowProperties.ListId];
 SPListItem item = myList.GetItemById(workflowProperties.ItemId);
 item[<"Status"] = "Started";

So, each time do an update on the SharePoint List Item, create a new instance of the SPSite object with the UserToken and do an update.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: