Skip to content
Development

How to Create a Calculator in D365 F&O: Programming Functionality

Caf2Code July 16, 2021 2 min read

Now that we’ve set up our D365 F&O VS environment, we can create a model and project in visual studio for our simple calculator project.

Editor's update — June 2026: The X++ logic in this post still holds — overriding the button clicked method and reading/writing control values with .value() remain the standard pattern in current Dynamics 365 Finance & Operations. The only thing that has moved on since 2021 is the development environment behind the "Build / Start" steps: Microsoft now uses a cloud-based Unified Developer Environment (UDE) provisioned via the Power Platform admin center, replacing the Lifecycle Services developer VMs, with build and run happening from Visual Studio 2022. See Unified environment types and templates for finance and operations apps.

We made it! In the final post of our series, we will be making our calculator functional.

Adding Functionality with X++ Programming

1. Click on the "Multiply" button to unfurl and right-click on Methods. Select Override and click "clicked".

Original screenshot not recoverable from the web archive
OverrideExample.png

2. Add the following code to the newly opened function.

Before the function, declare an int variable to hold the result of our calculations.

int result;

Use the newly created variable to create the correct equation.

result = Integer1.value() * Integer2.value();

Then pass the result variable to the Total field like this:

Total.value(result)
Original screenshot not recoverable from the web archive
MultiplyCodeExample.png

3. Copy and paste the above code three more times into the .xpp file, making sure to change the name and operator (*, /,+,-) to match. You should end up with one function for each of the following: Multiply, Divide, Add, Subtract.

Original screenshot not recoverable from the web archive
Code.png

4. In the Solution Explorer, right-click on the calculator form and click on "Set as Startup Object".

Original screenshot not recoverable from the web archive
StartupObj.png

5. In the toolbar, select Build and click Build Solution.

Original screenshot not recoverable from the web archive
BuildSolution.png

6. In the action pane, click on "Start". A new browser window should open with your calculator.

Original screenshot not recoverable from the web archive
Start.png

7. Put a value in each of the top two fields and click on your calculator buttons to test. If everything goes as planned, you should now have a functional calculator!

(Special thanks to the Ali Mahar YouTube page for the inspiration for this series.)

Caf2Code is a Microsoft Solutions Partner specializing in Dynamics 365 Finance & Operations, Power Platform, and Power BI. Originally published July 16, 2021; restored to caf2code.com in 2026.

Working on Dynamics 365 or Power Platform?

Caf2Code is a Microsoft Solutions Partner. Whether it is F&O development, security, reporting, or an end-to-end implementation, our team can help.