web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :

Get Parent Position Worker Name from Current Worker Position | D365FO X++

dasdasd Profile Picture dasdasd 841
In this blog, we explore how to fetch the Parent Position Worker from a Current Worker Position in D365FO.


















The solution revolves around core HCM tables: 
- HcmWorker
- HcmPositionWorkerAssignment
- HcmPosition
- HcmPositionHierarchy.

Source Code:

public Name getParentPositionWorkerName(HcmPositionRecId _positionRecId)
{

    HcmWorker                   hcmWorker;

    HcmPositionWorkerAssignment workerAssignment;

    HcmPositionHierarchy        hcmPositionHierarchy;

    utcdatetime                 now = DateTimeUtil::getSystemDateTime();

 

    // 1. Find the parent position in the hierarchy

    // 2. Join to the assignment table to find who sits in that parent position

    // 3. Join to the worker table to get the name

    select firstonly * from hcmWorker

    join workerAssignment

        where workerAssignment.Worker == hcmWorker.RecId

           && workerAssignment.ValidFrom <= now

           && workerAssignment.ValidTo   >= now

    join hcmPositionHierarchy

        where hcmPositionHierarchy.ParentPosition == workerAssignment.Position

           && hcmPositionHierarchy.Position       == _positionRecId

           && hcmPositionHierarchy.ValidFrom     <= now

           && hcmPositionHierarchy.ValidTo       >= now;

 

    return hcmWorker.name();

}


This was originally posted here.

Comments

*This post is locked for comments