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)?
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:
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:
Tero
So i tried what you said but i'm guessing i am making a mistake somewhere but i don't see it:
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)
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
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?
You dont need anything on the page, just one subscriber in a codeunit like this:
Code to copy:
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:
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.
Hi,
Try subcsribing to OnAfterConfirmPost post event in codeunit 81. That should enable you to change Invoice to No, should it be Yes.
Tero