the caf2code press
How To Create a Calculator in D365 F&O: Programming Functionality
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”.
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)
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.
4. In the Solution Explorer, right-click on the calculator form and click on “Set as Startup Object”.
5. In the toolbar, select Build and click Build Solution.
6. In the action pane, click on “Start”. A new browser window should open with your calculator.
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!