Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Class Hcmworkerlookup sort

Posted on by 1,531

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

  • Ganriver1 Profile Picture
    Ganriver1 1,531 on at
    RE: Class Hcmworkerlookup sort

    Hi Nikolaos,

    I did my testing, problem is with the joined 'UserGrouplist' table in HCMWorkerLookup query, if I removed it, it works fine, added it back, the sorting changed to personnel number.

    We want it filter by a user group, which is hard coded in query. Any ideal/suggestion? I don't see any setting I can play with.

    It's really weird.

    3247.Capture.PNG

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Class Hcmworkerlookup sort

    Is there some code involved in calling the lookup? Do you use a reference group? What are its settings? Any other details that might help someone to try what you did and possibly find answer to your question?

    Since we know the lookup form itself filters by name when opened from AOT, we know that the issue is somewhere in the caller. That's why I'm trying to milk information about it. It would be easiest if you shared all details at once.

  • Ganriver1 Profile Picture
    Ganriver1 1,531 on at
    RE: Class Hcmworkerlookup sort

    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.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Class Hcmworkerlookup sort

    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
    Ganriver1 1,531 on at
    RE: Class Hcmworkerlookup sort

    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
    nmaenpaa 101,156 on at
    RE: Class Hcmworkerlookup sort

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

  • Ganriver1 Profile Picture
    Ganriver1 1,531 on at
    RE: Class Hcmworkerlookup sort

    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
    nmaenpaa 101,156 on at
    RE: Class Hcmworkerlookup sort

    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
    Ganriver1 1,531 on at
    RE: Class Hcmworkerlookup sort

    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

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Class Hcmworkerlookup sort

    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?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans