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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Retrieve legal entity from employment from worker

(0) ShareShare
ReportReport
Posted on by

Hi all,

I am trying to print/info the legal entity that a Workers Employment is belonging to.

Am struggling to get the desired answer.

Have tired the following and other which ways.

any help appreciated.

static void getWorkerProject(Args _args)
{
HcmEmployment hcmEmployment;
HcmEmployment hcmEmp;
DimensionAttributeValueSetItem setItem;
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttribute;
CompanyInfo ci;
HcmWorker w;
;

dimAttribute = DimensionAttribute::findByName('Project');
//w = HcmEmployment::findByWorkerLegalEntity(

while select crossCompany hcmEmployment
join RecId, DisplayValue from setItem
where setItem.DimensionAttributeValueSet ==
hcmEmployment.DefaultDimension
join dimAttrValue
where dimAttrValue.RecId == setItem.DimensionAttributeValue &&
dimAttrValue.DimensionAttribute == dimAttribute.RecId &&
dimAttrValue.IsDeleted == false
{
//hcmEmp = HcmEmployment::findByWorkerLegalEntity(HcmWorker::find(hcmEmployment.Worker).RecId,hcmEmployment.LegalEntity);


info(strFmt("Employee = %1 %2 = %3 %4 %5 %6 %7",
HcmWorker::find(hcmEmployment.Worker).PersonnelNumber
,dimAttribute.Name
,setItem.DisplayValue
,CompanyInfo::findDataArea(hcmEmployment.dataAreaId).company()
,hcmEmployment.LegalEntity
,hcmEmployment.dataAreaId
,CompanyInfo::findDataArea(hcmEmployment.dataAreaId).Name ));


}
}

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,775 Super User 2026 Season 1 on at

    Please update this question with the current output and your desired output. You are stating you need information about the legal entity, then you are sharing some code which includes way more than only the legal entity. Also the method name is getWorkerProject. So this is confusing me. When you inform us about the current and desired output, I'm probably able to understand your question.

  • Community Member Profile Picture
    on at

    You will get the employment history details if you join HcmEmployment and HcmWorker. What is the expectation ?

  • Community Member Profile Picture
    on at

    Hi all,

    apologies i was away for a week there. thanks for responding.

    I have 2 companies/LEs, simply called A101, A102

    My problem is that from the 3 entries shown in the picture:

    ax_5F00_emp.JPG

    Line 1 and 3 are from Employee A, Line 2 is from Contractor B (obviously both workers).

    Employee A has two employment records, one in each of A101, A102.

    Employee A has a Financial Dimension 'Project' in both A101 and A102.

    Contractor B has only Employment record in A102.

    Contractor B has a Financial Dimension 'Project' against only A102.

    However, my results are not as expected. I would expect

    Employee = A, Project = P101, A101, 'My Company A101'

    Employee = A, Project = P102, A102, 'My Company A102'

    Contractor = B, Project = P102, A102, 'My Company A102'

    My unexpected result is that the code is pulling back only A101 and DAT....

    I understand that A101 is from the current code execution LE, but unsure as to why DAT is being returned.

    Thanks all.

    Rgds,

  • Verified answer
    Community Member Profile Picture
    on at

    Did you mean to sort the data by worker? so  that all the employment history for Employee A is shown first?

    I think you have given hcmEmployment.dataAreaId as the 2nd last value in the infolog which is returning DAT. this is because HcmEmployment table is not company specific

    hcmEmployment.LegalEntity is giving you the right value, Just get the corresponding company name for the RecId

  • Verified answer
    André Arnaud de Calavon Profile Picture
    303,775 Super User 2026 Season 1 on at

    Manish is correct. The crossCompany statement is not needed. Using the hcmEmployment.LegalEntity value you can retrieve additional information from the CompanyInfo table. There is a relation with the RecId in this table. Note that also CompanyInfo is a global table.

  • Community Member Profile Picture
    on at

    Hi, sorting is not required.

    You can see here that the Employment is shown by LE.

    I want to replicate this from code.

    ax_5F00_emp1.JPG

    here is can see the Contractor has one employment in A102.

    it is this relationship with A102 i am trying to retrieve along with the FD values.

    Problem is the A102 value..

    hope this clarifies, thank you.

  • Community Member Profile Picture
    on at

    Thanks both for your input.

    I have recoded as follows and I have achieved the result i expect.

    Many thanks to ye.

    while select w
    join hcmEmployment where w.RecId == hcmEmployment.Worker
    join ci where hcmEmployment.LegalEntity == ci.RecId
    join setItem where hcmEmployment.DefaultDimension == setItem.DimensionAttributeValueSet
    join dimAttrValue
    where dimAttrValue.RecId == setItem.DimensionAttributeValue &&
    dimAttrValue.DimensionAttribute == dimAttribute.RecId &&
    dimAttrValue.IsDeleted == false
    {
    //hcmEmp = HcmEmployment::findByWorkerLegalEntity(HcmWorker::find(hcmEmployment.Worker).RecId,hcmEmployment.LegalEntity);


    info(strFmt("Employee = %1 %2 = %3 %4 %5 %6 %7",
    //HcmWorker::find(hcmEmployment.Worker).PersonnelNumber
    w.PersonnelNumber
    ,dimAttribute.Name
    ,setItem.DisplayValue
    //,CompanyInfo::findDataArea(hcmEmployment.dataAreaId).company()
    ,ci.NameAlias
    ,ci.DataArea
    //,ci.dataAreaId //return DAT
    ));

  • Community Member Profile Picture
    on at

    Is there any location where i can discover the relations between AX Objects? EG: hcmEmployment.LegalEntity == ci.RecId

  • André Arnaud de Calavon Profile Picture
    303,775 Super User 2026 Season 1 on at

    Hi,

    In the AOT you can view relations per table. There you are able to find the relation between tables.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans