Deleting duplicate Record from Table – Ax2012
Sometimes we lost unique identity check in the tables while doing some customization in Dynamics AX. It may happen due to failure of database synchronization.
Here is the code to remove the duplicate records from a table.
static void RemoveDuplicates(Args _args)
{
Set fieldSet = new set(Types::Integer);
DictIndex dictIndex = new DictIndex(
tablenum(PurchTable),
indexnum(PurchTable,PurchIdx));
int i;
;
if(dictIndex.numberOfFields())
{
for(i=1;i<=dictIndex.numberOfFields();i++)
{
fieldSet.add(dictIndex.field(i));
}
ReleaseUpdateDB::indexAllowDup(dictIndex);
ReleaseUpdateDB::deleteDuplicatesUsingIds(tablenum(PurchTable),0, fieldSet);
ReleaseUpdateDB::indexAllowNoDup(dictIndex);
}
info("Successfully done");
}
Here is the code to remove the duplicate records from a table.
static void RemoveDuplicates(Args _args)
{
Set fieldSet = new set(Types::Integer);
DictIndex dictIndex = new DictIndex(
tablenum(PurchTable),
indexnum(PurchTable,PurchIdx));
int i;
;
if(dictIndex.numberOfFields())
{
for(i=1;i<=dictIndex.numberOfFields();i++)
{
fieldSet.add(dictIndex.field(i));
}
ReleaseUpdateDB::indexAllowDup(dictIndex);
ReleaseUpdateDB::deleteDuplicatesUsingIds(tablenum(PurchTable),0, fieldSet);
ReleaseUpdateDB::indexAllowNoDup(dictIndex);
}
info("Successfully done");
}