Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Business Central forum

How to check if invoicing option is selected with AL code

(0) ShareShare
ReportReport
Posted on by 450

So i'm trying to check if when posting an order an option with invoicing (Invoicing / Ship & Invoicing) is checked so that i can cancel it since people are not allowed to invoice from a sales order. Now i tried the property SalesHeader.Invoice and check whether this option is Yes or No (since it doesn't return true or false) but when I check if it's "Yes" and after try it, it still returns a no when an invoicing option is selected so in what way can i check if it is checked so that i can cancel the action of invoicing (and posting)?

Categories:
  • Verified answer
    Community Member Profile Picture
    on at
    RE: How to check if invoicing option is selected with AL code

    Oops, You are absolutely right, it is not a variable in the line but a parameter in the function call. I read the code too fast.

    Basically the subscriber should look like this:

    pastedimage1568038469428v1.png

    The only issue  in your code is that the first parameter name don't match the publisher, but that's likely due trying different options. I normally use intellisense (Ctrl+Space) on those as they need to be an exact match. Also, its good idea to install onprem on your local machine for reference purposes if you don't have one yet.

    Heres the code as text as well:

    [EventSubscriber(ObjectType::Codeunit, 5764, 'OnAfterConfirmPost', '', false, false)]
    local procedure MyProcedure(WhseShipmentLine: Record "Warehouse Shipment Line";Invoice: Boolean)
    begin
    if Invoice then
    Error('You are not allowed to post!');
    end;

    Tero

  • InsertX Profile Picture
    450 on at
    RE: How to check if invoicing option is selected with AL code

    So i tried what you said but i'm guessing i am making a mistake somewhere but i don't see it:

    6036.Capture.PNG
    5488.Capture1.PNG

    It keeps telling me there is no invoice parameter and somehow it's searching for the variable somewhere while i'm declaring it...

    (The else message('failed') is just for testing, it won't stay there)

  • Community Member Profile Picture
    on at
    RE: How to check if invoicing option is selected with AL code

    The Invoice parameter is on the "Warehouse Shipment Line". Otherwise it is exactly the same logic. Subscribe to OnAfterConfirmPost event, and check if Invoice is Yes on WhseShipmentLine. Also, in both cases you might want to limit the action with a document type to make sure you wont completely disable all invoicing, but I'm guessing you already did that.

    Tero

  • InsertX Profile Picture
    450 on at
    RE: How to check if invoicing option is selected with AL code

    Thanks this really helped me out for the sales order. Now just because i'm interested in it, tried to apply this as well on the warehouse shipments page. I searched for the codeunit which is codeunit: 5764 but appearently there is no such thing as the "Invoice" parameter in the "Warehouse Shipment Header". Any idea what to do here?

  • Verified answer
    Community Member Profile Picture
    on at
    RE: How to check if invoicing option is selected with AL code

    You dont need anything on the page, just one subscriber in  a codeunit like this:

    pastedimage1568024687656v1.png

    Code to copy:

    [EventSubscriber(ObjectType::Codeunit, 81, 'OnAfterConfirmPost', '', false, false)]
    local procedure CancelInvoicingOnAfterConfirmPost(var SalesHeader: Record "Sales Header")
    begin
    if SalesHeader.Invoice then
    Error('You are not allowed to post!');
    end;
    Tero
  • InsertX Profile Picture
    450 on at
    RE: How to check if invoicing option is selected with AL code

    So i attempted as suggested but the results seems to be the same.

    The following code is what i tried:

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post (Yes/No)", 'OnAfterConfirmPost', '', true, true)]

       local procedure CancelOnPost()

       var

           SalesHeader: Record "Sales Header";

       begin

           If Format("SalesHeader".Invoice) = 'Yes' then

               Error('You are not allowed to invoice');

       end;

    in my pageextension of the order i have:

     actions
        {
            modify(PostAndSend)
            {
                trigger OnAfterAction()
                var
                    Publisher: Codeunit 50002;
                begin
                    Publisher.CancelOnPost();
                end;
            }
        }
  • Hannes Holst Profile Picture
    5,767 on at
    RE: How to check if invoicing option is selected with AL code

    hi,

    Check event "OnAfterConfirmPost" of codeunit 81 "Sales-Post (Yes/No)".
    This event is published right after the values of SalesHeader.Invoice & SalesHeader.Ship have been selected by the user and stored in the table.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: How to check if invoicing option is selected with AL code

    Hi,

    Try subcsribing to OnAfterConfirmPost post event in codeunit 81. That should enable you to change Invoice to No, should it be Yes.

    Tero

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans