[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Writing)]
public static void SalesLine_OnWriting(FormDataSource _sender, FormDataSourceEventArgs _e)
{
SalesTable salesTable = _sender.formRun().dataSource(formDataSourceStr(SalesTable, SalesTable)).cursor();
SalesLine salesLine = _sender.cursor();
if (salesLine.DeliveryPostalAddress != salesTable.DeliveryPostalAddress)
{
ttsbegin;
salesLine.selectForUpdate(true);
salesLine.DeliveryPostalAddress = salesTable.DeliveryPostalAddress;
salesLine.update();
ttscommit;
}
}
Our users have been getting an error, "Cannot edit a record in Order lines (SalesLine). The record shown has been updated by another user." Through debugging, I have narrowed the error down to be coming from the event handler shown above. Is there any potential data loss that could happen if I refresh the datasource just before the ttsbegin?
[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Writing)]
public static void SalesLine_OnWriting(FormDataSource _sender, FormDataSourceEventArgs _e)
{
SalesTable salesTable = _sender.formRun().dataSource(formDataSourceStr(SalesTable, SalesTable)).cursor();
SalesLine salesLine = _sender.cursor();
if (salesLine.DeliveryPostalAddress != salesTable.DeliveryPostalAddress)
{
salesLine.reread(); //could this potentially overwrite data in the cursor?
ttsbegin;
salesLine.selectForUpdate(true);
salesLine.DeliveryPostalAddress = salesTable.DeliveryPostalAddress;
salesLine.update();
ttscommit;
}
}
If I change the code as above then I no longer get the error. Something in the back of my head tells me that this approach could be dangerous. Looking for some insight from the experts.