How to get workers current position, department and manger in X++

 How to get workers current position, department and manger in X++


In Dynamics 365 F&O, we have HcmWorkerHelper class which gives much information about worker such as department, primary position, current legal entity and so on.

The code to get worker’s current position.

This gives current worker record.

HcmWorkerRecId   hcmWorkerRecId =  HcmWorker::userId2Worker(curUserId());
HcmPositionRecId hcmPositionRecId = HcmWorkerHelper::getPrimaryPosition(hcmWorkerRecId);
positionDetail = hcmPositionDetail::findByPosition(HcmPosition::find(HcmWorkerHelper::getPrimaryPosition(hcmWorker.RecId)).RecId);

The code to get current worker manager.

HcmWorker currentWorker = HcmWorker::find(HcmWorkerLookup::currentWorker());
HcmWorker currentWorkerManager = HcmWorkerHelper::getManagerForWorker(currentWorker.RecId);

The code to get current worker department.

HcmWorker currentWorker = HcmWorker::find(HcmWorkerLookup::currentWorker());
OMOperatingUnit department = HcmWorkerHelper::getPrimaryDepartment(currentWorker.RecId);

The code to get current worker legal entity.

HcmWorker currentWorker = HcmWorker::find(HcmWorkerLookup::currentWorker());
CompanyInfo legalEntity = HcmWorkerHelper::getLegalEntity(currentWorker.RecId);

Comments

Popular posts from this blog

D365FO – AX – X++ –Refresh, Reread, Research, and ExecuteQuery

Create Inventory Journal through Code in D365FO X++

SalesLine Reservation in D365fo x++