HI
In X++ - Dynamics 365 for Finance and Operations 💚
**Updated Problem Description with Item Number:**
I'm working on Dynamics 365 for Finance and Operations. I added two custom fields (NetWeight and GrossWeight) to the SalesQuotationLine table and corresponding columns in the All quotations form. When selecting an ItemId (e.g., item number 1000) in a quotation line, I need to read weight values from the product card (InventTable) and display them in the new columns.
**The Issue:**
When I select item number 1000 in a quotation line using a FormDataFieldEventHandler, the weight values (NetWeight = 235.00) are saved to the database and appear in the columns, but I get an error: "Cannot edit a record in Quotation lines (SalesQuotationLine). The record has never been selected."
**What I've Tried:**
1. Display methods (not being called when selecting item 1000)
2. ModifiedField in table extension (doesn't trigger for item 1000 selection)
3. EventHandler with ds.reread() and ds.refresh() (works for item 1000 but shows error)
4. Used ttsbegin/ttscommit with selectForUpdate(true) and doUpdate() for item 1000
5. Tried update() instead of doUpdate() for item 1000
**Current code works for item 1000 and shows the correct weight values (235.00) but with the "record has never been selected" error. Need solution to remove this error when selecting item 1000.**
The values are completely correct.
Please help me resolve this error.
===========================================================================================
X++ Code :
class SalesQuotationLine_Written
{
[FormDataFieldEventHandler(
formDataFieldStr(SalesQuotationTable, SalesQuotationLine, ItemId),
FormDataFieldEventType::Modified)]
public static void ItemId_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
FormDataSource ds = sender.datasource();
SalesQuotationLine line = ds.cursor();
if (!line.ItemId)
return;
InventTable inventTable = InventTable::find(line.ItemId);
ttsbegin;
line.selectForUpdate(true);
line.NetWeight = inventTable.NetWeight;
line.GrossWeight = inventTable.GrossWeight();
line.doUpdate();
ttscommit;
ds.reread();
ds.refresh();
}
}
===========================================================================================