D365 Business Central : Post Sales Shipment or Invoice using AL

If you want to post Sales Shipment or Invoice from your extension, you can use Codeunit 80 Sales-Post. Before you send the Sales Header record to the codeunit, it is necessary for you to tag if you want to post the Shipment or Invoice. You can do this by modifying the fields in the Sales Header record and send the modified Sales Header to the codeunit.

First we need to define the variables.

SalesHeader: Record "Sales Header";
SalesPost: Codeunit "Sales-Post";

Once you declare the variable, you can start writing the logic. The following code will post both the shipment and invoice.

case SalesHeader."Document Type" of
  SalesHeader."Document Type"::Order:
      SalesHeader.Ship := true; //false if you do not want to post shipment
  SalesHeader."Document Type"::"Return Order"
      SalesHeader.Receive := true; //false if you do not want to post return receipt
end;

SalesHeader.Invoice := true; //false if you do not want to post the invoice
Clear(SalesPost);
SalesPost.Run(SalesHeader);

For Purchase, you can use the same logic as above, but use Codeunit 90 Purch.-Post.

thatnavguy

Experienced NZ-based NAV Developer and Consultant with 15+ years of experience leading multiple IT projects, performing business analyst, developing, implementing, and upgrading Dynamics NAV and Business Central. Passionate to deliver solution that focuses on user-friendly interface while keeping high standard of compliance with the needs.

You may also like...

1 Response

  1. 1 November 2020

    […] Post Sales Shipment or Invoice using AL […]

Leave a Reply

Your email address will not be published. Required fields are marked *