Microsoft_MVP_banner

Dynamics AX and database synchronization error

Due to huge customization in application we may come across database and application synchronization failure issue. Sometimes you will see this error when you add some new fields in CustTable or SalesTable, this is just for an example you can have this issue in any table or view. Following job will forcefully synchronize all the tables in AOT. static void forceDbSynchronize(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();     }     info(‘Sychrnonization is now done.’); }

Delete duplicate records from table

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, I used Dimension table as an example; static void deleteduplicate(Args _args) {     set fieldSet = new set(Types::Integer);     // create dicindex from the unique index     DictIndex dictIndex = new Dictindex(tablenum(Dimensions),indexnum(dimensions, DimensionIdx));     ;     // these are the fields from the index     // add them to a set     fieldset.add(fieldnum(Dimensions, DimensionCode));     fieldset.add(fieldnum(Dimensions, Num));     // set allow duplicates     ReleaseUpdateDB::indexAllowDup(dictIndex);     // delete duplicate records     ReleaseUpdateDB::deleteDuplicatesUsingIds(tablenum(Dimensions), 1, fieldset);     // re-enable index     ReleaseUpdateDB::indexAllowNoDup(dictIndex);     info(‘Done’); }  

Format the system date in Dynamics AX

The following code show the dates in format like December 22, 2011 static void datesJob(Args _args) {     str dd, mm, yy, dt;     dt = date2Str(systemDateGet(), 123, DateDay::Digits2, DateSeparator::Slash, DateMonth::Digits2,            DateSeparator::Slash, DateYear::Digits4);     dd = substr(dt, 0, 2);     mm = substr(dt, 4, 2);     yy = substr(dt, 7, 4);     dt = mthname(str2int(mm)) + ‘ ‘ + dd + ‘, ‘ + yy;     print   dt;     pause; }

FaisalFareed@2025. All rights reserved

Design by T3chDesigns