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