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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Get position Id from PersonnelNumber using x++

(0) ShareShare
ReportReport
Posted on by 390

Hey Team,

I'm rehiring  employees and therefore I need the last issued Position Id for that employee. I have the personnel number of that employee so how can I find the most recent position for that employee using the Personnelnumber? Please help me with this issue.

I have the same question (0)
  • Suggested answer
    Junaid Idrees Profile Picture
    on at
    RE: Get position Id from PersonnelNumber

    Hi Skd,

    Did you check the worker Position assignment screen to check the Position ID:

    Data Source: HcmPositionWorkerAssignment
    Data Field: Position

    63811.PNG

  • skd Profile Picture
    390 on at
    RE: Get position Id from PersonnelNumber using x++

    Hey  Junaid Idrees,

    I want to do this through x++.

  • WillWU Profile Picture
    22,361 on at
    RE: Get position Id from PersonnelNumber using x++

    Hi skd,

    Please check the following code:

    HcmWorker hcmWorker;
    HcmPosition hcmPosition;
    HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
    
    select firstonly hcmWorker where hcmWorker.personnelNumber == 000001; // Personnal number
    hcmWorker.name())); // worker Name
    info(strfmt(“Department Name :%1”,hcmWorker.primaryDepartmentName(); // department name
    
    select * from hcmPositionWorkerAssignment where hcmPositionWorkerAssignment.Worker == hcmWorker.RecId;
    info(strfmt(“Start date :%1”, DateTimeUtil::date(hcmPositionWorkerAssignment.ValidFrom))); // Start date
    
    select * from hcmPosition where hcmPosition.RecId == hcmPositionWorkerAssignment.Position;
    info(strfmt(“Position name :%1”, hcmPositionDetail::find(hcmPosition.RecId).Description)); // Position Name

  • skd Profile Picture
    390 on at
    RE: Get position Id from PersonnelNumber using x++

    Hey Will Wu,

    I tried the above code but it's not giving me position of past workers, which is a problem. As I want to rehire those employee who have been terminated, so can you give me a solution to this?

    This was the result I got when I tried to get position of the past worker:

    GetWorkerDetails.png

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,029

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 871 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 582 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans