Error when posting Sales Order, if not CodeUnit.Run(), BC Cloud.

GFBirkGFBirk Member Posts: 1
Hi experts!
I'm getting this generic error message when trying to post a Sales Order through the option "Ship and Invoice". Posting by klicking "Ship" and then "Invoice" works without any problems. The problem started after I added the condition "if not CodeUnit.Run() then...." and running the CodeUnit without conditions works without a problem.
The CodeUnit "CurrencyClauseCodeUnit" creates new SalesLines and SalesShipmentLines. These newly created records won't get rolled back if an error occurs in the CodeUnit, hence the need for running the error handling procedure "IfError".

The procedure "IfError" is not causing any problems. It doesn't matter what happends if the condition is met, it still leads to the same error.

Advice and thoughts are greatly appreciated.

vefski0qiyp3.png

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnBeforePostSalesDoc', '', true, true)]
    procedure OnBeforePostSalesDoc(var SalesHeader: Record "Sales Header")
    begin
        if SalesHeader.Invoice = true then begin
            if not CurrencyClauseCodeUnit.Run(SalesHeader) then begin
                CurrencyClauseCodeUnit.IfError(SalesHeader);
                Message(GetLastErrorText());
            end;
        end;
    end;

Answers

Sign In or Register to comment.