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 :
Finance | Project Operations, Human Resources, ...
Answered

D365 Counting journal X++ CSV import - Qty field column empty

(0) ShareShare
ReportReport
Posted on by 70

Hi all,

I've imported the CSV file to counting journal with 2 fields, Barcode and Qty. 

The Qty column is not getting set to the field I'm importing through the file.

Can anyone tell me the reason with their past experience?

I have the same question (0)
  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Based on your other question I know that you use custom code for import. Could you share it here please? Otherwise it's not so easy to know what could be wrong with it :) 

  • Dynamics365 Profile Picture
    70 on at

    Thank you for the help!

    please have a look at the code. 

    class CFZCountingJournalImport
    {
        #define.utility("Counting journal import utility")
       
    
    
        CFZ_CountingJournalImportTmp cfzCountingJournalImportTmp;
        InventJournalTable      inventJournalTable,inventJournalTableParm;
        InventJournalTrans      inventJournalTrans;
        InventJournalTrans      inventJournalTrans_pram;
        InventTableModule       inventTableModule;
       
        InventSum               inventSum;
        
    
        InventItemBarcode       inventItemBarcode;
        InventDim               inventDim,inventDim2,inventDimNew,inventDimFindOrCreation;
                                                     
        JournalId               journalId;
        InventSiteId            inventSiteId;
        InventLocationId        inventLocationId;
        Qty                     qty;
        ItemBarCode             itemBarcode;
        ItemCostPrice           itemCostPrice;
        MainAccountNum          offsetAccount;
        RetailStoreId           store;
        str                     referenceStore, referenceDoc;
        FormRun                 forme;
        Args                    arg;
        NoYes                   IsAnyErrorOccured;
        int                     row;
        int                     iQty;
        str                     fileString;
        int                     iTOCount;
        str                     businessUnit,subBusinessUnit,department,location,purpose,worker,natureOfExpense;
        
    
        //Used to get the File Stream
        public List setStream(System.IO.Stream _stream,Args _args)
        {
            //Parse the file by converting the file to String and passing it to class MTQImportVaidationNParser
            arg                         = _args;
            System.IO.StreamReader sr   = new  System.IO.StreamReader(_stream);
            fileString                  = sr.ReadToEnd();
            List mainlist               = CFZImportHelper::parseString(fileString);
    
            return mainlist;
        }
    
        public void importLogic(List _list)
        {
            ListIterator iterator;
            container cont;
            iterator = new ListIterator(_list);
            int i;
    
            while(iterator.more())
            {
                cont = iterator.value();
                this.importCountingJounralLines(cont);
                cont = conNull();
                iterator.next();
    
            }
        }
    
        public void importCountingJounralLines(container _journalLines)//, InventSiteId _siteid, InventLocationId _locationid)
        {
            /*Insert Temp Table*/
            /*--------------------- Processing Excel File, Verifying Then Insert into Temp Table-----------------------------*/
            if(_journalLines)
            {
                row  ;
                if(row > 1)
                {
    
                  
                    itemBarcode         = strLtrim(strRtrim(conpeek(_journalLines, 1)));
                    qty                 = any2Real(strLtrim(strRtrim(conpeek(_journalLines,2))));
                   
    
                    if (qty == 0)
                    {
                        error(strFmt("Row # [%1] found invalid quantity [%2].", row, qty), #utility);
                        IsAnyErrorOccured = NoYes::Yes;
                    }
    
                    if (IsAnyErrorOccured == NoYes::No)
                    {
                        ttsbegin;
                        // Insert temp table
                        cfzCountingJournalImportTmp.initValue();
                        cfzCountingJournalImportTmp.clear();
                        cfzCountingJournalImportTmp.ItemBarCode      = itemBarcode;
                        cfzCountingJournalImportTmp.Qty              = qty;
                      
                        cfzCountingJournalImportTmp.insert();
                        ttscommit;
                    }
                    else
                    {
                        IsAnyErrorOccured = NoYes::No;
                    }
                }
            }
        }
    
        public void afterTmpTableProcessing(InventSiteId _siteID, InventLocationId _locationId)
        {
            if (arg.record().TableId == tableNum(InventJournalTable))
            {
                inventJournalTableParm = arg.record();
            }
    
            Info(strFmt("Journal id: %1",inventJournalTableParm.JournalId));
            journalId = inventJournalTableParm.JournalId;
    
        
            if (row <= 1)
            {
              
                warning("No data found in csv file");
                return;
            }
            else
            {
                if (IsAnyErrorOccured == NoYes::Yes)
                {
    
                    error("Please Find Above Errors List.");
                    ttsAbort;
                    // delete_from cfzCountingJournalImportTmp;
                    return;
                }
                else
                {
                    iTOCount = 0;
                    ttsbegin;
    
                    while select cfzCountingJournalImportTmp
                    {
                        inventItemBarcode   = InventItemBarcode::findBarcode(strLTrim(cfzCountingJournalImportTmp.ItemBarCode), false, false, '', false);
                        inventDim           = InventDim::find(inventItemBarcode.inventDimId);
    
                        
    
                        if(inventItemBarcode)
                        {
                            info(strFmt("%1",inventItemBarcode.itemId));
                           
                            inventJournalTrans = null;
                            inventJournalTrans.initValue();
                        
                            inventJournalTrans.LineNum      = InventJournalTrans::lastLineNum(journalId)   1;
                            inventJournalTrans.JournalType  = 4;
                            inventJournalTrans.JournalId    = journalId;
                            inventJournalTrans.ItemId       = inventItemBarcode.itemId;
                            inventJournalTrans.Qty          = cfzCountingJournalImportTmp.Qty;
    
                            info(strFmt("%1",cfzCountingJournalImportTmp.Qty));
    
                            /* Find or Create InventDimID */
                            inventDimFindOrCreation.InventSiteId        = _siteID;//cfzCountingJournalImportTmp.InventSiteId;//inventDim.InventSiteId;
                            inventDimFindOrCreation.InventLocationId    = _locationId;//cfzCountingJournalImportTmp.InventLocationId;//inventDim.inventLocationId;
                            inventDimFindOrCreation.InventSizeId        = inventDim.InventSizeId;
                            inventDimFindOrCreation.INVENTCOLORID       = inventDim.INVENTCOLORID;
                           
                            inventJournalTrans.InventDimId              = InventDim::findOrCreate(inventDimFindOrCreation).inventDimId;
                            /*-----------------------------*/
    
                            inventJournalTrans.initFromInventTable(InventTable::find(inventItemBarcode.itemId),false,false);
    
                            
                          
                            inventJournalTrans.insert();
                          
                            iTOCount  ;
    
                        }
    
                        
                    }
    
                    if  (iTOCount > 0)
                    {
                        Box::info(strfmt('Total [%1] Counting journal lines created successfully.',iTOCount));
    
                       
                    }
    
                    delete_from cfzCountingJournalImportTmp;
                    ttsCommit;
                }
                
                forme = arg.caller();
                if(forme)
                {
                    forme.dataSource().research(true);
    
                }
    
            }
        }
    
    }
       

    One more problem that i'm facing is that in this line

     inventItemBarcode = InventItemBarcode::findBarcode(strLTrim(cfzCountingJournalImportTmp.ItemBarCode), false, false, '', false);"

    "inventItemBarcode" variable is showing null value of itembarcode, although there is value in "cfzCountingJournalImportTmp.ItemBarCode" which I checked while Debugging

    Please let me know the issue

    Regards,

  • Verified answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    Hi,

    For question 1, Qty not getting set, Can explain more details? Where is it not getting it set? Is it Temp table where you are reading the values from file? or assigning at inventJournalTrans buffer? Is the code pasted by you is all the code?

    for question 2: InventItemBarcode variable is showing null, Did you chek if the ItemBarcode exists in the InventItemBarcode? if it doesnt exists inventItemBarcode buffer will be null.

  • Dynamics365 Profile Picture
    70 on at

    Hi Vinit Goyal,

    Thanks for the reply

    1) I'v checked and you were right. the Itembarcode that I was trying to use was not in the InventItemBarcode table. That issue is resolved now.

    2) Qty is not getting set into the QTY column of the Counting Journal Form where I'm uploading my file. 

    Yes I'm using TempDb table which is cfzCountingJournalImportTmp

  • André Arnaud de Calavon Profile Picture
    303,730 Super User 2026 Season 1 on at

    Hi KZOo,

    Have you used the debugger to see if the source has a quantity and/or if the variable qty or cfzCountingJournalImportTmp.Qty field has a value?

  • Dynamics365 Profile Picture
    70 on at

    Hi André Arnaud de Calavon

    Yes, I debugged and the cfzCountingJournalImportTmp.Qty field has a value.

    Moreover, I've used info(strFmt("%1",cfzCountingJournalImportTmp.Qty)); and its showing the message with the quantity when the file is uploaded but not filling the value in the form Qty column

  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    1) Please try "info(strFmt("%1", inventJournalTrans.Qty))" instead?

    2) Please look with the table by table browser to see if there's value in Qty field?

    3) Please debug all the way to inventJournalTrans.insert() method and check which values are inserted?

    And please share all learnings from above 3 points with us. Thanks!

    Also, InventJournalTrans.initFromInventTable can modify the Qty field in some cases, you can find this out by looking at the code and also by debugging. So, perhaps it's good to call this method before setting Qty yourself.

    By the way - not related to your problem, but may I suggest to use following pattern when initializing new records:

    MyTable myTable;
    
    myTable.clear(); // inizialize a new buffer
    myTable.initValue(); // Call initValue() method to initialize any default values from it
    myTable.MyField = "foo";
    myTable.insert();
    
    

    I saw that somewhere you were usingt "myTable = null" instead of myTable.clear(), and also calling myTable.clear() after myTable.initValue(), clearing any default values that might come (now or in the future) via initValue method.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 616

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 460 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 331 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans