How to get current user information using x++ in D365 F&O | AX 2012

When building business logic in Microsoft Dynamics AX or Dynamics 365 for Finance and Operations, it’s often important to know who the current logged-in user is.

This blog post shows a simple X++ example to fetch the current user ID and user account type at runtime.


curUserId()

This built-in function returns the User ID of the person currently logged into the application.


class getCurrentUserInfo
{      
    /// <summary>
    /// this method used to get current user detail
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {  
        info(strfmt("Current User - %1",curUserId()));    
        info(strfmt("User Account Type - %1",xUserInfo::find(false,curUserId()).accountType));  
    }

}

Output will look something like this:






THANK YOU






Comments

Post a Comment