Deleting duplicate records in Ax 2012 Table through code in X++

static void DupDeleteTest(Args _args)
{
Bill_TabMethod_1 btm1;
int c1,c2;
Set fieldset = new set(types::Integer);

// create dictindex from unique index

DictIndex dictIndex = new dictIndex (tablenum(Bill_TabMethod_1), indexnum(Bill_TabMethod_1,CustIdx));

;

select count(RecId) from btm1;c1=btm1.RecId;

// these are fields from index
// add them to set

fieldset.add(fieldnum(Bill_TabMethod_1 ,CustName));
fieldset.add(fieldNum(Bill_TabMethod_1,ItemName));

ReleaseUpdateDB::indexAllowDup(dictIndex);

// set allow duplicates

ReleaseUpdateDB::deleteDuplicatesUsingIds(tablenum(Bill_TabMethod_1),0,fieldset);

//re enable duplicates

ReleaseUpdateDB::indexAllowDup(dictIndex);

select count(RecId) from btm1;c2=btm1.RecId;

if(c1!=c2)
info(“Duplicate Deletion done”);
else
info(“No Duplicates found”);

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s