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 :
Microsoft Dynamics AX (Archived)

Error while trying to edit/update SalesLine

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    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.

  • Community Member Profile Picture
    on at

    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!

  • Vilmos Kintera Profile Picture
    46,149 on at

    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
    on at

    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!

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans