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;
   8:   
   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;
  11:          
  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.
If you liked the story and want to see more of this kind of content, please follow our twitter handle @CursorRun or FB page @CursorRun
Default image
Rahul Sharma
Rahul is a technology enthusiast, solutions architect, trainer, and blogger, working on various Microsoft and open source solutions with more than 18 years of industry experience. He specially takes interest in designing enterprise applications, cloud integrations, IoT, and other architecture rich business solutions.

Leave a Reply

%d bloggers like this: