I am facing an issue related to saving dynamic column values in a Sales Order scenario.
I have two related screens:
-
First screen
This screen is used to store locations related to a Sales Order.-
The number of locations is dynamic and not fixed per Sales Order.
-
Locations are saved correctly in this screen.
-
-
Second screen
In this screen:-
The previously stored locations are dynamically converted into columns.
-
The rows represent the Sales Order items (lines).
-
Each cell should store the quantity/value of a specific item in a specific location.
-
Problem Description
When saving data from the second screen:
-
The values entered for all rows are incorrectly saved as the same values of the last row only.
-
As a result, in the SQL table, all item lines end up having identical values, matching the last inserted/updated row.
This behavior occurs despite the UI showing different values per row before saving.
I have attached:
-
The screen code used for handling the dynamic columns and saving the data.
-
Screenshots showing:
-
The dynamic locations setup
-
The dynamic grid layout
-
The incorrect data stored in the SQL table
-
Question
What is the correct approach in Dynamics 365 to handle saving data from a grid with dynamic columns, ensuring that each row is saved with its own correct values and not overwritten by the last row?
Any guidance, best practices, or examples would be highly appreciated.
//////////////////////////////////////////////////////
public class GIG_PartialShipmentItems extends FormRun
{
SalesId salesId;
Map locationControlMap;
{
super();
locationControlMap = new Map(Types::String, Types::Class);
}
{
super();
this.fillValues();
}
{
SalesLine salesLine;
GIG_PartialShipmentItemsTmp tmp;
where salesLine.SalesId == salesId
{
tmp.clear();
tmp.SalesId = salesLine.SalesId;
tmp.LineNum = salesLine.LineNum;
tmp.ItemId = salesLine.ItemId;
tmp.ItemName = salesLine.ItemName();
tmp.Qty = salesLine.QtyOrdered;
tmp.RemainingQty = salesLine.RemainSalesPhysical;
tmp.insert();
}
}
{
GIG_PartialShipmentDrivers drivers;
FormRealControl ctrl;
int idx = 1;
where drivers.SalesId == salesId
{
ctrl = ItemsGrid.addControl(
FormControlType::Real,
strFmt("dyn_%1", idx)
);
ctrl.width(80);
ctrl.allowEdit(true);
idx++;
}
}
{
GIG_PartialShipmentItemsTmp tmp;
GIG_PartialShipmentItemQty itemQty;
MapEnumerator mapEnum;
FormRealControl ctrl;
real totalQty;
where tmp.SalesId == salesId
{
mapEnum = locationControlMap.getEnumerator();
{
ctrl = mapEnum.currentValue();
where itemQty.SalesId == tmp.SalesId
&& itemQty.LineNum == tmp.LineNum
&& itemQty.Location == mapEnum.currentKey();
}
}
}
class btnSave
{
public void clicked()
{
super();
GIG_PartialShipmentItemsTmp tmp;
MapEnumerator mapEnum;
FormRealControl ctrl;
FormDataSource tmp_ds = GIG_PartialShipmentItemsTmp_ds;
where itemQty.SalesId == salesId;
tmp_ds.first();
{
mapEnum = locationControlMap.getEnumerator();
{
ctrl = mapEnum.currentValue();
{
itemQty.clear();
itemQty.SalesId = tmp.SalesId;
itemQty.LineNum = tmp.LineNum;
itemQty.Location = mapEnum.currentKey();
itemQty.Qty = ctrl.realValue();
itemQty.insert();
}
}
tmp_ds.next();
}

Report
All responses (
Answers (