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

CRM 2011 Dialogs do not provide any easy way to access the currently logged in user’s information.

By creating a new instance of an entity (I create a special entity), the owner field will contain the currently logged in user.

The steps I follow:

  1. Log into CRM and create a new entity, call it new_CurrentDialogUser. You do not have to add any new fields.
  2. Open your existing dialog for editing.
  3. From the Dialog editor, the first thing to do is create an instance of new_CurrentDialogUser.
    • Create a new stage, positioned at the very beginning of the dialog.dialogue graphic 1
    • Click ‘Add Step’ and select ‘Create Record’.
    • Choose the type to be new_CurrentDialogUser.
    • Click on properties. Notice the owner field is presented. Do not populate this field. Instead, when the ‘Create Record’ step executes, it will default the owner to the currently logged in user.dialogue graphic 2
  4. Once the ‘Create Record’ steps executes in your dialog, you have the ability to reference this step from throughout the rest of your dialog, just as if you were referencing the current record that is related to your dialog.
  5. In my case, I use an ‘Assign Value’ step to store the owner of the newly created new_ CurrentDialogUser to a local variable, called CurrentUser.
    • Click ‘Add Step’ and choose ‘assign value details.’dialogue graphic 3
    • In the ‘Look For’, select from the local values, the choice ‘Create (Current Dialog User)’.dialogue graphic 4
  6. Finally, once my am done using the current user, I perform an ‘UpdateStatus’ step, as a means to
    deactivate the dynamically created new_CurrentDialogUser instance.dialogue graphic 5

    • Add step, select ‘Change Status’
    • Select the ‘Create (Current Dialog user)’.dialogue graphic 6
    • Change the status to ‘Inactive’.dialogue graphic 7
  7. At this point, you can adopt Gonzalo Ruiz’s custom activity workflow, which exposes a ‘delete’ record step. The deleting can performed as  separate workflow.

3 thoughts on “CRM 2011 – How to get the current user from within a dialog

  1. Hi, to find, who is running current dialog session, you can use this simple workflow activity, just call it at the beginning of a dialog and read its output argument “Initiating User”.

    using System.Activities;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Workflow;

    public class GetInitiatingUserActivity : CodeActivity
    [Output(“Initiating User”)]
    public OutArgument InitiatingUserReference { get; set; }

    protected override void Execute(CodeActivityContext context)
    IWorkflowContext wcontext = context.GetExtension();
    InitiatingUserReference.Set(context, new EntityReference(“systemuser”, wcontext.InitiatingUserId));

  2. I mostely use the Standard function “Query CRM data” to find current user. Than I have an introduction frame within the Dialog to explain function and where I place a simple line “Dialog is running in context of…” and add the result of query. So I´m now able to use current user without creating any dummy data.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s