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)

sort a grid so that the data is sorted on the form if called from different forms

(0) ShareShare
ReportReport
Posted on by 206

Hi all,

Suppose we have a table TableA that contains 3 fields A,B and C. This is added to the form Form A which is called from 2 different forms FormX and FormY . The requirement is :

1. If formA is called from FormX the sort order should be C,B then A.

2. If formA is called from FormY the sort order should be A,B then C.

How can this be achieved ? 

*This post is locked for comments

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

    You can get the caller form name using element.args().caller().name() in init method of your form A.

    Then, in the init method of the data source of form A you can set sorting of the data source according to the caller.

  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    Also, consider using an enum parameter on menu items instead of form names. This will allow you (and anybody extending your solution) to reuse the same logic from other places. Also, you won't have to change FormA if you rename FormX or FormY.

  • Suggested answer
    BrandonSA Profile Picture
    1,673 on at

    Hi

    From form X and form Y, call form A like this (or call it from a normal menu Item and set the enum parameter values in the same way):

    FormRun formRun;
    Args args = new Args();
    
    args.name(formstr(FormA));
    args.parmEnumType(enumNum(MySortingEnum));
    args.parmEnum(MySortingEnum::SortABC);
    formRun = ClassFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    In form A, create a variable in the class declaration called sortingEnum, or something like that - MySortingEnum sortingEnum;
    In the init() method of the form, add this code to pull get the enum value from the sent arguments
    sortinEnum = element.args().parmEnum();
    In the init() method of the datasource you want to sort, after the super() call, add the code:
    switch (sortingEnum)
    {
        case MySortingEnum::sortABC:
             this.queryBuildDataSource().addSortField(fieldNum(FormADS, A)); 
             this.queryBuildDataSource().addSortField(fieldNum(FormADS, B));
             this.queryBuildDataSource().addSortField(fieldNum(FormADS, C));
        case MySortingEnum::sortCBA:
             this.queryBuildDataSource().addSortField(fieldNum(FormADS, C)); 
             this.queryBuildDataSource().addSortField(fieldNum(FormADS, B));
             this.queryBuildDataSource().addSortField(fieldNum(FormADS, A));
    }
    That should do it. You can obviously neaten/optomise the code up that I've added here.
    Tx
  • Suggested answer
    startax Profile Picture
    1,845 on at

    Check caller in form Init() using

    objects   objectCaller  = args.caller()

    based on caller you can write your sort condition.

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