Search code examples
formsaxaptax++dynamics-ax-2012records

How to show rows-records between two tab form?


In my Form, I have Two TabPages, with the same DataSource for each.

In TabPageA I have all records from my DataSource. I select records in TabPageA and I want to only show, in TabPageB, those records I selected previously in TabPageA.

If I don't select anything in TabPageA I don't see anything in TabPageB

My form body

For example if in my GridA I selected Record#4 , in GridB I see only Record#4.


Solution

  • I don't think you'll be able to filter TabPageB differently from TabPageA easily due to the fact they share the same DataSource.

    There are two quick ways to modify this.

    Keep it as one DataSource: Create a global QueryBuildRange to easily update the range on selected records.

    public class FormRun extends ObjectRun
    
        {
            QueryBuildRange qbr;
        }
    

    Override the init of your datasource. Here you will set the qbr:

    public void init()
    {
        super();
        qbr = this.queryBuildDataSource().addRange(fieldNum(SalesTable, RecId));
    }
    

    Then override the pageActivated TabPage method for each to set the range and re-execute the query to your liking:

    TabPageA:

    public void pageActivated()
    {
        super();
    
        qbr.value('');
    
        SalesTable_ds.executeQuery();
    }
    

    TabPageB

    public void pageActivated()
    {
        super();
    
        element.createRange();
    
        SalesTable_ds.executeQuery();
    }
    

    Method to update range:

    public void createRange()
    {
        MultiSelectionHelper    multiSelectionHelper = MultiSelectionHelper::createFromCaller(this);
        common                  common;
        Set                     set = new Set(Types::Int64);
    
        // Necessary if the datasource you want is not the header datasource.
        multiSelectionHelper.parmDatasource(SalesTable_ds);
    
        common = multiSelectionHelper.getFirst();
    
        while (common)
        {
            // Use of set not necessary, but a little cleaner.
            set.add(common.RecId);
    
            common = MultiSelectionHelper.getNext();
        }
    
        qbr.value(strRem(set.toString(), '"{}'));
    }
    

    This is somewhat dirty, but you get the idea and could clean it up as needed.

    Two Datasources: Update the range on the second datasource (used by TabPageB) based on the multi-selection of the first datasource. But I'm assuming you only want one datasource for some reason.