The code below will help out in fetching current user Information in AX 7 or D365 FO. Here I fetch the basic details of logged users including User Id, Person Name, and working position. In Dynamics 365 FO user details and associated personal information are kept in different tables. But by using the below x++ codes, you can easily fetch the details. For this, you create a runnable class then copy and paste the 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 the successful build of the project, you will get the output. You can elaborate the codes as per your requirement, by writing more codes you can also fetch more user details.