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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Import Movement Journal through Excel with x++

(0) ShareShare
ReportReport
Posted on by 30

Hi everyone,

I'm looking to import an excel file through x++ code, to Movement Journal. 

What I want is - when I run the project, there should be a dialog box with a button to upload the excel file and on pressing OK, the file should be uploaded and the values should be set in the Movement Journal Lines.

The Problem is that I don't know what kind of project should I create to do this.

should I create an RDP class and use it with UI Builder class and Contract class or it is done in the forms?

What is the exact solution?

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,025 Super User 2025 Season 2 on at

    Hi AhsanZia,

    Are you aware of the Data Import Export Framework? This can already import Excel files. There is an entity available for an inventory journal: docs.microsoft.com/.../data-import-export-framework-entities-dixf-dmf

    This would save you from some development efforts.

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi,

    There are some posts related to this.

    Please check e.g. the following sites:

    abdulghani121.blogspot.com/.../job-for-importing-journal-in-ax-2012.html

    axactive.com/.../

    Best regards,

    Ludwig

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hello AhsanaZia,

    Have you tried following the code examples provided and did you make some progress?

    Please let us know if there is anything else the community can help you with.

    Many thanks and best regards,

    Ludwig

  • AhsanZia Profile Picture
    30 on at

    Hi Ludwig Reinhard

    I really really appreciate your help!

    I have created a job to import the excel file and there is one little problem.

    which is - When I post the excel file, it says posted and Movement journal is created but when I check the movement journal in the form, the lines are not created

    Can you tell me the issue by seeing my code ?

    Here it is-

    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;
        InventJournalTable  journalTable;
        InventJournalTrans  journalTrans;
        InventJournalTableData journalTableData;
        InventJournalTransData journalTransData;
        InventTable     inventTable;
        InventDim       inventDim,_inventDim;
        int                 i=1;
        InventDimCombination        inventDimCombination;
        EcoResProductMaster         ecoResProductMaster;
        EcoResDistinctProductVariant        ecoResDistinctProductVariant;
        InventLocation      inventLocation;
    
    
         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
         {
              //Incrementing the row line to next Row
            if(i == 1)
            {
            journalTableData = JournalTableData::newTable(journalTable);
            journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);
    
            // Init JournalTable
    
            journalTable.clear();
    
            journalTable.JournalId      = journalTableData.nextJournalId();
            journalTable.JournalType    = InventJournalType::Movement;
            journalTable.JournalNameId  = journalTableData.journalStatic().standardJournalNameId(journalTable.JournalType);
    
            journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));
            journalTable.insert();
            journalTrans.clear();
            i  ;
            }
            try
            {
                row  ;
    
           journalTrans.clear();
           journalTransData.initFromJournalTable();
    
            journalTrans.TransDate      = systemDateGet();//mkDate(15,11,2013);
            journalTrans.ItemId        = cells.item(row,2).value().bStr();
    
             inventDim.clear();
    
             inventDim.InventSiteId = inventLocation.InventSiteId;//
              inventDim.InventLocationId = cells.item(row,4).value().bStr();//Ware House
            select firstFast inventLocation where inventLocation.InventLocationId == inventDim.InventLocationId;
             inventDim.wMSLocationId = cells.item(row,5).value().bStr();//A-01-00
            journalTrans.Qty  = Cells.item(Row,6).value().double();//.float();//.double(); //date();
            journalTrans.CostPrice = decRound(cells.item(row,7).value().double(),2);
            journalTrans.CostAmount = journalTrans.Qty * journalTrans.CostPrice;
           //  journalTrans.LedgerDimension = cells.item(row,9).value().toString();//.bStr();//double();//.bStr();
    
           //  inventDim.configId =cells.item(row,15).value().bStr();//here (EcoResConfiguration)=color
          
    
    
         //   inventDim.inventBatchId = cells.item(row,7).value().bStr();
    
            //inventDim.inventSerialId = cells.item(row,16).value().bStr();
            //inventDim.InventLocationId = cells.item(row,14).value().bStr();*/
                //for offset account
           // journalTrans.LedgerDimension = cells.item(row,14).value().toString();//.bStr();//double();//.bStr();
    
          //  _inventDim=inventDim::findOrCreate(inventDim);
    
          //  journalTrans.InventDimId = _inventDim.inventDimId;//"FCC-000153";
          //  journalTransData.insert();
    
    
         _inventDim=inventDim::findOrCreate(inventDim);
    
            journalTrans.InventDimId = _inventDim.inventDimId;//"FCC-000153";
            journalTrans.insert();
      // Loads the next row into the variant type and validating that its is empty or not
        type = cells.item(row 1, 1).value().variantType();
                row  ;
            }
            catch
            {
                throw error("error");
            }
        }
        while (type != COMVariantType::VT_EMPTY);
            // quits the application
        application.quit();
        info(strFmt("Inventory Journal Imported   :%1",journalTable.JournalId));
    
    }

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi,

    How does your file look like?

    Are the items in your file matching those in your system?

    Best regards,

    Ludwig

  • AhsanZia Profile Picture
    30 on at

    DYND54C.tmp.xlsx

    This is my file and yes the fields match 

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,025 Super User 2025 Season 2 on at

    Hi Ahsan,

    It is a bit hard to read the coding with some obsolete lines (out commented).

    I would suggest to use the debugger to see what exact values are read from the Excel file and if the journal ID is set correctly when you insert the lines.

    As mentioned above, you can also use the Data Import Export Framework without coding; just configuration.

  • AhsanZia Profile Picture
    30 on at

    Hi,

    Thanks again for the help

    I'm now using the code in this blog post. Here is the link-

    https://abdulghani121.blogspot.com/2013/11/job-for-importing-journal-in-ax-2012.html

    But when I post the excel file, it is showing an error, "item number must be specified"

    Can you tell me the reason of this issue?

    Regards, 

  • Mahmoud82 Profile Picture
    50 on at

    hello AhsanZia

    this error is coming when you called the journalTrans.insert(); due to the item code field is mandatory in the journal lines table

    this may be due to the item id cell in excel is not in the text format in this case it will be imported as a blank value

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi AhsanZia,

    Have you tried sending the author of the post a direct message asking for a demo sample import file and the error message that you see?

    Best regards,

    Ludwig

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans