Retrieving Worker Personal & HR Details in D365FO Using X++

 

Introduction

In HR and payroll modules of Dynamics 365 Finance & Operations, it’s common to retrieve detailed employee information — from personal details like marital status and gender, to financial dimensions and reporting structure.

In this post, I’ll share how I query D365FO tables to get:

  • Personal details (marital status, gender, birth date, etc.)

  • Age calculation

  • CNIC details

  • Financial dimensions (Department, Business Unit)

  • Reporting hierarchy (Who the worker reports to)


Getting Personal Details of a Worker

Fetch details like marital status, gender, birth date, number of dependents, and ethnic origin.

select hcmPersonDetails
    where hcmPersonDetails.Person == hcmWorker.Person
    join dirPartyTable
        where dirPartyTable.RecId == hcmPersonDetails.Person
    join hcmPersonPrivateDetails
        where hcmPersonPrivateDetails.Person == dirPartyTable.RecId
    join hcmEthnicOrigin
        where hcmEthnicOrigin.RecId == hcmPersonPrivateDetails.EthnicOrigin;

Calculating Age

date _asOfDate = HcmDateTimeUtil::currentDate();
age = yearDiff(_asOfDate, hcmPersonPrivateDetails.BirthDate);


Fetching CNIC Details

Retrieve the worker’s CNIC number and expiry date.

select firstonly IdentificationNumber, ExpirationDate 
from hcmPersonIdentificationNumber
    where hcmPersonIdentificationNumber.Person == hcmWorker.Person;

Getting Financial Dimensions

Fetch Default Dimension for Worker

select worker, defaultDimension from hcmEmployment where hcmEmployment.Worker == hcmWorker.RecId;

Get Department Dimension


select dimensionAttributeValueSetItem where dimensionAttributeValueSetItem.DimensionAttributeValueSet == hcmEmployment.DefaultDimension join dimensionAttributeValue where dimensionAttributeValueSetItem.DimensionAttributeValue == dimensionAttributeValue.RecId join dimensionAttribute where dimensionAttributeValue.DimensionAttribute == dimensionAttribute.RecId && dimensionAttribute.Name == 'Department';

To get the Business Unit dimension, simply replace 'Department' with 'BusinessUnit'.

Finding Reporting Position

Identify the position (and person) to whom the worker reports.
select * from hcmPositionWorkerAssignment where hcmPositionWorkerAssignmentReportsToPosition.Worker == hcmWorker.RecId;




Comments

Popular posts from this blog

JSON-Based HTTP POST Request from X++ to Retrieve an Access Token

Calling an External API from D365FO Using X++ to Retrieve a Token

Restricting Date Selection in Dynamics 365 FO using X++