Thursday, March 9, 2023

D365 Retain record position on grid refresh

Microsoft Dynamics 365 Finance
When refreshing the datasource of a grid, a common requirement is to retain the position of the selected record.
The datasource function refresh(true) was supposed to handle this, but does not always work. Also getPosition() and setPosition() will not provide this functionality.

One way to solve it is to use findRecord(Common _record). For this to work you will need to fetch the record from the database, as simply using the cursor() record will not suffice.

  MyTable myTableCursor = MyTable_ds.cursor();
  MyTable myTableLocal = MyTable::findRecId(myTableCursor.RecId);
  MyTable_ds.executeQuery();
  if(myTableLocal)
  {
  	MyTable_ds.findRecord(myTableLocal);
  }

No comments:

Post a Comment