Unleashing Dynamics 365 Excellence: Your Source for Pro Tips and Snippets at D365Snippets.com

Our blog provides a curated collection of tips, tricks, and code snippets that streamline your workflow and enhance your proficiency.
Unleashing Dynamics 365 Excellence: Your Source for Pro Tips and Snippets at D365Snippets.com

How to get current logged user information using x++ code in D365fo

0

Suppose you have a small requirement where you have to pick and display current log in user informations like name , department , position etc.The code below will help out in fetching current user Information in AX 7 or D365 FO. Here i fetching the basic details of logged user including User Id, Person Name and working position. In dynamics 365 fo user details and associated personal information are keeping in difference tables. But by using the below x++ codes , you can easily fetch the details.

If you are a beginner or new to dynamics 365 Finance & Operations, you can use Microsoft'f Free Virtual Machine. Learn How to Set Up a Free Virtual Machine for Dynamics 365 Development

For this you create a runnable class then copy and paste below codes to the main method. 

class RunnableUserInfo
{
  
   public static void main(Args _args)
   {
       
       HcmWorkerRecId              hcmWorkerRecId;
       HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
       HcmPositionDetail           hcmPositionDetail;
       OMOperatingUnit             omOperatingUnit;
   
       hcmWorkerRecId = HcmWorker::userId2Worker(curUserId());
       hcmPositionWorkerAssignment =   HcmPositionWorkerAssignment::getActivePositionWorkerAssignment(hcmWorkerRecId);
       hcmPositionDetail = HcmPositionDetail::findByPosition(hcmPositionWorkerAssignment.Position);
       
       DirPartyName PersonName = DirPersonUser::userId2Name( curUserId());
   
       info(strFmt("User Id : %1 - Name : %2 - Position: %3",
               curUserId(),PersonName,hcmPositionWorkerAssignment.description()));
   }
 
}

After successfull build of the project you will get the output. You can ellaborate the codes as per your requirement, by writing more codes you can also fetch more user details.

How to get current logged user information using x++ code in D365fo

All the tutorials are for beginners , if you dont hav a virtual machine for your learning purposes you can use microsofts free Virual machine. if this tuotorial is useful , please share to others.

Happy coding with D365 Snippets

Tags

Get Current User and User Name in d365
Get Current User and User Name in AX
How to get current user information using x++ D365
How to get current user information using x++ AX 7
Get Current User Name in  X++ in D365FFO
Get Current User Name in  X++ in AX

Post a Comment

0Comments
Post a Comment (0)