web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How can I import data from Excel?

(0) ShareShare
ReportReport
Posted on by

Hi guys

I would like ask you that how i can import data from excel to dynamics ax r3

*This post is locked for comments

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi Musaad,

    What data do you want to import from Excel to AX?

    In AX2012 you have the AIF and the DIXF available that can help you importing the data.

    What might fit best depends on what you try to import and do.

    Best regards,

    Ludwig

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Musaad,

       You can import data by using Job and by using form buttons and so..

    You can you this code to import data form excel to ax. Try this code by using Job or Button(Clicked Method).

    Job:

    static void InsertRecords(Args _args)
    {
         SysExcelApplication application;
         SysExcelWorkbooks workbooks;
         SysExcelWorkbook workbook;
         SysExcelWorksheets worksheets;
         SysExcelWorksheet worksheet;
         SysExcelCells cells;
         COMVariantType type;
         Name name;
         FileName filename;
         int row =1;
         int i=0;
         InventTable         inventTableLoc;
         ItemId              itemid;
         TransDate           transdate;
         str                 NewField;
         Dialog dialog;
         DialogField dialogField;
         ;
         application = SysExcelApplication::construct();
         workbooks = application.workbooks();
         dialog = new Dialog("FileOpen");
         dialogfield = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
         dialog.run();

         if (dialog.run())
         {
            filename = (dialogfield.value());
         }
         try
         {
         workbooks.open(filename);
         }
         catch (Exception::Error)
         {
         throw error("File cannot be opened.");
         }
         workbook = workbooks.item(1);
         worksheets = workbook.worksheets();
         worksheet = worksheets.itemFromNum(1);
         cells = worksheet.cells();
         do
         {
             ttsBegin;
         row++;
         itemid    = cells.item(row, 1).value().bStr();
         NewField  = cells.item(row, 2).value().bStr();
         inventTableLoc = InventTable::find(itemid,true);
         inventTableLoc.NameAlias = NewField;
         inventTableLoc.insert();
             ttsCommit;
         i++;
         type = cells.item(row+1, 1).value().variantType();
         }
         while (type != COMVariantType::VT_EMPTY);
         application.quit();
         info("Done");
         info(strFmt("%1", i));
    }

    Thanks

    Suresh

  • Ruben Heinrich Profile Picture
    643 on at

    In general you would have to install the Micsosoft Office Plug In on the Client. Once installed you can then open your Excel and use the Dynamics AX Plug In which enables you to exchange all table data as well as some data sets. However you must be Aware of the interdependencies and Relations of the tables.

    Another way is, working with the Dynamics Import Export Framework, which has some preconfigured entitites. It also supports Format Excel.

  • Okay Akdeniz Profile Picture
    110 on at

    Hi Musaad,

    There are many methods to import data from excel into AX. 

    • DIXF
      • Create or use existing entity
      • Create an data source type. (Excel)
      • Create a mapping source and target
      • Process 
    • AIF Document Services. 
      • You can create an query.
      • Execute Tools\AIF Document Services Wizard
      • Create an Inbound Port in System Management module
      • Create an DocumentSource in Organization Management module
      • Full CIL
      • Open an Excel with Dynamics AX Excell add-in
      • Select Add Data and use
    • XPP Custom Code
      • There are many code samples on the internet.
      • But standard samples just shows import method.
      • You will be faced many problems when the excel crashes or another excel application run.
      • You may prefer import csv file method. Because TXT file import faster than excel.
    • Office Add-in VSTO
      • You can create an VSTO projects
      • You can add a ribbon bar on excel like Dynamics AX Excel add-in
      • Business Connecter or AIF Document Services can help to import.

    DIXF the best way to import Excel.

  • Dishanth Profile Picture
    90 on at

    I tried with this code but there is error saying SysExcelWorkbook does not denote any class table.....

    how can i clear this

  • ergun sahin Profile Picture
    8,826 Moderator on at

    Can you confirm you are using ax 2012? Sounds like 365fo error to me.

  • Suggested answer
    Hossein.K Profile Picture
    6,650 on at

    Hi,

    If you use AX2012, you can use below code:

     SalesLine           _salesLine;
        InventDim           _inventDim;
        SalesTable          _salesTable;
        InventTable         inventTable;
        SalesId             salesId = salesTable.SalesId;
        ItemId              itemId;
        EcoResItemSizeName  inventSize;
        EcoResItemColorName inventColor;
        EcoResItemStyleName inventStyle;
        InventSiteId        inventSiteId;
        InventLocationId    inventLocationId;
        EcoResItemConfigurationName configId;
        SalesPrice          salesPrice;
        Qty             qty;
        InventDimId     inventDimIdTmp;
    
        SysExcelApplication             application;
        SysExcelWorkbooks               workbooks;
        SysExcelWorkbook                workbook;
        SysExcelWorksheets              worksheets;
        SysExcelWorksheet               worksheet;
        SysExcelCells                   cells;
        COMVariantType                  type;
        FilenameOpen                    filename;
        dialogField                     dialogFilename;
        Dialog                          dialog;
        Integer                         row = 1;
    
    
        str COMVariant2Str(COMVariant       _cv)
        {
            switch (_cv.variantType())
            {
                case (COMVariantType::VT_BSTR):
                    return _cv.bStr();
                case (COMVariantType::VT_R8):
                  //  return _cv.toString() ;
                    return _cv.bStr() ;
                case (COMVariantType::VT_DATE):
                    return date2str(_cv.date(),123,2,1,2,1,4);
                case (COMVariantType::VT_EMPTY):
                    return '';
                default:
                    throw error(strfmt("@SYS26908", _cv.variantType()));
            }
        }
         ;
         dialog              =   new Dialog('Import Vendor Details');
         dialogFilename      =   dialog.addField(ExtendedTypeStr("FilenameOpen"));
         dialog.filenameLookupTitle('Import from excel.');
         dialog.caption('Import From Excel');
         dialogFilename.value(filename);
         if(dialog.run())
         {
             filename            =   dialogFilename.value();
             application         =   SysExcelApplication::construct();
             //application.displayAlerts(false);
             workbooks           =   application.workbooks();
             try
             {
                 workbooks.open(filename);
             }
             catch (Exception::Error)
             {
                 throw error('File cannot be opened.');
             }
             workbook            =   workbooks.item(1);
             worksheets          =   workbook.worksheets();
             worksheet           =   worksheets.itemFromNum(1);
             cells               =   worksheet.cells();
             try
             {
                // ttsbegin;
    
                 do
                 {
                     inventTable.clear();
                     _inventDim.clear();
                     _salesLine.clear();
    
    
                     row  ;
                     itemId           = cells.item(row, 1).value().bStr();
                     inventSize       = strreplace(cells.item(row, 2).value().bStr(),'\'','');
                     inventColor      = strreplace(cells.item(row, 3).value().bStr(),'\'','');
                     inventStyle      = strreplace(cells.item(row, 4).value().bStr(),'\'','');
                     configId         = cells.item(row, 5).value().bStr();
                     qty              = cells.item(row, 6).value().double();
                     inventSiteId     = cells.item(row, 7).value().bStr();
                     inventLocationId = cells.item(row, 8).value().bStr();
                     salesPrice       = cells.item(row, 9).value().double();
    
                     type = cells.item(row 1, 1).value().variantType();
    
                     _salesLine.initValue();
    
                     /* Init SalesLine from SalesTable*/
                     _salesLine.SalesId = salesId;
                     _salesLine.initFromSalesTable(salesTable);
    
                     /* Set SalesLine Item*/
                     _salesLine.ItemId = itemId;
    
    
                     //Initializing the sales line from inventory
                    _salesLine.initFromInventTable(InventTable::find(_salesLine.ItemId));
    
                    //Setting and creating inventory dimensions
                    //I have given the warehouse in
                    if(Inventlocation::find(inventLocationId).InventLocationId != "")
                    {
                        _inventDim.inventBatchId = "General";
                        _inventDim.InventSiteId = InventLocation::find(inventLocationId).InventSiteId;
                        _inventDim.InventLocationId = Inventlocation::find(inventLocationId).InventLocationId;
                        _inventDim.wMSLocationId = "In_01";
                        _inventDim.InventSizeId = inventSize;
                        _inventDim.InventStyleId = inventStyle;
                        _inventDim.InventColorId = inventColor;
                        _inventDim.InventStatusId = "normal";
                        _inventDim.ConfigId = configId;
                    }
                    _salesLine.InventDimId = InventdIm::findOrCreate(_inventDim).inventDimId;
                   // _salesLine.initFromProductDimensions(inventDim);
                    inventDimIdTmp = _salesLine.InventDimId;
                     /* Set Sales line value*/
                     _salesLine.SalesQty   = qty;
                    // _salesLine.SalesPrice = salesPrice;
                     /* End*/
    
                     /* Look for trade agreement if not found base selling price will be use*/
                     //_salesLine.setPriceDisc(inventDim);
                     /* End*/
    
                     /* Create SalesLine*/
                     //_salesLine.CreateLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes );
                     _salesLine.createLine(NoYes::Yes, // Validate
                                          NoYes::Yes, // initFromSalesTable
                                          NoYes::Yes, // initFromInventTable
                                          NoYes::Yes, // calcInventQty
                                          NoYes::Yes, // searchMarkup
                                          NoYes::Yes ); //
    
                    _salesLine.SalesPrice = salesPrice;
                    _salesLine.LineAmount = _salesLine.calcLineAmount();
                    _salesLine.InventDimId = inventDimIdTmp;
                    _salesLine.update();
                 }
                while (type != COMVariantType::VT_EMPTY);
                workbooks.close();
                application.quit();
               // ttscommit;
    
                 SalesLine_ds.research();
                 InventDim_ds.research();
                 InventDim_ds.refresh();
    
             }
             catch
             {
                 try{
    
                    workbooks.close();
                    application.quit();
                     }
                 catch{
                     info('error in importing...');
                 }
             }
        }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans