Ask a questionAsk a question
 

AnswerUser ID in Workflow History

  • Thursday, June 04, 2009 8:44 PMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    In the Workflow History of my custom workflow everything seems to be performed by the System account.  Is it possible for this User ID to be the User ID of the person making the changes or updating a task etc. 

    Otherwise I do not see the point in having the User ID present in the Workflow History.

Answers

  • Friday, June 05, 2009 9:42 AMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Maybe this will help somebody else trying to do the same:  ( I found it here: http://blogs.officezealot.com/jkremer/archive/2007/01/17/20075.aspx)

    Workflow LogToHistoryList UserID and Task Activity Executor

    I got asked a question today about the unsightly "System Account" entry in the workflow history list.  System Account will always be the default but it makes more sense that the person who actually completed or executed the task or event associated with the log item is listed as the user in the workflow history list.  To make this happen, make sure you have created the Executor property on your OnTaskChanged activity (you'll see this property in the property window on the activity).  Also create the UserID property on the log activity.  In your code, correlate the two and wala, the unsighly System Account will be changed to the Executor of the task changed event.

    Update With Code:

    Supporting Function:

    private SPUser GetUserObject( string accountID)
    {

    try
    {
      if (accountID.IndexOf( @"\" ) > 0)
      {
         //this needs to come out of Active Directory
         SPUser user = this .workflowProperties.Web.SiteUsers[accountID];
         return user;
      }
      else
      {
         //this needs to come out of Active Directory
         SPUser user = this .workflowProperties.Web.SiteUsers[ @"OSS\" + accountID];
         return user;
      }
    }
    catch
    {
       //default to Administrator
       //this should be changed to someone in your organization
       SPUser adminUser = this .workflowProperties.Web.SiteUsers[ @"OSS\Administrator" ];
       return adminUser;
     }
    }

    In the OnTaskChanged event:

    SPUser executor = GetUserObject(onTaskChanged_Rejected_Executor);
    log_RejectChanged_UserId = executor.ID;


  • Tuesday, November 03, 2009 10:59 PMpritishjacob Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Although Julie's method worked well for me, I didn't feel the write up was clear enough on what code needed to be inserted, and where.  I think she assumed a certain level of familiarity with workflow, properties and related objects. I've maybe clarified a few things and added some screenshots to help anyone else doing this;

    http://pritishwrites.blogspot.com/2009/11/workflow-logtohistorylist-userid-and.html

    pritish.
    • Marked As Answer bywexford Saturday, November 14, 2009 9:27 PM
    •  

All Replies

  • Friday, June 05, 2009 7:18 AMSerge Luca [MVP]MVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I've just tested the OOB Collect feedback workflow, assigned task to user 1 & user 2 who completed their tasks; in workflow history , userId were user 1 and user 2. not System Account;
    Did you use a SPDesigner workflow ?

    Serge Luca; blog: http://www.redwood.be
  • Friday, June 05, 2009 8:55 AMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    No it's a custom workflow built in VS 2008.  I must need to assign the user id somewhere in the workflow.
    I'm not sure where the correct property is to do that though so it appears in the Workflow History.
  • Friday, June 05, 2009 9:15 AMSerge Luca [MVP]MVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You probably have to set it up at the level of the LogToHistoryList activity : it is the UserId property; you can get it from the SPUser.ID property if I remember well; there are different ways the get a SPUser object , like using the SPWeb.Users collection for instance.

    Hope this helps

    Serge Luca

    Serge Luca; blog: http://www.redwood.be
  • Friday, June 05, 2009 9:42 AMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Maybe this will help somebody else trying to do the same:  ( I found it here: http://blogs.officezealot.com/jkremer/archive/2007/01/17/20075.aspx)

    Workflow LogToHistoryList UserID and Task Activity Executor

    I got asked a question today about the unsightly "System Account" entry in the workflow history list.  System Account will always be the default but it makes more sense that the person who actually completed or executed the task or event associated with the log item is listed as the user in the workflow history list.  To make this happen, make sure you have created the Executor property on your OnTaskChanged activity (you'll see this property in the property window on the activity).  Also create the UserID property on the log activity.  In your code, correlate the two and wala, the unsighly System Account will be changed to the Executor of the task changed event.

    Update With Code:

    Supporting Function:

    private SPUser GetUserObject( string accountID)
    {

    try
    {
      if (accountID.IndexOf( @"\" ) > 0)
      {
         //this needs to come out of Active Directory
         SPUser user = this .workflowProperties.Web.SiteUsers[accountID];
         return user;
      }
      else
      {
         //this needs to come out of Active Directory
         SPUser user = this .workflowProperties.Web.SiteUsers[ @"OSS\" + accountID];
         return user;
      }
    }
    catch
    {
       //default to Administrator
       //this should be changed to someone in your organization
       SPUser adminUser = this .workflowProperties.Web.SiteUsers[ @"OSS\Administrator" ];
       return adminUser;
     }
    }

    In the OnTaskChanged event:

    SPUser executor = GetUserObject(onTaskChanged_Rejected_Executor);
    log_RejectChanged_UserId = executor.ID;


  • Tuesday, November 03, 2009 10:59 PMpritishjacob Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Although Julie's method worked well for me, I didn't feel the write up was clear enough on what code needed to be inserted, and where.  I think she assumed a certain level of familiarity with workflow, properties and related objects. I've maybe clarified a few things and added some screenshots to help anyone else doing this;

    http://pritishwrites.blogspot.com/2009/11/workflow-logtohistorylist-userid-and.html

    pritish.
    • Marked As Answer bywexford Saturday, November 14, 2009 9:27 PM
    •