If you need to get details about the current user the first method you want to look at is
UserId sUserId = curUserId();
To get more details you want to look at DirPersonUser table which relates to DirPerson and UserInfo and contains methods that cover most requirements.
I think a sample will respond to most questions, once you get the idea you can discover more yourself.
For completeness I also added some examples to look in the Active Directory user data.
static void Job_GetCurrentUserDetails(Args _args)
{
UserId userId;
DirPartyRecId partyRecId;
DirPartyName name;
UserInfo userInfo;
HcmWorkerRecId workerRecId;
DirPartyTable partyTable;
HcmPersonnelNumberId personnelNumber;
xAxaptaUserManager axUsrMgr;
xAxaptaUserDetails axUsrDet;
//curUser
userId = curUserId();
info(strFmt('UserId: %1', userId));
//get user name:
name = DirPersonUser::userId2Name(userId);
info(strFmt('Name: %1', name));
//get user info
userInfo = DirPersonUser::current().userInfo();
info(strFmt('User language: %1', userInfo.language));
info(strFmt('network alias: %1', userInfo.networkAlias));
info(strFmt('network domain: %1', userInfo.networkDomain));
//Get worker
workerRecId = Global::currentWorker();//very fast because is chached
info(strFmt('workerRecId: %1', workerRecId));
personnelNumber = DirPersonUser::currentWorkerPersonnelNumber();
info(strFmt('worker personnel number: %1', personnelNumber));
info(strFmt('Worker name: %1', HcmWorker::find(workerRecId).name()));
//get party
partyRecId = Global::currentParty();//very fast because is chached
partyTable = DirPartyTable::findRec(partyRecId);
info(strFmt('party Name: %1', partyTable.Name));
info(strFmt('party primary Email: %1', partyTable.primaryEmail()));
//get Active directory user datails
axUsrMgr = new xAxaptaUserManager();
axUsrDet = axUsrMgr.getDomainUser(userInfo.networkDomain, userInfo.networkAlias);
if (axUsrDet)
{
info(strFmt('Active directory Email: %1', axUsrDet.getUserMail(0)));
info(strFmt('SID: %1', axUsrDet.getUserSid(0)));
info(strFmt('Active directoru user name: %1', axUsrDet.getUserName(0)));
}
}
Wherever possible try to use the global helper methods that make use of the SysGlobalObjectCache and are much faster.
No comments:
Post a Comment