Navigation Bar

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.




13 comments:

  1. Im very new to all this but Im suffering this issue. May you publish the whole code? I'm getting errors with GetWorkflowHistoryItem, GetItemForThisWorkflow and Helper.

    Thanks!

    ReplyDelete
  2. I will publish updated code in codeplex soon.

    ReplyDelete
  3. Hello,

    can you please also post the GetItemForThisWorkflow,GetWorkflowHistoyItem method and the Helper class?!

    ReplyDelete
  4. hi there, when we can expect the code? Thanks

    ReplyDelete
  5. Hi,

    Source code has been uploaded at https://approvalworkflowfix.codeplex.com/

    Thanks,
    Muhammad Masood
    http://blog.mmasood.com

    ReplyDelete
  6. The clarity in your post is simply spectacular and I can assume you are an expert on this field. Well with your permission allow me to grab your rises feed to keep up to date with incoming post.

    ReplyDelete
    Replies
    1. Thanks for your comments. The purpose of my blog to help myself and others.

      Delete
  7. Hi,

    I would still like to use the option to "Start this workflow to approve publishing a major version of an item." Is this possible with this code? Also I am new to programming SharePoint. How and where do I put this code?
    Thanks

    ReplyDelete
    Replies
    1. Hi,

      You can use that option but it will show the "System Account" in modified by field even though the modification will be done by your last user.

      Thanks.

      Delete
    2. How and where do you install your code to make this work?

      Thanks

      Delete
    3. This comment has been removed by the author.

      Delete
    4. The code goes to FARM's GAC.

      Thanks

      Delete