AX / D365FO – Check if records of 2 different Tables with same or similar structure are changed

I have two tables tha are identical (Different names but same fields). The second table is the exact copy of the first

When a record in the first table is modified I want the record in the second table to also be modified.

To know if the record has been changed I should check every column values in the first table and check that they correspond to those in the second. If even just one is different it means the record has been modified.

To do the comparison you can use this mehod.

static boolean checkRecordsAreIdentical(Common  _from, Common  _to)

{
DictTable dictTableFrom = new DictTable(_from.TableId);
DictTable dictTableTo = new DictTable(_to.TableId);
DictField dictFieldFrom;
FieldId fieldIdFrom = dictTableFrom.fieldNext(0);
FieldId fieldIdTo;

while (fieldIdFrom && ! isSysId(fieldIdFrom))
{
dictFieldFrom = new DictField(_from.TableId, fieldIdFrom);

if(dictFieldFrom)
{
fieldIdTo = dictTableTo.fieldName2Id(dictFieldFrom.name());

if(fieldIdTo)
{
if(_to.(fieldIdTo) != _from.(fieldIdFrom))
{
return false;
}
}
}
fieldIdFrom = dictTableFrom.fieldNext(fieldIdFrom);
}

return true;
}

and here an example on how to use it

//Check if records are different

boolean identical = DLX_Utility::checkRecordsAreIdentical(TableBuffer1, TableBuffer2);

if(identical)
{
  info('records are identical')
}

Leave a comment