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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Unable to select employment details of past workers in the list of workers

(0) ShareShare
ReportReport
Posted on by 10

Hello everyone,

I'm having a problem with getting the employment details of past workers in the current company when I join hcmworker table to hcmEmployment table.

I'm using this job:

static void Job37(Args _args)
{
HcmWOrker hcmWorker;
HcmEmployment hcmEmployment;
DIrPersonName dirPersonName;
CompanyInfo companyInfo;

companyInfo = CompanyInfo::find(companyInfo::current());
info("Company :"+companyInfo.DataArea);
while select * from hcmWOrker order by hcmWOrker.PersonnelNumber
join dirPersonName where hcmWorker.Person==dirPersonName.Person
join hcmEmployment where hcmEmployment.Worker==hcmWorker.RecId
&& hcmEmployment.LegalEntity==companyInfo.RecId
{
info("Number: "+ hcmWorker.PersonnelNumber+" , Name: "+dirPersonName.LastName+" "+dirPersonName.FirstName);
}

}

and this is what I get in output:

0676.Image1.PNG

As you can see, I can have the list of active workers (their numbers start with 020) in the same company (020).

The problem is that I can only get the workers that have a valid effective date due to a property called  ValidTimeStateEnabled that is set to UtcDateTime in the hcmEmployment Table.This property limits the list of workers in terms of validfrom and validto date. I can't set it to None because it will delete all the records.

I need to get all employment details of the active and past workers in the same company.

Any Idea please?? Thank you for help.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    hello,

    there is a form called Past worker. is using the query: HcmWorkerListPage_PastWorkers,

    but this query is using the ValidTo field to filter the data.

    you can check this querys.

    Regards!

  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Hi Maroua Bouhachem,

    You can use validTimeState(dateFrom, dateTo) in select statement to read not active workers, please refer to next msdn article for details msdn.microsoft.com/.../gg843767.aspx

  • Maroua Bouhachem Profile Picture
    10 on at

    Thank you Sir for your response. I've already tried with this query but i'm having the same result. Here's the job i'm using:

    sstatic void Job39(Args _args)

    {

       Query                   query;

       QueryRun                queryRun;

       HcmWorker               hcmWorker;

       QueryBuildDataSource    qbdsWorkerTable;

       ListIterator            workersListIterator;

       List workers;

       workers=new List(Types::Int64);

       workersListIterator = new ListIterator(workers);

       query = new Query(queryStr(HcmWorkerListPage_PastWorkers));

       qbdsWorkerTable = query.dataSourceTable(tableNum(HcmWorker));

       while(workersListIterator.more())

       {

            qbdsWorkerTable.addRange(

            fieldNum(HcmWorker,RecId)).value(workersListIterator.value());

            workersListIterator.next();

       }

       queryRun = new QueryRun(query);

       while(queryRun.next())

       {

           hcmWorker = queryRun.get(tableNum(hcmWorker));

           info(hcmWorker.PersonnelNumber);

       }

    }

    I think that the purpose of using this query is to have directly the list of past workers in the same company. Unfortunately, what I really get as a result of this query is the list of active and past employees from different companies. Am I missing something?

  • Maroua Bouhachem Profile Picture
    10 on at

    Thank you so much. It worked perfectly for me!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans