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 :
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
    299,024 Super User 2025 Season 2 on at
    RE: Retrieve legal entity from employment from worker

    Hi,

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

  • Community Member Profile Picture
    on at
    RE: Retrieve legal entity from employment from worker

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

  • Community Member Profile Picture
    on at
    RE: Retrieve legal entity from employment from worker

    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
    RE: Retrieve legal entity from employment from worker

    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.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    299,024 Super User 2025 Season 2 on at
    RE: Retrieve legal entity from employment from worker

    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.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Retrieve legal entity from employment from worker

    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

  • Community Member Profile Picture
    on at
    RE: Retrieve legal entity from employment from worker

    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,

  • Community Member Profile Picture
    on at
    RE: Retrieve legal entity from employment from worker

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

  • André Arnaud de Calavon Profile Picture
    299,024 Super User 2025 Season 2 on at
    RE: Retrieve legal entity from employment from worker

    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.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans