[X++] Find worker assigned to specific user

I already posted an article how to find the worker related to the current logged in User in Dynamics AX 2012 (here).

Now here is a peace of code to get the associated worker of any specific user, not just the current logged in user:

HcmWorkerRecId  workerRecId;
HcmWorker       hcmWorker;
UserId          userId  = curUserId();

workerRecId = DirPersonUser::findUserWorkerReference(userId);
hcmWorker   = hcmWorker::find(workerRecId);

info(hcmWorker.name());

Or to make it even shorter:

HcmWorker   hcmWorker;
UserId      userId  = curUserId();

hcmWorker   = hcmWorker::find(DirPersonUser::findUserWorkerReference(userId));

info(hcmWorker.name());

Robin

Software Engineer / Application Developer

Subscribe to robsCode

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!