CRM 2011 – How to get the current user from within a worflow

Today I needed to get the Current User inside a workflow activity. In CRM 2001 process it is not possible to get current user and in some cases a reference can be necessary in order to set the right user.
A Custom Workflow Activity can be created for this purpose, taking advantage of the InitiatingUserId property.

public class GetCurrentUser : CodeActivity
        [Output("Current User")]
        public OutArgument<EntityReference> CurrentUser { get; set; }
        protected override void Execute(CodeActivityContext context)
            IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
            CurrentUser.Set(context, new EntityReference("systemuser", workflowContext.InitiatingUserId));


Now from our workflow activity we have the current user.


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:


Stai commentando usando il tuo account Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...