axaptadynamics-ax-2012x++dynamics-ax-2012-r2

How to do multi-select so that multiple selections on a parent datasource will display combined child datasource


I'll be using SalesTable/SalesLine for the sake of this discussion.

I have a simple form with two DataSources, SalesTable and SalesLine, with SalesLine joined to SalesTable. There is a header and lines grid. The header grid has property MultiSelect = Yes

When I select 3 SalesTable records from the grid, is there a way to make it display all of the SalesLine records in the lower grid from the three selected SalesTable records in some native style?

I know I can accomplish this through some code in some way or another, but I would think this can be accomplished through form and DataSource properties somehow through a design pattern? It does not make sense to me that you could select/highlight three header records, and AX will just make the lines-grid display only one of the header:child line pairs.


Solution

  • You have to code, the standard dynalink behavior does not support this for good reasons.

    Beware that nonstandard form behavior may confuse the user. Also selecting all records in the header table is easy, but will not perform well!

    As usual, set the JoinSource property of the SalesLine datasource to SalesTable (LinkType Delayed) then override the linkActive method of the SalesLine datasource:

    public void linkActive()
    {
        SalesTable table;
        QueryBuildDataSource ds = this.query().dataSourceNo(1);
        ds.clearDynalinks();
        ds.clearRanges();
        for (table = salesTable_ds.getFirst(1) ? salesTable_ds.getFirst(1) : salesTable_ds.cursor(); table; table = salesTable_ds.getNext())
        {
            ds.addRange(fieldNum(SalesLine,SalesId)).value(queryValue(table.SalesId));
        }
        super();
    }
    

    The dynalink is cleared, and the ranges are added by code for marked or current records.

    If more than a few hundred headers are marked, the SQL expression may overflow. You probably should try to avoid this by throwing a more user-friendly error if too many headers are selected.