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

2

5

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.

Emigration answered 19/10, 2015 at 20:25 Comment(0)
E
5

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.

Eddo answered 20/10, 2015 at 7:14 Comment(1)
The whole multi-select in AX12 seems like a half-baked idea to me. When multiple ones are selected, depending on what you click last, will determine the link that is made. The use case is for a configuration table, so performance shouldn't be an issue. I was hoping it was native is some fashion.Emigration
D
2

Active record is only one and join is done with this record. You will have to write some code. You need to add range on child datasource based on parent datasource selection.

Derail answered 20/10, 2015 at 5:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.