Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Sort Field in Lookup Control

(0) ShareShare
ReportReport
Posted on by 97

Hi All,

These objects are fully customized not standard,

Initially the lookup sort out based on Rating scale,

Requirement is to change sort based on Rating,

 

I tried using custom code , but first time when we click on lookup its coming properly,

After selecting any value and again click on lookup, its showing sorting based on rating scale

 

pastedimage1684319099057v1.jpeg

 

pastedimage1684319099061v2.jpeg

 

 

 [FormControlEventHandler(formControlStr(LTPMSJournalDetailsYrEnd, BusinessProcesses_SelfAppraisalRating), FormControlEventType::Lookup)]
    public static void BusinessProcesses_SelfAppraisalRating_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        Query query = new Query();
        QueryBuildDataSource queryBuildDataSource;
        QueryBuildRange queryBuildRange;
        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(LTRatingMasterCompetency), sender);
        queryBuildDataSource = query.addDataSource(tableNum(LTRatingMasterCompetency));
        //
       // queryBuildDataSource.clearSortIndex();
       // queryBuildDataSource.sortClear();
        queryBuildDataSource.addSortField(fieldnum(LTRatingMasterCompetency,Rating),sortOrder::Ascending);
       // queryBuildDataSource.removeOrderByField(fieldnum(LTRatingMasterCompetency, RatingScale));
       // queryBuildDataSource.applyFilter(fieldnum(LTRatingMasterCompetency,Rating));

        sysTableLookup.addLookupField(fieldNum(LTRatingMasterCompetency, RatingScale));
        sysTableLookup.addLookupField(fieldNum(LTRatingMasterCompetency, Rating));

        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
        FormControlCancelableSuperEventArgs cancelableSuperEventArgs = e as FormControlCancelableSuperEventArgs;
        cancelableSuperEventArgs.CancelSuperCall();
    }

 The base table for this lookup is RatingTable.

In that table also i changed the clusterIndex property as based on rating index.


What i need to do to fix this issue, kindly advise me, thanks in advance.

  • Suggested answer
    PJ JohnPaul Profile Picture
    PJ JohnPaul 97 on at
    RE: Sort Field in Lookup Control

    Thanks Girish for your suggestion, i created one tmp table and inserted value in tmp table whenever lookup control cliked and added tmp table in syslookup now its working fine.

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Sort Field in Lookup Control

    Sorry, this is final workaround you have.

    So, the reason may be as soon as you type in some value in the lookup field - sort order added will get cleared and order gets changes based on the entered data.

    I don't think there is no fix available as you have tried some suggestions as mentioned.

    Thanks,

    Girish S.

  • PJ JohnPaul Profile Picture
    PJ JohnPaul 97 on at
    RE: Sort Field in Lookup Control

    Hi Girish,

    I tried as you mentioned, now the number(rating - ex: 4) like that its getting inserted in the control after that if i click again the lookup its sort based on rating scale , same issue.

    Thanks

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Sort Field in Lookup Control

    I think this is because there is a value given in the rating scale field. It gets filtered based on the rating scale field, and it omits sort order added in the rating field.

    Try adding the Rating as a first field in the lookup field and check. If the Rating field as added first check if it works in that case.

    sysTableLookup.addLookupField(fieldNum(LTRatingMasterCompetency, Rating));
    sysTableLookup.addLookupField(fieldNum(LTRatingMasterCompetency, RatingScale));

    Thanks,

    Girish S.

  • PJ JohnPaul Profile Picture
    PJ JohnPaul 97 on at
    RE: Sort Field in Lookup Control

    Hi Girish,

    Thanks for your reply , using query and views also its not working facing same issue.

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Sort Field in Lookup Control

    Hi Pj John,

    Try creating query and set the order by field on the query for Rating field - Create a view from the query and use that view in the lookup instead of custom tables.

    Thanks,

    Girish S.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans