Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Error while trying to edit/update SalesLine

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have 2 warnings displayed, saying Company and Lot Id need to get filled up, while trying to update my sales line. I am sure inside my SalesLine, I have the Lot Id being filled up. However, I have no idea what Company is AX trying to refer to, because I cannot find such a field in the SalesLine table. 

In my requirement, I need to create Sales order and sales line, without knowing the inventory (such as sites, etc).

I have created my sales order successfully through X++, but not for Sales Line. Below is the code which creates both the Sales order and the sales line. Please shed me some light to what is exactly wrong. Thanks in advance.

    public SalesTable createSalesTable()//(HISLedgerJournalImport _hISLedgerJournalImport)
    {
        SalesTable              salesTable;
        SalesFormLetter         salesFormLetter;
        HISLedgerJournalImport  hisLedgerJournalImport;// = _hISLedgerJournalImport;

        info("Start inserting records into SalesTable");

        while select hisLedgerJournalImport
            where hisLedgerJournalImport.HISCategory == HIS_SALESCATEGORY
        {   
            str tmpSalesId = hisLedgerJournalImport.HISSalesDeptId + "-" + hisLedgerJournalImport.HISSalesId;

            if (!SalesTable::exist(tmpSalesId))
            {
                info("Inserting record: " + int642Str(hisLedgerJournalImport.RecId));

                salesTable.SalesId = tmpSalesId;

                salesTable.initValue();

                salesTable.CustAccount = hisLedgerJournalImport.LedgerJournalTrans_HISAccount;
                salesTable.initFromCustTable();
                //salesTable.initFromCustTableMandatoryFields();

                salesTable.CurrencyCode = hisLedgerJournalImport.LedgerJournalTrans_CurrencyCode;            
                salesTable.LanguageId   = CompanyInfo::languageId(); //Grabbing not from the cust table, but from companyInfo
            
                salesTable.insert();          

                this.createSalesLine(salesTable, hisLedgerJournalImport);
            }
        }
        return salesTable;
    }

    public void createSalesLine(SalesTable _salesTable, HISLedgerJournalImport _hISLedgerJournalImport)
    {
        SalesTable                  salesTable = SalesTable::find(_salesTable.SalesId);
        SalesLine                   salesLine;
        HISLedgerJournalImport      hisLedgerJournalImport;
        
        while select hisLedgerJournalImport
            where hisLedgerJournalImport.HISSalesDeptId == _hISLedgerJournalImport.HISSalesDeptId &&
                  hisLedgerJournalImport.HISSalesId     == _hISLedgerJournalImport.HISSalesId
        {
            salesLine.SalesId        = salesTable.SalesId;

            //salesLine.initValue(); 
            //salesLine.initFromSalesTable(salesTable); 

            salesLine.ExternalItemId = hisLedgerJournalImport.HISSalesExternalItemId; 
            salesLine.Name           = hisLedgerJournalImport.HISSalesItemTxt; 
            salesLine.SalesCategory  = EcoResCategory::findByName(HIS_SALESCATEGORY, 
                                       EcoResCategoryHierarchyRole::getHierarchiesByRole
                                       (EcoResCategoryNamedHierarchyRole::Sales).RecId).RecId;
            salesLine.SalesQty       = hisLedgerJournalImport.HISSalesOrderedQty; 
            salesLine.SalesPrice     = hisLedgerJournalImport.HISSalesPrice; 
            salesLine.LineAmount     = hisLedgerJournalImport.HISSalesLineAmount;

            salesLine.createLine(true, true, true, true, true, false);
        }
    }


*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error while trying to edit/update SalesLine

    And guess what... just one day later I had the same issue, googled on it and found this post which quickly solved my issue :) Thanks!

  • Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Error while trying to edit/update SalesLine

    Good to hear you could resolve it though this tip, and thanks for sharing what was missing in case someone else faces the same issue.

    Cheers!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error while trying to edit/update SalesLine

    Hello Vilmos Kintera

    Thanks for the reply, and for the very useful tip on putting a breakpoint in \Classes\Info\add to stop code execution with the Debugger when an infolog message.

    Indeed, as you have mentioned, SalesLine meddled with other tables. In my case, I found out by debugging that SalesLineForeignTradeCategory has missing records, which was needed to be created.

    I fixed it by adding in the following after having created the SalesLine:

    SalesLineForeignTradeCategory salesLineForeignTradeCategory;
    
    salesLineForeignTradeCategory.initFromSalesLine(salesLine);
    salesLineForeignTradeCategory.insert();

    Thanks again for the help, Vilmos Kintera!

  • Verified answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Error while trying to edit/update SalesLine

    You could put a breakpoint in \Classes\Info\add to stop code execution with the Debugger when an infolog message is raised, then check the callstack to see at what point do you get the error message.

    SalesLine creates records in additional tables, and a Company refers to the dataAreaId field which should normally be populated automatically.

    Maybe you have some missing setup, which leads to some records not being inserted correctly.

    Try to debug through and see what is missing in a Dev/Test environment.

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans