Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,671 Moderator on at
    RE: Get person name in User page through X++ code in D365 F&O

    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()));

  • Suggested answer
    Jie G Profile Picture
    Jie G on at
    RE: Get person name in User page through X++ code in D365 F&O

    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;
     
        }
    
    }
  • Sohaib Cheema Profile Picture
    Sohaib Cheema 46,610 User Group Leader on at
    RE: GET PERSON NAME IN USER PAGE THROUGH X++ CODE IN D365 F&O

    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

  • BINAY KUMAR PANDEY Profile Picture
    BINAY KUMAR PANDEY 135 on at
    RE: GET PERSON NAME IN USER PAGE THROUGH X++ CODE IN D365 F&O

    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
    Sohaib Cheema 46,610 User Group Leader on at
    RE: GET PERSON NAME IN USER PAGE THROUGH X++ CODE IN D365 F&O

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

    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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans