Recently, I had a requirement to show multiple selected records from Item master form to a new form, when a button is clicked on the Item master form. I wrote all the necessary code using MultiSelectionHelper class in X++ and applied the range on form’s datasource, but it was showing only one selected record on the new form instead of all the selected records. After wasting lot of time on this, I was finally able to figured out the solution which I want to share. The problem was that due to the dynalink created between the InventTable and the datasource on my new form, it was preventing all the selected records to be shown and only one record was showing on my new form. So, the solution is to clear the dynalinks on the datasource before applying the ranges. Below is the code I wrote in the datasource’s init method on my new form which is called from Item master form:

public void init()
{
MultiSelectionHelper multiSelectionHelper;
InventTable inventTableLocal;

QueryBuildDataSource qbds;

str selectedProducts;

super();

if (element.args().caller() &&
element.args().record())
{
multiSelectionHelper = MultiSelectionHelper::construct();
multiSelectionHelper.parmDatasource(element.args().record().dataSource());

inventTableLocal = multiSelectionHelper.getFirst();

while (inventTableLocal.RecId != 0 &&
EcoResProduct::find(inventTableLocal.Product).productSubtype() == EcoResProductSubtype::ProductMaster)
{
selectedProducts = queryRangeConcat(selectedProducts, inventTableLocal.ItemId);

inventTableLocal = multiSelectionHelper.getNext();
}

ecoResProductMaster_ds.query().dataSourceTable(tableNum(EcoResProductMaster)).clearDynalinks();

ecoResProductMaster_ds.query().literals(true);
ecoResProductMaster_ds.query().dataSourceTable(tableNum(EcoResProductMaster)).
addRange(fieldNum(EcoResProductMaster, DisplayProductNumber)).value(selectedProducts);
}
}