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?

  • André Arnaud de Calavon Profile Picture
    293,280 Super User 2025 Season 1 on at
    RE: Import Movement Journal through Excel with x++

    Hi AhsanZia,

    You have to check the value of the COMVariantType using a debugger or info statement.

    When it is VT_BSTR then the command bStr() should be used. If it is VT_I1, you can use the method char() to get the value.

    Have you checked using the debugger if a value has been retrieved or what exactly is causing the error?

  • AhsanZia Profile Picture
    30 on at
    RE: Import Movement Journal through Excel with x++

    I've checked and the item number format in the Excel sheet is Text and in code its string so It should work for me but it isn't. I'm using item numbers like F0001,D0001 etc.

    Can anyone help me?

  • André Arnaud de Calavon Profile Picture
    293,280 Super User 2025 Season 1 on at
    RE: Import Movement Journal through Excel with x++

    Hi,

    The coding in the blog is assuming that the contents of the Excel column for the item number is a string (bStr()). Can you check the contents? If it is a number only, you have to use another command to read the Excel cell or change the format in Excel.

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Import Movement Journal through Excel with x++

    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

  • Mahmoud82 Profile Picture
    50 on at
    RE: Import Movement Journal through Excel with x++

    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

  • AhsanZia Profile Picture
    30 on at
    RE: Import Movement Journal through Excel with x++

    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, 

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    293,280 Super User 2025 Season 1 on at
    RE: Import Movement Journal through Excel with x++

    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
    RE: Import Movement Journal through Excel with x++

    DYND54C.tmp.xlsx

    This is my file and yes the fields match 

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Import Movement Journal through Excel with x++

    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
    RE: Import Movement Journal through Excel with x++

    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));
    
    }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,280 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,046 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans