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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

All companies all workers

(0) ShareShare
ReportReport
Posted on by 351

Hi,

I want to get all worker and all companies so that i can't able current company and all companies.

Below my code.

while select  hcmEmployment
            where (hcmEmployment.LegalEntity != CompanyInfo::find().RecId
            && hcmEmployment.LegalEntity == CompanyInfo::current())
            outer join hcmWorker where hcmWorker.RecId == hcmEmployment.Worker
           
        {
           
                Info(strFmt("%1", CompanyInfo::getDataArea(hcmEmployment.LegalEntity), hcmWorker.PersonnelNumber));
           
        }

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    306,659 Super User 2026 Season 2 on at

    Hi Waytod365,

    Can you elaborate on your actual business requirement? I can't understand what should be the outcome of your select statement.

    What is the current and expected outcome?

    Note that the coding will be better readable if you use the rich formatting and then choose Insert > Code.

  • waytod365 Profile Picture
    351 on at

    Thanks for your reply,

    I want to get all workers all companies.

  • Suggested answer
    Alireza Eshaghzadeh Profile Picture
    15,225 Super User 2026 Season 2 on at

    Hi waytod365,

    All workers can be exported by HcmEmployment table. It has information about the legal entity and date interval that they are active.

    pastedimage1661332017189v1.png

  • Suggested answer
    Martin Dráb Profile Picture
    240,278 Most Valuable Professional on at

    I think you want code like this:

    while select hcmEmployment
    	join hcmWorker
    		where hcmWorker.RecId == hcmEmployment.Worker
    {
    	info(strFmt("%1 - %2", CompanyInfo::getDataArea(hcmEmployment.LegalEntity), hcmWorker.PersonnelNumber));
    }

    Or maybe this:

    while select hcmWorker
    	outer join hcmEmployment
    		where hcmEmployment.Worker == hcmWorker.RecId
    {
    	info(strFmt("%1 - %2", CompanyInfo::getDataArea(hcmEmployment.LegalEntity), hcmWorker.PersonnelNumber));
    }

    By the way, please use Insert > Code (in the rich-formatting view) to paste source code.

  • waytod365 Profile Picture
    351 on at

    Thanks for your reply sir,

    Yes, i tried but both code only show USMF company related worker.

    I want to see all company legal entity and all workers. How can I get this?

  • waytod365 Profile Picture
    351 on at

    I want like :-

    Employment.legalEntity != CompanyInfo::find().recid and companyInfo:: current (). How can I check both?

  • Martin Dráb Profile Picture
    240,278 Most Valuable Professional on at

    There is nothing more to do. Both HcmWorker and HcmEmployment are shared tables and therefore the query returns data from all companies of the current partition.

    I suspect the probem in your assumptions. How did you determine that the user has one more employment in another company valid for current date, which should therefore be returned by this query?

  • Martin Dráb Profile Picture
    240,278 Most Valuable Professional on at

    Your code makes no sense to me. You're trying to get employment from legal entity that is or isn't the current company, which is always true and therefore the result is the same not having any condition at all. Please stop trying to use this useless code.

    Also, you're wrong if you believe that CompanyInfo::find().RecId and CompanyInfo::current() can you give you two different things.

  • André Arnaud de Calavon Profile Picture
    306,659 Super User 2026 Season 2 on at

    Hi Waytod365,

    Actually, I'm lost here. The requirement is "get all workers all companies". In that case, why do you want to add "Employment.legalEntity != CompanyInfo::find().recid and companyInfo:: current ()."? In my thoughts, all workers, all companies should not have any additional "where clauses".

    The code suggestion from Martin looks good to me, unless the requirement is different.

  • waytod365 Profile Picture
    351 on at

    Sorry for the late reply Martin sir,

    My bad i noted.

    Actually what I want to get if the worker belong to two company in this case that worker and legal entity name only i want to get so that need to change above your code ?

    If not please give me some example on this.

    Thanks 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 263 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 257 Super User 2026 Season 2

#3
Subra Profile Picture

Subra 235 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans