Friday, February 28, 2014

TO get a current User Id and User Role assignment through X++

// TO get a current User Id and User Role  and WorkerIdassignment through X++ in ax 2012



static void HCMWorkerIDFromUSerID(Args _args)
{
    UserInfo    userInfo;
    SecurityUserRole securityUserRole;
    SecurityRole       Roles;
    HcmWorkerRecId workerRecId ;
    str workerDesgn,workername;
    Label label = new Label();
   
    info(curUserId());              // Current User id
    workerRecId = DirPersonUser::currentWorker();
    info(strFmt("%1",workerRecId)); // HCM.Person   // worker id

    while select userInfo where userInfo.Id == curUserId()
            join securityUserRole where securityUserRole.User == userInfo.Id
                   join Roles where Roles.RecId  == securityUserRole.SecurityRole
    {
        workerDesgn = Roles.Name;      
        info(strFmt("%1",workerDesgn));
        workername = label.extractString(Roles.Name);
        info(strFmt("%1",workername));// Current WOrker 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...