locked
Getting the currently signed in user in a custom workflow RRS feed

  • Question

  • Hi,

    There are a number of different posts about trying to get actual current user in a custom workflow and not the owner of the workflow that created the entity.

    Most of them are older and there are a couple that suggest other methods, like WhoAmIRequest and PortalCrmConfigurationManager.

    Does anyone know if there is a way to get the current user? Does WhoAmIRequest get the logged on user every time?

    Thanks,

    Gary


    • Edited by GaryMk Wednesday, July 10, 2013 6:30 PM clarity
    Wednesday, July 10, 2013 6:30 PM

All replies

  • Hi,

    A workflow will run under the context of the owner of the workflow, but you can find the id of the user who trigged it (via an create/update/delete etc.) using the initiatinguserid -  http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.iexecutioncontext.initiatinguserid.aspx


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Guido PreiteMVP Wednesday, July 10, 2013 7:14 PM
    • Unproposed as answer by GaryMk Wednesday, July 10, 2013 7:15 PM
    • Proposed as answer by Guido PreiteMVP Wednesday, July 10, 2013 8:04 PM
    Wednesday, July 10, 2013 6:43 PM
    Answerer
  • Hi Scott,

    Thanks for the reply. The user that triggered it is the same as the owner of the workflow. I'm looking for the signed on user.

    Gary

    Wednesday, July 10, 2013 6:56 PM
  • Hi Gary,

    You could work with an input parameter on the workflow and set it to the workflow creator.

    Best regards

    Steve


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at

    Wednesday, July 10, 2013 7:49 PM
  • Thanks for the reply

    I am not looking for the workflow creator but the user that is signed on at the time the workflow is executed.

    Gary

    Wednesday, July 10, 2013 7:52 PM
  • Hi Gary,

    So there are two users involved - one is the currently signed in user who performs the action that triggers the workflow - the other is the user who owns the workflow who will be impersonated when creating/updating records inside the workflow.

    The InitiatingUserId will give you User 1 - and the UserId property will give you User 2.

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, July 10, 2013 7:59 PM
    Answerer
  • Hi,

    Just tested it in my environment:

    IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
          
    var _userID = workflowContext.UserId;

    gives me the user id which fires the workflow in the front end. 

    best regards

    steve


    Steve Sämmang, Vienna, Austria
    Blog: xrm.io Website: simplic.at

    Wednesday, July 10, 2013 8:08 PM
  • Correct, the signed on user is different than the creator of the workflow.

    I have tried both Userid and InitiatingUserId are both the same.

    • Edited by GaryMk Wednesday, July 10, 2013 9:20 PM clairify
    Wednesday, July 10, 2013 9:06 PM
  • This gives me the owner of the workflow and not the user that is signed in.
    Wednesday, July 10, 2013 9:12 PM