Wednesday, August 28, 2019

get Ax UserId from from NetworkAlias in Dynamics Ax

I started by wring something like this

public static UserInfo findUserInfo(NetworkAlias _networkAlias)
{
    UserInfo userInfo;

    select firstOnly userInfo
        where userInfo.networkAlias == _networkAlias;

    return userInfo;
}

this code does the job, but after some research I could find a built in method. I think it is always better to use native code then write your own. It handles many more variables that I didn’t even think of. if you look inside (as you always should) you will see that the above code is quite incomplete.

static void JobUSerInfoFromWindowsUser(Args _args)
{
    UserInfo userInfo;
    AifWindowsUser windowsUser = 'myDomanin.com\\ActiveDirecotryUserName';
    userInfo = AifPortUser::getAxaptaUser(windowsUser);
    info(userInfo.id);
}

No comments:

Post a Comment