web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Consistent error when using Event OnBeforeCode from codeunit12.

(0) ShareShare
ReportReport
Posted on by

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.

pastedimage1612827171040v2.png

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.

pastedimage1612829351686v3.png

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.

pastedimage1612829384971v4.png

pastedimage1612829391064v5.png

pastedimage1612829399042v6.png

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

pastedimage1612829585561v7.png

pastedimage1612829710029v8.png

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

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Consistent error when using Event OnBeforeCode from codeunit12.

    Hi Suresh,

    I'm making some changes acordding the portuguese rules.

    Basically i'm moving the existing customizations from c12 BC140 to BC170 and make the necessary changes.

    At the benning i'm started using the existing events in codeunit 12 to make the necessary changes but at some point i figured out which doesn't exists the necessary events or the events doesn't have the needed parameters - after discuss with my collegues we all think we don't choise and need to duplicate the codeunit12, customize and use the OnbeforeCode to ensure which the codeunit for posting it's the portuguese C12 to do the accounting according the country rules.

    Best regards,

    Luis Franco

  • Suggested answer
    Suresh Kulla Profile Picture
    49,609 Super User 2025 Season 2 on at
    RE: Consistent error when using Event OnBeforeCode from codeunit12.

    Are you creating any additional lines or posting in your custom code?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 3,406

#2
Sumit Singh Profile Picture

Sumit Singh 2,852

#3
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 2,217

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans