Monday, 20 December 2021

D 365 FO code UserID to Employee details and Vice-versa

Hi all, 

The below block of code will give you the detail of employee by is userid and Vice-Versa, 


Public HCMWorker getEmployeeDetailsByUserID(UserID    _UserId)

{

        DirPersonUser   personUser;

        HcmWorker       worker;

        if (_userId == "")

    {

        _userId == curUserId()

    }

            select firstonly * from worker

                exists join personUser

                where worker.Person == personUser.PersonParty

                &&    personUser.User == _userId;

            return worker;

        }



Public DirPersonUser   getUserDetailsByPersonnelNo(PersonnelNum    _PersonnelNo)

{

        DirPersonUser   personUser;

        HcmWorker       worker;

select * from personUser

join worker

where worker.Person == personUser.PersonParty

&&  worker.PersonnelNumber == _PersonnelNo;

Return personUser.UserID;

}


Keeping DAXing ;/