Friday, February 28, 2014

To get a User Id in AX client workspace Display..

//To get a User Id in AX client workspace Display..

class->info->method->workspaceWindowcreated
info Class: http://msdn.microsoft.com/en-us/library/xinfo.aspx


static void printCurrentUserId()


{
        //info(curUserId());
        //info(curext());

    SecurityRole        role;
     SecurityUserRole    userRole;
     UserInfo            userInfo,userInfoName;

     ;


    select firstonly  role
    exists join userRole
    where role.RecId     == userRole.SecurityRole
          && userRole.User == curUserId();
    select userInfoName where userInfoName.id == curUserId();

    info(strFmt("System Role :%1 \n UserID :  %2 \n userName: %3 \n UserCompany: %4", role.Name,curUserId(),userInfoName.name,curext()));

}

void workspaceWindowCreated(int _hWnd)
{

     UserInfo userInfoName;
        ;
    super(_hWnd);

    // Put workspace window specific initialization here.

    select userInfoName where userInfoName.id == curUserId();
     WinAPI::setWindowText(_hWnd,strFmt("%1-%2", userInfoName.name, WinAPI::getWindowText(_hWnd)));
}


// To get a Current User id and current working company in X++

info(curuserid());
info(curext());


// In order find out the employee linked to the current user..

In AX 2009:
EmplTable::find(SysCompanyUserInfo::find(curUserId()).EmplId);

In AX 2012:
HcmWorker::find(DirPersonuser::findUserWorkerReference(curUserId())).name();

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...