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
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!
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!
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!
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.
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156