Wednesday, July 13, 2022

How to add a C# class in Dynamics 365 FO

 Create a C# project in visual studio like below




Add the following class in your project area

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AYDotNet
{
    public class Calculator
    {
        public decimal Add(decimal x, decimal y)
        {
            return x + y;
        }
    }
}

Now build the project and not the solution.


Once that is done, now add a new Dynamics 365 FO project in the same solution and give the appropriate model.

Add a runnable class in the D365 FO as follows:


using AYDotNet;

class MCO_Test

{

    public static void main(Args _args)

    {

        var cal = new Calculator();

        Info(strFmt("%1",cal.Add(10, 20)));

    }

}


Now add the reference of the C# class in the D365 FO project as follows :



Now you will see something as below, select it and press Ok



Tada !!!