Search This Blog

Monday 4 February 2019

D365 for Finance and Ops X++ Job to Get the Primary Position Title of Employee by Passing Worker Recid

Below is the code snippet to get the Primary Position Title of the employee by passing the worker recid.


private HcmTitleId getPositionTitle(HcmWorkerRecId hcmWorkerRecid)
    {
        HcmWorker                   hcmWorker;
        HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
        HcmPosition                 hcmPosition;
        HcmPositionDetail           hcmPositionDetail;
        HcmTitle                    hcmTitle;

        hcmPositionWorkerAssignment = HcmWorkerHelper::getWorkerPrimaryPositionAssignment(hcmWorkerRecid);
       
        select TitleId from hcmTitle
            join hcmPositionDetail
        where hcmPositionDetail.Title == hcmTitle.RecId
            join hcmPosition
            where hcmPosition.RecId == hcmPositionWorkerAssignment.Position;
       
        return hcmTitle.TitleId;
    }

Note that HcmPositionWorkerAssignment is a validTimeState table. The above query will only retrieve position assignment that is currently active. 
This posting is provided "AS IS" with no warranties, and confers no rights.

Thanks,
Zahid