How to create only one invoice for several purchase orders in DAX012

Updated: 29.05.2015

How to create only one invoice for several purchase orders in DAX012.

//Create Purchase Parameter Lines for one of the purchases:

purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.purchTable(purchTable);
purchFormLetter.specQty(PurchUpdate::ALL);
purchFormLetter.chooseLines(true);

//Use the standard code that adds purchases to invoice

purchFormLetterInvoiceContract  = purchFormLetter.getPurchFormLetterContract();
purchParmUpdate = purchFormLetterInvoiceContract.parmParmUpdate();
select firstOnly forUpdate vendInvoiceInfoTable
    where vendInvoiceInfoTable.ParmId == purchParmUpdate.ParmId;

//delete all of the vendInvoiceInfoLine
delete_from vendInvoiceInfoLine
    where vendInvoiceInfoLine.ParmId == _vendInvoiceInfoTable.ParmId; 

purchSelectLinesManager = PurchSelectLinesManager::newPurchSelectLinesManager(_vendInvoiceInfoTable.TableRefId);
purchSelectLinesManager.parmPurchTableMark(parmPurchTableMark);
purchSelectLinesManager.parmPurchLineMark(parmPurchLineMark);
purchSelectLinesManager.parmParmId(_vendInvoiceInfoTable.ParmId);
purchSelectLinesManager.lukParmBuildQuery(false);//additional parameter, it disables query creation
purchSelectLinesManager.init();

while select purchLine 
..where //your filters
{
    purchSelectLinesManager.mark('', purchLine.RecId, purchLine, true, NoYes::No, true);
}
purchSelectLinesManager.passSets(_purchFormLetter);

purchFormLetter.reArrangeNow(false);//it's very important to make this parameter false
purchFormLetter.run();

 

Other blog posts

14.11.2017
Why outsourcing company is more effective than In-house IT-specialists There are situations when in-house specialists spend most of their time awaiting requests or they cannot get their work...
26.09.2017
Microsoft Dynamics AX program decisions are constantly improving. At first, innovations come to European companies, and only after that to Russian enterprises.We aspire to be one step ahead in this...
28.08.2017
Notes of the summit and of Dynamics market in Russia. Neti has been specializing in AX development since 2003. Our sphere of interest is the cutting-edge MS Dynamics technology. We find, study...

Subscribe for blog updates

Get updated with our blog new articles via your email!


Subscribe now