Post Sales Shipment or Invoice using AL
Views (441)
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.
This was originally posted here.
*This post is locked for comments