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 :
Finance | Project Operations, Human Resources, ...
Answered

Active worker through x++

(0) ShareShare
ReportReport
Posted on by 1,215

Hi all,

I want to get active worker in job.

I found in HcmWorkerLookup::newActiveWorkers(); and i have a 25 active worker.

Could you please give me some example how to show active worker in job info ?

Thanks   

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,109 Super User 2025 Season 2 on at

    Hi Riyas,

    Can you elaborate? Your question is not clear. What is the business requirement you try to solve?

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your reply sir,

    I want to show active worker in job. So that how to do in X++? How can I show active worker only in the info message?

    Can you give me some example for that.?

    Thanks for your attention.

  • André Arnaud de Calavon Profile Picture
    301,109 Super User 2025 Season 2 on at

    Hi Riyas,

    What exact "job" are you talking about? Do you need one worker or all active workers? What is the info message about?

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your replay sir,

    The job I want to get only active workers. not one worker.

    I found it its 25 records in active records and there is used HcmWorkerLookup::newActiveWorkers() method.

    Now, the thing is that 25 record how to get and show info message in the job sir.?

    I hope its clear.

  • Riyas ahamed F Profile Picture
    1,215 on at

    Can you help me this sir,  still i have a doubt.

    Are you understood what I'm trying to say. ? if no, please tell me sir i will explain deeply.

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    You can find active workers using the HcmWorker and HcmEmployment tables

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your replay ergun sir,

    In my custom form used worker lookup reference method.

    Private HcmWorkerLookup workerLookup;
     
    public void init()
    {
        super();
        workerLookup = HcmWorkerLookup::newCustomOptions(true, true, true, false, false, false, false, true, false);
    }
     
    *******Worker field dataSource lookup reference method***********
     public Common lookupReference(FormReferenceControl _formReferenceControl)
    {
        return workerLookup.lookupWorkerTeam(_formReferenceControl);
    }

    As i mentioned above code its show in UI 26 worker no and name.

    The same process how can i show in job ? give me some example for that sir.

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    I don't know why you are stuck with HcmWorkerLookup, but if you want to solve it like there, you can examine the HcmWorkerLookup query and the updateQuery method of the HcmWorkerLookup class.

    Or you can simply look at the isActive method of HcmEmployment

    public static boolean isActive(HcmEmploymentRecId _recId)
    {
        HcmEmployment hcmEmployment;
        utcdatetime now = DateTimeUtil::utcNow();
    
        return _recId && (select ValidTimeState(now) RecId from hcmEmployment
                    where hcmEmployment.RecId == _recId).RecId!= 0;
    }

    If you discard the while condition and join the worker table, it will give you active workers.

    HcmEmployment hcmEmployment;
    utcdatetime now = DateTimeUtil::utcNow();
    HcmWorker worker;
    
    while select ValidTimeState(now) hcmEmployment
    join worker
    where worker.RecId == hcmEmployment.Worker
    {
    //..info etc.
    }

    Note:I wrote the code in the editor, changes may be needed.

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your valuable suggestion.

    Sir I tried in your code  its show in the info msg 500 workers. total i have 938.

    Sorry i think the thing is not active worker related I misled you.

    Its my bad. because what I thought its active worker  

    Now, as i mentioned above lookup in UI its show 26 worker number and name. how ?

    My goal that 26 workers only. let me know sir how it show ? do you have a any idea ?

    Please forgive my ignorance and thank you so much for the time you are taking to help.

  • ergun sahin Profile Picture
    8,826 Moderator on at

    You can add LegalEntity and EmploymentType fields

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans