Creating custom POS functionality inside Business Central

  1. How can write code inside a local procedure to payandpost a sales order after release
  2. 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
1 Like

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;
}
2 Likes

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