Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

retrieve worker line manger ( report to position worker name ) using x++

Posted on by Microsoft Employee

I want to create small job that list all worker name, position, report to position, and report to position worker name

static void GetPosOFEmployees(Args _args)
{
   HcmWorker hcmWorker;
   HcmPositionWorkerAssignment workerAssignment;
   HcmPosition hcmPosition;
   HcmPositionDetail   hcmPositionDetail;


   while select recid, person from hcmWorker
       join worker, position from workerAssignment
       where workerAssignment.Worker == hcmWorker.RecId
       join recid from hcmPosition
       where hcmPosition.RecId == workerAssignment.Position
       join position, description from hcmPositionDetail
       where hcmPositionDetail.Position == hcmPosition.RecId

   {        
       info(strFmt("%1's position is %2 ",hcmWorker.name(),
       hcmPositionDetail.Description));
   }


}


*This post is locked for comments

  • Muhammad Zahid Profile Picture
    Muhammad Zahid 480 on at
    RE: retrieve worker line manger ( report to position worker name ) using x++

    Hi I have the similar scenario I am trying to show the position id , worker name and positionreporttoid and workerreportingtoname using the data entity D365 for operations on which change tracking is enable.

     I am able to get the reportstopositionid through hcmpositionhierarchy and than through hcmposition table but when I try join it with hcmpositionworkerassingment and than hcmworker to get the worker name of position reports to. I am getting multiple records of child records of that position if I modified the reports toposition data at any stage.

    Can anyone guide me how can i get the reports to position name in my data entity with out getting the multiple records?? can we use display methods or anything else?

    below is the image of my data entity.

     16682.Untitled.jpg

  • Suggested answer
    Rohin Profile Picture
    Rohin 4,624 on at
    RE: retrieve worker line manger ( report to position worker name ) using x++

    Well, I have tried your job in my environment and realized that you are not getting report to position and  report to position worker name what you are expecting .

    If i am right here, I modified you code to get report to position name , please see below code:

    static void GetPosOFEmployees(Args _args)
    {
       HcmWorker hcmWorker;
       HcmPositionWorkerAssignment workerAssignment;
       HcmPosition hcmPosition;
       HcmPositionDetail   hcmPositionDetail;
       HcmPositionHierarchy hcmPositionHierarchy; // declare this table to get report to position 
    
    
       while select recid, person from hcmWorker
           join worker, position from workerAssignment
           where workerAssignment.Worker == hcmWorker.RecId
           join recid from hcmPosition
           where hcmPosition.RecId == workerAssignment.Position
           join hcmPositionHierarchy
           where hcmPositionHierarchy.Position == hcmPosition.RecId
           join position, description from hcmPositionDetail
           where hcmPositionDetail.Position == hcmPosition.RecId
    
       {        
           info(strFmt("%1's position is %2 and report to position :%3 ",hcmWorker.name(),
           hcmPositionDetail.Description,hcmPosition::find(hcmPositionHierarchy.ParentPosition).description()));
       }
    
    
    }


    similarly , you can get report to position worker name. please let me know if it helps you

  • Rohin Profile Picture
    Rohin 4,624 on at
    RE: retrieve worker line manger ( report to position worker name ) using x++

    Sorry, but you have not mention what problem you are getting with this? any specific error or not getting expected result?

    please provide more details

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans