web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get User Name in Custom Workflow

(0) ShareShare
ReportReport
Posted on by 12,119 Moderator

Hi all

I need to get User Name in a custom workflow. I know how to get user id.

Please tell me. How can I get user name in a custom workflow.?

Thank You

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Which User Name, The user who is running the workflow or some user field on entity?

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Saad Akhtar

    User who run this custom workflow. Means User name belongs to this userid

    ITracingService tracingService = context.GetExtension<ITracingService>();

               IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();

               IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();

               IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);

               var id = workflowContext.UserId;

    Thank You

  • Suggested answer
    AbiRami Profile Picture
    516 on at

    Hi,

    Check the link below to get the current user.  

    www.crmanswers.net/.../get-current-user-inside-workflow.html

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Abi Rami

    It is not my case. I need user on the basis of current user id, noparameters required in my case.

    Thank You

  • Sumit.icfai196 Profile Picture
    65 on at

    Hi Abdul

    The information will be easily available in the organisationservice context,its something similar to the getting the username in the plugin.

  • Verified answer
    Community Member Profile Picture
    on at

    create a query expression using the userid on systemuser entity and get full name of the user.

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Sumit Gupta

    But How?

    Thank You

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Abdul Wahab,

    If you get the user id, then you could retrieve the username using the following function.

    function GetUserName(userId) {
    var cols = ["domainname"];
    var resultXml = XrmServiceToolkit.Soap.Retrieve("systemuser", userId, cols);
    if (resultXml != null && resultXml.attributes['domainname'] != null) {
    var username = resultXml.attributes['domainname'].value;
    }
    }
  • Community Member Profile Picture
    on at

    Use this code:

    	Entity User = service.Retrieve("systemuser", context.UserId, new ColumnSet(new String[] {"fullname"}));
        if (User != null)
    		{
    			if (User.Attributes.Contains("fullname") && User.Attributes["fullname"] != null)
    				{
    					string UserName = ((string)User.Attributes["fullname"]);
                    }
           }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans