I was trying to change parent in a detail (child) row in a master-detail screen. The parent could be changed by a dropdown field in the child row.
I was expecting the child row to be changed and then it disappeared after saving the form.
Instead I’ve got the following error: Server error occurred. Please check server log for more details:
ForeignKeyConstraint FK_LogisticsRouteSchedule requires the child key values (xxxxx) to exist in the parent table.
Fix to this problem is some what complicated. The exception is thrown here:
The problem is that the row’s dataset only contains the original parent row but not the new one.
Solution one:
add row.Table.DataSet.EnforceConstraints = false; before the line 1747 does fix the problem but it does not look like something we want to do.
Solution two:
load the missing row into the dataset. This would contradict the idea behind the lazy loaded screen. So probably not a good idea either.
This issue will be on hold until we can consult @tvavrda.
From my point of view, I don’t see any problem to load the other master record, since it’s needed. It’s the point of lazy-loading - load it when it’s needed, isn’t it?. So I would go with solution 2.
The current implementation works with only one master record in memory.
Implementing support for loading second master record doesn’t seem to be a matter of simple adjustment of the current code and could have an impact on other things.
This would be too much for such a specific use case. I would solve it by an action button that would offer a dialog for choosing another parent record and then load/update/save workflow to save it directly in the db. Then set the action button to RefreshAfterReturn: ReloadActualRecord so the updated record would disappear from the current screen.