Tuesday, August 20, 2019

Get Active Directory user name details from x++ in Dynamics Ax

here an example how you can query your active directory and get user details like email, sid, name

static void JobEF_ActiveDirectoryUserDetails(Args _args)
{
    xAxaptaUserManager                  axUsrMgr;
    xAxaptaUserDetails                  axUsrDet;

    #define.NewDomain("yourDomain.com")

    axUsrMgr = new xAxaptaUserManager();

    try
    {
        axUsrDet = axUsrMgr.getDomainUser(#NewDomain, 'activeDirectoryUserName');

        if (axUsrDet)
        {
            info(strFmt('%1', axUsrDet.getUserMail(0)));
            info(strFmt('%1', axUsrDet.getUserSid(0)));
            info(strFmt('%1', axUsrDet.getUserName(0)));
        }

    }
    catch
    {
        info('Could not find');
    }
}

but please note AxaptaUserManager runs on the Client.
This cannot be used with the new batch framework. Since new batch
ramework runs on the server and we cannot call code on the client.

No comments:

Post a Comment