Pages

Monday, 10 December 2012

Approval worfklow showing "System Account" in "Modified By" field


As you may know there is known issue or product feature that when you use OOTB Approval workflow, it publishes the item but leaves Modified by as System Account (http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId=%7b72C1C85B-1D2D-4A4A-90DE-CA74A7808184%7d&pID=865 ).

I am writing this blog 1) to save time of my other developer fellows as I have spent lot of time to figure out the issue 2) to help myself for future reference and my other fellows who are still struggling to find out the solution.

You may find below solution when you google it:

1.       Adding another column to track Modified By and displaying in all views

2.       Adding hidden column and call UpdateOverwriteVersion to overwrite when SharePoint Approval workflow updates the item

3.       Update OOTB Approval workflow (tried as well but having workflow publishing issue through SPD)

I have tried option #1 and it works fine, but our client was not happy with that solution. Then we implemented option #2, during testing we observed that after calling UpdateOverwriteVersion it increments by 0.1 version. So this solution is not going to work L

I started analysing “Approval – SharePoint 2010” OOTB workflow and I found that the workflow updates the content approval status using workflow author and that is leaving the “Modified By” field with System Account. Please see below snapshot of OOTB Approval workflow:


[Figure 1]

After analysis, I created a workflow association with below configuration:

 
[Figure 2]




[Figure 3]

When creating association, I did not select options (i.e. Start this workflow to approve publishing a major version of an item” and “Enable Content Approval”) and tested manually and everything worked as expected (i.e. not getting System Account in Modified By field).

So, I wrote an event receiver to publish item through code when the outcome of workflow is approved otherwise rejected.

So I came up with solution #4 that is given below:

1.       Create workflow association as shown in Figure 1 and Figure 2.
2.     An Event Receiver that kicks off the workflow (as I had a requirment to kick approval  process ONLY for some documents). If you don't have this kind of requirement then you don't need this even receiver.
 
3.       Write an event receiver (SPWorkflowEventReceiver) for workflow completed and publish item (a sample of code is posted below as image L)
 
 
 
 
 
 
 
 
 
NOTE: The properties contains information about Workflow History item.

You can download source code from https://approvalworkflowfix.codeplex.com/
Hope this post will help you.