Hi All,
I'm getting a consistent error when i try to post a sales invoice using one codeunit which subscribe the event OnBeforeCode from codeunit12.

At the beginning I think which there something is wrong with the code but after looking better for code and made several tests I don’t have any clue about why the error is triggered
Using the posting preview, it’s looks like everything it’s fine.

but it i try to post i get the consistent error.
If I try to post one document using the journal it’s works fine, the accounting is right and without any problem.



If I comment the Consistent check (i know this is not the solution) in the codeunit i can of course post the document and can check which the accounting it’s correct


My code for the event subscription it’s like the following.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", 'OnBeforeCode', '', false, false)]
local procedure OnBeforeCodePT(var GenJnlLine: Record "Gen. Journal Line"; CheckLine: Boolean; var IsPosted: Boolean; var GLReg: Record "G/L Register");
begin
IsPosted := "Code"(GenJnlLine, CheckLine);
end;
For debug the error I also have tried one thing…I copied all the code from codeunit 12 save in a new object, create the event subscriber and the error persist.
I’m trying to use this event subscription because I don’t have enough events or the events don't have enough parameters, in the standard to do the necessary changes related with VAT for the Portuguese localization.
Anyone else already subscribed this event to change the standard post behavior?
Any sugesttion?
Thanks in advance.
Best regards,
LuÃs Franco