Rahul Sharma

Solutions Architect - Microsoft Dynamics AX | Azure

This is a technology blog covering Microsoft Dynamics AX, Microsoft Dynamics CRM, Microsoft Azure, IoT, .Net, SharePoint, SQL Server, SSRS, SSAS, SSIS, Apache Cassandra, MongoDB, and related technologies. Join this blog on facebook {Rahul Sharma}, to start a discussion !!! NOTE: My employer is not responsible for the content published here.

Index | MS Dynamics AX | MS Dynamics CRM
View blog as >> Magazine | Sidebar | Flipcard | Mosaic | Snapshot | Timeslide

Modify Dynamics AX Standard Excel Import to Include - Update existing records - rule

Sometimes we need to import an excel file that contains existing and new records. With standard Dynamics AX 2009 you don't get an option (import rule) where you can specify ONLY import and update existing records. Below are standard AX excel import rules...

To add a rule that says "Update existing records" only.

Modify Enum SysDataExcelImportRule to add a new element for update.

Note: If you noticed I have inserted new Enum element with value 101, which is far away what Microsoft is using. It is a best practice to keep some difference between the enum values, so if Microsoft inserts new standard enum elements later then our custom enum element do not overlap with the standard. It helps when you upgrade your AX system in future. 

Modify Class SysDataImportExcel, method ImportData as stated below. Just add lines having related modification comments.

   1:      switch (importRule)
   2:      {
   3:          //#N by Rahul Sharma on 19Apr2011 for RAH_ExcelImportRule_UpdateOnlyOption
   4:          //added update only option
   5:          case SysDataExcelImportRule::RAHUpdate :
   6:          case SysDataExcelImportRule::InsertAndUpdate :
   7:              selectForUpdate = true;
   9:          case SysDataExcelImportRule::InsertNew :
  10:              updCommon = this.recordExist(_dictTable, _curcommon, selectForUpdate);
  11:              break;
  12:      }

   1:      if (updCommon.RecId)
   2:      {
   3:          //existing standard code
   4:      }
   5:      else
   6:      {
   7:          //#N by Rahul Sharma on 19Apr2011 for RAH_ExcelImportRule_UpdateOnlyOption
   8:          //break if its a new record
   9:          if (importRule == SysDataExcelImportRule::RAHUpdate)
  10:              return false;
  12:          selectForUpdate = false;
  13:          updCommon = _curcommon;
  14:      }

After these small changes, you now should be able to import and update only existing records using standard AX excel import.

You can download the AX Project from here.

Join me on facebook and feel free to post your comments / feedback / queries.