How to Delete duplicate records using X++
static void DeleteDuplicateValues(Args _args)
{
Set fieldset = new set(types::Integer);
// create dictindex from unique index
DictIndex dictIndex = new dictIndex (tablenum(PurchTable), indexnum(PurchTable,PurchIdx));
;
// these are fields from index
// add them to set
fieldset.add(fieldnum(PurchTable ,OrderAccount));
//Can add multiple fields also
//fieldset.add();
//Note the index should Not be primary index it alternake key should be no
ReleaseUpdateDB::indexAllowDup(dictIndex);
// set allow duplicates
ReleaseUpdateDB::deleteDuplicatesUsingIds(tablenum(PurchTable),0,fieldset);
//reenable duplicates
ReleaseUpdateDB::indexAllowNoDup(dictIndex);
//Can also handle timestatekey index
//by ReleaseUpdateDB::indexAllowNoDupAndDateEffective(dictIndex,ValidTimeStateMode::NoGap);
info("Deletion done");
}
No comments:
Post a Comment