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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Viewing / understanding codeunits

(0) ShareShare
ReportReport
Posted on by 10

Hello forum!

I'm admitting I am a rank beginner, probably in over my head here. I have been tasked with doing some customization to our cloud based business central tennant and am up to a wall here.  Basically I have written come code that creates a few pages and tables that allow me to calculate commissions to our unique circumstances.  I am at the stage where I need to figure out how posting the order to an invoice happens so I can attach my stuff to that. I have been advised to check codeunit 12 Gen. Jnl. -Post Line and Codeunit 22 Item Jnl. Post Line.

The problem is I have no idea how to do that!

Is this question so basic no one has posted anything about this, or is it I am just not seeing the answer in obvious places? Gaaaaak, it is so frustrating sometimes...

I have the same question (0)
  • Suggested answer
    Francisco Bedolla Profile Picture
    1,123 on at

    you to subscribe your code to an event in the codeunit

    I want that BC look for the salesperson code and look for him in the new commision table and get the percentage for that salesperson and put that percentage in a decimal variable, then calculate the unit price * quantity and apply the percentage and store the result in some table, this needs to be happened when "your event here", as an example of an event you can say "when i clic in the post action", and then "before the sales line be posted in the Sales invoice line", this is your event.

    please read docs.microsoft.com/.../devenv-subscribing-to-events

    and then you can understand what is an event and how to use it

  • JoeRoche Profile Picture
    10 on at

    Thank you. I appreciate your response.

    I guess I am a little off track here, which would explain why there isn't a similar question out there in the Googleverse. I have finally stumbled onto a blog that shows me how to do exactly what you say I need to do, and am in the process of trying to write my code. I have chosen the "OnAfterSalesInvLineInsert" event to subscribe to.  My question is really more about how to know what "OnAfterSalesInvLineInsert" actually does.

    Maybe I am overthinking it...

  • Francisco Bedolla Profile Picture
    1,123 on at

    OnAfterSalesInvLineInsert means

    the code that you put in the event will be triggered after the sales line was copied to the sales invoice line

    if you check the codeunit 80, you will find that the system creates gl entries, customer ledger entries, vat entries, item ledger entries, and sales invoice line entries. So, if you choose to put your code in that event, let's say you are making sure that it has been validated first that everything could be registered correctly without errors and without allowing false executions and this is different if you use OnBeforeSalesInvLineInsert.

    this last event allows you to calculate values before the sales invoice line is created so you can calculate any value and then, add this new value to the sales invoice line, as an example, you want to calculate the commission prior to insert the invoice line because you want to add that calculated value to a new field in that table.

    what im trying to say is,

    you need to choose the event depending on what you are trying to obtain, if it is already calculated or not and if it is already "registered" (validated) or not

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,092

#2
YUN ZHU Profile Picture

YUN ZHU 663 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 515

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans