Post Purch Receipt List programmatically

Updated: 23.04.2015

In some cases you have to post purchase order's lines partly.
You can post Receipt List only for some of Purchase lines. Here is example, it's suitable for DAX 2009.

void postReceiptList(PurchTable    _purchTable)
{
    PurchFormLetter_ReceiptsList    purchFormLetter;
    PurchParmLine                   purchParmLine;
    Num                             parmId;
    ;
    
    purchFormLetter = purchFormLetter::construct(DocumentStatus::ReceiptsList);

    purchFormLetter.purchTable(_purchTable);
    purchFormLetter.initParmPurchTablePublic(_purchTable);//this method is a copy of initParmPurchTable() method, but it has public modifier


    parmId = purchFormLetter.parmId();
    purchFormLetter.parmParmTableNum   (parmId);
    purchFormLetter.transDate          (systemDateGet());
    purchFormLetter.specQty            (PurchUpdate::All);
    purchFormLetter.proforma           (NoYes::No);
    purchFormLetter.printFormLetter    (NoYes::No);
    purchFormLetter.usePrintManagement (false);
    purchFormLetter.creditRemaining    (purchFormLetter.creditRemaining());
    purchFormLetter.sumNum             (parmId);

    purchFormLetter.createParmUpdate(false);

    purchFormLetter.initParameters();

    purchFormLetter.initLinesQuery();

    purchFormLetter.progressHide();

    //tmpPurchLine is a temporary table that contains only Purch lines we need to be posted. 
    //you should prepare tmpPurchLine records before this block of code.
    while select forupdate purchParmLine
    where purchParmLine.ParmId == parmId
    {
        select firstonly tmpPurchLine
        where tmpPurchLine.PurchId == _purchTable.PurchId
            && tmpPurchLine.LineNum == purchParmLine.LineNum;
        if (!tmpPurchLine)
        {
            //So you should delete purchParmLine record if you don't need corresponding PurchLine to be posted
            purchParmLine.delete();
        }
    }

    purchFormLetter.run();
}    
    
Here is the declaration of PurchFormLetter_ReceiptsList.initParmPurchTablePublic() method
Class PurchFormLetter_ReceiptsList
public void initParmPurchTablePublic(PurchTable  _purchTable)
{
    this.initParmPurchTable(_purchTable);
}

 

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