- How can write code inside a local procedure to payandpost a sales order after release
- how can I prevent a release onAction trigger from changing the status from open to released when the lines have no items
in business central using AL code
Welcome to the community! Hopefully someone can help you out.
Not yet received any reply to my post.
Hello terr!
First part you can achieve without coding by setting up a Payment Method that has Bal. Account type and No. set to automatically mark the Ledgers as paid. Then you can set up a Job Queue Entry card to run report 296 Batch Post Sales Orders which will do the posting part for you.
Information how you can do that can be found from Microsoft Docs: Set Up Payment Methods - Business Central | Microsoft Docs
and:
Post Multiple Documents at the Same Time - Business Central | Microsoft Docs
Second question sample code is below. Hope that helps.
/// <summary>
/// Codeunit My Subscribers (ID 60014).
/// </summary>
codeunit 60014 "My Subscribers"
{
EventSubscriberInstance = StaticAutomatic;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Release Sales Document", 'OnBeforeManualReleaseSalesDoc', '',true,true)]
local procedure OnBeforeManualReleaseSalesDoc(var SalesHeader: Record "Sales Header")
var
SalesLine: Record "Sales Line";
begin
SalesLine.Reset;
SalesLine.SetRange("Document Type" ,SalesHeader."Document Type");
SalesLine.SetRange("Document No.", SalesHeader."No.");
if SalesLine.IsEmpty then
Error('There is no lines on %1 %2, release failed.',SalesHeader."Document Type",SalesHeader."No.");
end;
}
Thanks @UrpoKotipalo . I tried your solution for the lines its working because its catching the error âThere is no lines on the invoiceâ. Which is okay. There after came another error once i fill the line and click the release button, it still brings the erorr i have prompted there?
what ca ne be the problen?
this is my code
begin
"Document Type" := "Document Type"::Invoice;
salesLine.Reset();
//SalesLine.SetRange("Document Type", Rec."Document Type");
SalesLine.SetRange("Document No.", Rec."Document No.");
if SalesLine.IsEmpty then
Error('There is no lines on %1 %2, release failed.', Rec."Document No.")
else
Rec.Modify(true);
Rec."SalesHeader-Status" := Rec."SalesHeader-Status"::Released;
end;
Hello terr
You shouldnât really set the Document type to something, if you do that, all your Sales Lines turn to sales invoice lines, disregarding the Header type. This leads to orphaned Sales Lines.
You donât need to do Modify either, BC should follow its standard path and release the Sales Header. The field âSalesHeader-Statusâ field is unknown to me, perhaps you have added it there?
Ok i was trying to achieve something like a point of sales. So i have my table for both the header, named pos header, and lines named sales line. I have pages for each of them, list and card as well as lispart for the lines. Having done so, I thought setting a document type to invoice would help me post the pos as an invoice directly