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.
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
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?
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?
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.
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.
Sohail Ahmed
815
YUN ZHU
773
Super User 2025 Season 1
Mansi Soni
559