Tuesday, August 22, 2017

How to delete Duplicate Records through X++ in Dynamics Ax

static void DupDeleteRecords(Args _args)
{
VendTable       vendTable ;
int                   c1,c2;
Set fieldset = new set(types::Integer);
// create dictindex from unique index
DictIndex dictIndex = new dictIndex (tablenum(VendTable  ), indexnum(VendTable  ,AccountNumIdx));
;
select count(RecId) from vendTable  ;
c1=vendTable .RecId;
// these are fields from index add them to set
fieldset.add(fieldnum(VendTable  ,AccountNum));

ReleaseUpdateDB::indexAllowDup(dictIndex);
// set allow duplicates
ReleaseUpdateDB::deleteDuplicatesUsingIds(tablenum(VendTable  ),0,fieldset);
//re enable duplicates
ReleaseUpdateDB::indexAllowDup(dictIndex);
select count(RecId) from vendTable ;
c2=vendTable .RecId;
if(c1!=c2)
info(“Duplicate Deletion done”);
else
info(“No Duplicates found”);
}
force DB Synchronize :

static void forceDbSynchronize1(Args _args)
{
Dictionary dict;
int idx, lastIdx, totalTables;
TableId tableId;
Application application;
SysOperationProgress progress;
StackBase errorStack;
ErrorTxt errorTxt;
;
application = new Application();
dict = new Dictionary();
totalTables = dict.tableCnt();
progress = new SysOperationProgress();
progress.setTotal(totalTables);
progress.setCaption(“@SYS90206″);
errorStack = new StackBase(Types::String);
lastIdx = 0;
try
{
for (idx = lastIdx+1; idx <= totalTables; idx++)
{
tableId = dict.tableCnt2Id(idx);
progress.setText(dict.tableName(tableId));
lastIdx = idx;
application.dbSynchronize(tableId, false, true, false);
progress.incCount();
}
}
catch (Exception::Error)
{
errorTxt = strFmt("Error in table '%1' (%2)", tableId, dict.tableName(tableId));
errorStack.push(errorTxt);
retry;
}
setPrefix("@SYS86407");
errorTxt = errorStack.pop();
while (errorTxt)
{
error(errorTxt);
errorTxt = errorStack.pop();
}
}

Enable/Disable form control based on multiple rows select

 class PurchTableFormEventHandler {      [FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchTable), FormDataSourceEventType::Act...