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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Get person name in Use...
Finance forum

Get person name in User page through X++ code in D365 F&O

(0) ShareShare
ReportReport
Posted on by 135

Hi,

can anyone please suggest ,how can i get the "Person Name " through code for my user id.

I want to fetch the Person Name value associated with the Current User and to use it in my logic.

Which method can return the Person Name from the User Id in D365 f&o

0876.Capture.PNG

  • Sohaib Cheema Profile Picture
    49,668 Super User 2026 Season 2 on at

    There are many ways to do it, such a following line of code can do

    HcmWorker::find(HcmWorkerLookup::currentWorker()).name();
  • BINAY KUMAR PANDEY Profile Picture
    135 on at

    Its not working , Its throwing Blank in Job ,  Can you please help with other options.

    I want to get the Person Name not ReciID in   my code for my current user id.

  • Sohaib Cheema Profile Picture
    49,668 Super User 2026 Season 2 on at

    Please watch user relationship with employee. There must be an active/valid relationship

    If following is not working, that's not my code. It's Microsoft code

    HcmWorkerLookup::currentWorker())

    Nowhere i returned recid, re-watch the code i provided originally it returns name, not recid

  • Suggested answer
    Jie G Profile Picture
    Microsoft Employee on at

    Hello Binay,

    You can use the userId2Name method of the DirPersonUser table.

        public static DirPartyName userId2Name(UserId _userId)
        {
            DirPersonUser   personUser;
            DirPerson       person;
    
            select Name from person
                exists join personUser
                where personUser.PersonParty == person.RecId
                    && personUser.User == _userId;
    
            return person.Name;
        }

    You can test it as following demo code

    class Class1
    {    
        public static void main(Args args)
        {      
           
            str currentUserId = curUserId();
            print currentUserId;
            DirPartyName PersonName = DirPersonUser::userId2Name(currentUserId);
            print PersonName;
     
        }
    
    }
  • Suggested answer
    Sukrut Parab Profile Picture
    71,741 Moderator on at

    Any of the below statement should give you name of the person associated with user .

    info(strFmt("%1",HcmWorker::find(DirPersonuserEX::findUserWorkerReference(curUserId())).name()));

     info(strFmt("-%1",HcmWorker::find(HcmWorkerLookup::currentWorker()).name()));

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans