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

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...