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

24.05.2018
Disclaimer
08.05.2018
We apply OKR methodology in Neti since 2014. We started from a quarterly planning, but then understood that no ambitious goals can be achieved per quarter. So we switched to semi-annual intervals....
11.04.2018
As you know, Microsoft recently has launched Dynamics 365 Business Central. And we are proud to announce we have launched intracompany training for sales and development departments:Why do we need it...

Subscribe for blog updates

Get updated with our blog new articles via your email!


Subscribe now