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)

Class Hcmworkerlookup sort

(0) ShareShare
ReportReport
Posted on by 1,559

Hi Friends,

The default sorting on the worker lookup form is by personnel id, I want to change it to sorting by worker's first, last name within this HcmWorkLookup class, name is from Dirperson, how can I add sorting to query?

Many thanks,

River

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Looking at the new() method of the class, we can see that it's using an AOT query called HcmWorkerLookup.

    That query already has a sort field on DirPerson.Name so I would expect that to be used by default (in AX2012 R3 CU13).

    You don't give more specifics on your scenario, but perhaps the code that calls this lookup adds their own sort field? You need to check that. Or maybe in your AX version (what is it) the AOT query has a different sorting setup.

  • Ganriver1 Profile Picture
    1,559 on at

    Hi Nikolaso,

    Yes, the query has the sorting of dirPerson.Name, but, it's not working as it should be, or something is missing.  We are on AX 2012.  We don't have specifics change on this one.

    BTW, if you double click on the column name in grid, it will sort by 'Name'. But, we want it to be default.

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    The HcmWorkerLookup query sorts by name. You can easily try this by running the query in a job.

    So like I said, maybe in your scenario the code that calls this lookup adds their own sorting field. But it's impossible to know without having more details on your scenario.

    So, can you share some more details? Where do you see the lookup sort on Personnel number?

  • Ganriver1 Profile Picture
    1,559 on at

    you are right, I open the form alone, it's sorted by name.

    What we changed is the query, by joining 'UserGrouplist' table, so we can filter it based on group, nothing else changed. Even it's sort by same thing Dirperson.name, but some how it's not working.

    5488.Capture.PNG

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Since you say the form sorts correctly for you, too, we clearly see that the problem is not in the query definition or the form.

    But somewhere along the way something changes the sorting. Feel free to share the details that I asked if you feel you still need advice.

  • Ganriver1 Profile Picture
    1,559 on at

    Hi Nikolaos,

    As I showed you the screenshot before, all new changes we added is joining a new table within the query, then, in the lookup form, we use this new query.

    Any idea how to debug this to find out where could be the problem?

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Yes. That's why I asked where you are using the lookup. I'm still waiting for your answer.

  • Ganriver1 Profile Picture
    1,559 on at

    Hi Nikolaos,

    Here is the changed code part in red within updateQuery method in class HCMWorkerLookup, and screen shot of result, nothing else changed.

    Query 'MyHcmWorkerLookup' is the one I showed in previous screen shot, we joined a table to filter result.

    public Query updateQuery(HcmWorkerRecId _workerRecId = 0)
    {
        QueryBuildRange         legalEntityRange;
        QueryBuildRange         validFromRange;
        QueryBuildRange         validToRange;
        QueryBuildRange         workerRange;
        QueryBuildRange         employmentValidFromRange;
        QueryBuildRange         employmentValidToRange;
        QueryBuildRange         employmentTypeRange;
        QueryBuildDataSource    qbdsEmployment;
        QueryBuildDataSource    qbdsDirPersonUser;
        QueryBuildDataSource    qbdsActiveEmployments;
        QueryBuildDataSource    qbdsWorker;
        utcdatetime             now = DateTimeUtil::utcNow();
    
        // My change >
        if(Mycondition)
        {
            query = new Query(queryStr(MyHcmWorkerLookup));
        }
        // my change >
    
        qbdsWorker              = query.dataSourceTable(tableNum(HcmWorker));
        qbdsEmployment          = query.dataSourceName('HcmEmployment');
        qbdsActiveEmployments   = query.dataSourceName('ActiveEmployments');
        qbdsDirPersonUser       = query.dataSourceTable(tableNum(DirPersonUser));
    
        validFromRange          = qbdsEmployment.findRange(fieldNum(HcmEmployment, ValidFrom));
        validToRange            = qbdsEmployment.findRange(fieldNum(HcmEmployment, ValidTo));
        legalEntityRange        = qbdsEmployment.findRange(fieldNum(HcmEmployment, LegalEntity));
        employmentTypeRange     = qbdsEmployment.findRange(fieldNum(HcmEmployment, EmploymentType));
        workerRange             = qbdsEmployment.findRange(fieldNum(HcmEmployment, Worker));
    
        employmentValidFromRange    = qbdsActiveEmployments.findRange(fieldNum(HcmEmployment, ValidFrom));
        employmentValidToRange      = qbdsActiveEmployments.findRange(fieldNum(HcmEmployment, ValidTo));

      ...............

    Please let me know what else you want to know.

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    I can't see the screenshot.

    I still would like to know from where this lookup is called. Standard form? Your own form? I feel you share only part of your process and therefore it's hard to troubleshoot.

  • Ganriver1 Profile Picture
    1,559 on at

    2185.Capture.PNG

    Here is screen shot, it's reference field to HCMWorker from our customized AP invoice form, please ignore the worker's name.

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