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

Performing Mathematical Calculations in Business Central Visual Studio Code

(0) ShareShare
ReportReport
Posted on by 197

Hey Everyone.

I have created a hypothetical task in which I am trying to perform a mathematical calculation in Business Central and record the output values in a subledger account. An example of the calculation is 

Interest on Savings =  $50 * 0.047 (interest rate) * 31/365 (number of days in a month divide by number of days in a year) = $0.20

I have done a similar calculation when i wrote a C++ code in which I would write a procedure and call that procedure to perform the calculation but how can i accomplish something similar in Visual Studio Code in Business Central. I know that I can use CodeUnit which is similar to a procedure I believe in C++ but my worry is how do I record the output into a GL account? Any thoughts would be nice or any experience with writing a similar code with mathematical calculation would also be appreciated. 

I have the same question (0)
  • Suggested answer
    keoma Profile Picture
    32,729 on at

    you can write the formula like in c++.

    to add the result to a g/l account you have to create a g/l entry.

  • Suggested answer
    THE Italian Profile Picture
    on at

    You have to create a function inside a codeunt where you pass the parameters you need. 

    Every time you need that calculation, you have to reference that codunit into your object and call the function where you need most. 

  • attique Profile Picture
    10 on at

    I am wondering if you can add an extension (field) to the payment journal and let the user enter some values and let the system output the correct interest value. Do you think that is a good option for you and practicable?

  • Aneeq Profile Picture
    197 on at

    what if i have different scenarios that determines how the calculation will be done? I am thinking if I should ask the user to input certain fields in the payment journal and use IF THEN statements to figure out which calculation to perform. Will I have to create an extension by adding fields to payment journal and referencing the codeunit to those field? Can that happen?

  • Suggested answer
    THE Italian Profile Picture
    on at

    Yes. This can be done. You could create create field A and field B where you gather values and then field C is enabled=false and just trigger the result of the formula after validation of the fields

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,577

#2
YUN ZHU Profile Picture

YUN ZHU 888 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 778 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans