Click here to Skip to main content
13,763,800 members
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 15 Sep 2010
Licenced CPOL

Integrate Microsoft Dynamics Axapta with Temperature Conversion C# Application

, 25 Sep 2010
Rate this:
Please Sign up or sign in to vote.
This article is having a C# code DLL to convert a Farenhite temperature into Celsius and vice versa. Further I have used this DLL in Axapta to integrate the “Convert Temperature” UI with Axapta.


This article is dedicated to Microsoft Dynamics Axapta and the C# community. Microsoft dynamics Axapta is an ERP for large scale industries. Every large organization has their own legacy system which they want to integrate with Microsoft dynamics Axapta so that without much effort they can leverage Microsoft Dynamics Axapta and their existing C# application. To understand it better, assume that the clients' C# application is having the UI with some functionality and we want to utilize that functionality in Microsoft dynamics Axapta without building that functionality from scratch but instead only passing the desire input for C# application from Microsoft Dynamics Axapta and in turn getting the output from C# application.

In order to understand the advantage of this article, please read the following scenario.

Suppose Client A is having one application B which is working perfectly fine to accomplish their small business goal. Now after some time, they decided to implement ERP Microsoft Dynamics Axapta to streamline and enhance their business process and to obtain profit. Suppose, the functionality B is not in ERP Microsoft Dynamics Axapta and client does want to implement that functionality in Axapta as already they are satisfied with that and application is having the DLL so that it can be used by other application. Hence to achieve this, we can integrate the application B of Client A to Axapta and thus by achieving this type of integration, client does not need to invest time and money in implementing the functionality to a larger extent. This article will also help any ISV partner for Microsoft Dynamics Axapta to have a POC of how to integrate the Axapta with C# application. Any ISV partner can develop their add-on and then expose their functionality as an DLL with API, which in turn Axapta will be utilized so that Axapta functionality is integrated to Add-on.

To develop a POC, I had developed a C# DLL “CvrtC2Frnt.dll” with project name as CvrtC2Frnt. After that “CvrtC2Frnt.dll” is utilized in Axapta to integrate the Convert Temperature application with Axapta table and form.

I am providing the source code for the following items:

  1. CvrtC2Frnt.dll
  2. Axapta code to integrate with Convert Temperature application

In addition to the above, I am also providing a sample application to test the CvrtC2Frnt.dll without using Axapta too.

There are many ways to integrate Axapta with .NET applications. In my upcoming articles, I will be covering some other aspects of integrating Axapta with .NET applications.

Let's begin...

Step 1: Creation of “CvrtC2Frnt.dll"

Create a C# project of type Class Library with the namespace CvrtC2Frnt. Let us assume that we have named the solution, "CvrtC2Frnt."

Step A

First, we will create the “CovertTemp” class. We will create the following members as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CvrtC2Frnt
    public class ConvertTemp
        public static double sourceTemp=0, destTemp=0;
        public static bool Faren = false;
        public static  double ConvertCelsiusToFahrenheit(double c)
            destTemp = 0;
            destTemp = ((9.0 / 5.0) * c) + 32;
            return ((9.0 / 5.0) * c) + 32;
        public static double ConvertFahrenheitToCelsius(double f)
            destTemp = 0;
            destTemp = (5.0 / 9.0) * (f - 32);
            return (5.0 / 9.0) * (f - 32);

The above code clearly specifies that two functions are created to convert temperature from Fahrenheit to Celsius and vice versa.

Step B

Now, we will add new windows form “ShowTemperature”, which will contain the UI for leveraging the functionality and interface to applications like Axapta.

Add the following controls on the form:

  1. Text Box of name txtSourceTmp
  2. Text Box of name txtDestTmp
  3. Label Box of name lblsrcTemp with blank value in Text property
  4. Label Box of name lbldesTemp with blank value in Text property
  5. One Command button with Text as Convert and name as btnConvert

Note: Text of labels will be displayed dynamically depending upon the type of conversion like if conversion is taking place from Fahrenheit to Celsius, then label lblsrcTemp will contain the Text as Fahrenheit and “lbldesTemp” as Celsius.


Step C

Now, create the following functions of class ShowTemperature:

public ShowTemperature(double Temperature, Boolean Fahrenheit)
            txtSourceTmp.Text = Temperature.ToString();
            ConvertTemp.sourceTemp = Temperature;
            ConvertTemp.Faren = Fahrenheit;
//Above code clearly specifies that we are initializing the label and text 
//box with vales coming from user input.
        private void btnConvert_Click(object sender, EventArgs e)
            if (ConvertTemp.Faren == true)
                txtDestTmp.Text = Convert.ToString
            if (ConvertTemp.Faren == false)
                txtDestTmp.Text = Convert.ToString
// above code is triggered when Convert button is click to convert the temperature.

        private void ShowTemperature_Load(object sender, EventArgs e)
            if (ConvertTemp.Faren == true)
                lblsrcTemp.Text = "Farenheit";
                lbldesTemp.Text = "Celsius";
                lblsrcTemp.Text = "Celsius";
                lbldesTemp.Text = "Farenheit";
// above  code specifies that form ShowTemperature is displayed dynamically 
// by label values depending
// upon the type of conversion is selected from Axapta or any other application.

Step D

Now, create the function ShowResult in class ConverTemp as follows:

public void ShowResult(double Temperature, bool Farenhite)
            ShowTemperature sT = new ShowTemperature(Temperature, Farenhite);

The above function in created to first call the constructor of ShowTemperature class with Temperature and type of temperature (Fahrenheit or Celsius) values. Afterwards, ShowTemperature UI is called to display corresponding UI.

Step E

This step is optional as already our DLL is created but to test before we actually use it in Axapta, we can perform Step E.

Add a New project of type Windows Form Application to the existing solution. Put the name of project as ShowUI. Add a reference of CvrtC2Frnt.dll in references.

Now design the form as given below:


The above form will work as follows:

If the value in Temperature Text box is as 50 and Fahrenheit check box is checked out, then it means that Temperature is given in Fahrenheit. When user will click on button Show Convert Temperature UI, then UI which was created in step B will be displayed.

Now the code behind Show Convert Temperature UI button is as follows:

private void btnShowUI_Click(object sender, EventArgs e)
            ConvertTemp ct = new ConvertTemp();
            if (chkFaren.Checked == true)
                ct.ShowResult(Convert.ToInt32(txtTemperature.Text), true);
                ct.ShowResult(Convert.ToInt32(txtTemperature.Text), false);

Now build the application and run it to test the result.


Click on this to get the UI for converting Fahrenheit to Celsius.


Click on Convert button to convert Fahrenheit to Celsius


Step 2: Integrate the CvrtC2Frnt.dll with Axapta

To perform step 2, you need to have Microsoft Dynamics Axapta installed in your system. Assuming that this is installed and running, follow the steps given below:

Step A

  1. Copy CvrtC2Frnt.dll file into the Bin folder under Microsoft Dynamics Axapta installable folder. i.e. C:\Program Files\Microsoft Dynamics AX\50\Client\Bin.
  2. Open AOT (Application object tree). AOT is a development environment in Axapta. By using AOT, we can customize and develop new functionalities in Axapta.


    Click to Open AOT or Press CTRL+D


  3. Now under AOT, go to References and expand it. Then click over Add Reference. Browse the CvrtC2Frnt.dll file into the Bin folder under Microsoft Dynamics Axapta installable folder. i.e. C:\Program Files\Microsoft Dynamics AX\50\Client\Bin.


    Click on Browse and select file CvrtC2Frnt.dll
  4. Click on Open after selecting CvrtC2Frnt.dll file from into the Bin folder under Microsoft Dynamics Axapta installable folder. i.e. C:\Program Files\Microsoft Dynamics AX\50\Client\Bin.


    Click on Open
  5. Click on Ok to add the reference.


    Click on Ok to add reference.


Step B

  1. Now create a New Project in Axapta name as ConverTemp. Press CTRL+SHIFT+P to open Project window and then right click on private node of Project window. Select New-> Project to create New Project.


    Click on Project to create New Project

    Rename the new project as ConverTemp.

  2. Create two groups and rename it to Form and Class.


    Click on Group two times to create new Groups and rename it to Form and Class
  3. Now right click on Class node under ConverTemp project and click on New-> Class to create new Class. Rename it to Temperature.


    Click on Class to create new Class in Axapta
  4. Now go to Class Declaration which is under and click Edit to open it.


    Click on Edit to edit class declaration of ConvertTemp Class
  5. Write the following code in class declaration:
    class Temperature
    CvrtC2Frnt.ConvertTemp ct;

    The above code is creating the object for ConvertTemp class which is defined in CvrtC2Frnt DLL.


  6. Add a new method ConvertTemperature to Temperature class in Axapta. Right click on temperature class and click on OverideMethod->New to add a new method. Rename the new method as ConvertTemperature.


    Click on New under OverideMethod to create new Method.
  7. Right click on ConvertTemperature method and select Edit to add code to it.


    Click on Edit to edit the class

    Add the following code to the editor:

    void ConvertTemperature(real Temperature, Boolean Fahrenheit)
        ct = new CvrtC2Frnt.ConvertTemp();
        ct.ShowResult(Temperature, Fahrenheit);


    The above function is taking two parameters as Temperature and Fahrenheit. Both parameters are passed to the ShowResult API defined in CvrtC2Frnt DLL.

  8. Right click Temperature class and select Save to save and compile the class.


    Click on Save to save and compile the Temperature Class

Step C

  1. We will create two new fields in SalesTable of Axapta:
    1. Temperature
    2. Farenhite
  2. Open AOT and go to data dictionary. Click on Tables and search for SalesTable.


    Select SalesTable.


    Select SalesTable


    Go to fields and right click over it and select new field of type real.


    Rename it Temperature.

    Add a new field as define of type as enum.


    Click Enum

    Rename it to Farenhite.


    Select the value in extended type property as Temp Type which is again a user enum of type NoYes. Hence before creating Farenhite field, first create the User Enum TempType.

    To create the TempType Enum, go to Extended Data Types in Data dictionary and right click select new->Enum.


    Click ExtendedData Type -> Click Enum

    Rename it to TempType and go to property. Select EnumType property value as NoYes.


    Select NoYes


    Now save it and go to SalesTable under DataDictionary. Search the Farenhite field created earlier and then go to ExtendedData Type property and select TempType as value.

    Select TempType


    Now save it.

  3. Now we will add two fields created in the above step to SalesTable Form.

    Go to SalesTable form under Form section in AOT. Select Designs->Design->Group:Table->Tab:TabHeader->TabPage:TabHeaderOverview->Grid:GridHeader and drop Temperature, Farenhite field from Datasource of SalesTableForm in it.


    Now Save it.

  4. Now Drag and drop the SalesTable Form from AOT to Form group under ConverTemp project in Axapta. Please note that Form group is created under point 2 of Step B.


  5. Now, we will create the Convert Temperature button on SalesTable Form.

    Go to SalesTable->Designs->Design->ButtonGroup:ButtonsHeader and right click to select new CommandButton control on SalesTable form.


    Click on CommandButton to create new Command button
  6. Right click on new command button and click properties to open property window. Go to Text attribute and enter value as ConverTemperature.


    Enter Convert Temperature -> Click on properties.
  7. Now we will create a new method clicked associated to ConvertTemperature button. This method we will create by right clicking on Methods under ConvertTemperature button and then selecting Overide method and then selecting Clicked.

    Methods->Overide Method->Clicked


    Select Clicked to override click method
  8. In the editor window, copy the following code:
    void clicked()
        Temperature tem = new Temperature();
        tem.ConvertTemperature( element.salesTable().Temperature, 

The above code is creating the object of class Temperature created in Axapta. Then we are calling ConvertTemperature function defined in Temperature class of Axapta with parameters as Temperature and Farenhite from SalesTable in Axapta. Earlier in point 1 of Step C, we had created two new fields in SalesTable of Axapta, i.e.:

  • Temperature (Data type: real)
  • Farenhite (Data Type: Enum with boolean)
  • Save the Code and run the SalesTable Form. To run go to Account Receivable module of Axapta and then click Sales Order.


Step D

Click on Account receivable

Double click on Sales Orders under Account Receivable module of Axapta. Under Sales Order Grid, select any record and double click and go overview tab of Sales Order form. Scroll to find out the Temperature and Farenheit field.


First click on Sales Order


Enter Temperature as 59 and check the Farenhite Check. (If Farenhite is checked, then the temperature in Temperature field is in Fahrenheit and upon clicking Convert Temperature, command button will convert it to Celsius. If the Farenhite checkbox is not checked, then the temperature in Temperature field is in Celsius and upon clicking Convert Temperature command button will convert it to Fahrenheit).

  • Click on Convert Temperature Command button on sales order form.


    Click on ConvertTemperature Button
  • Click on Convert Button of Convert Temperature Form.


    You got the temperature in Celsius!!!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

abhishek pareek2009
Technical Lead
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Kanasz Robert1-Dec-11 3:51
memberKanasz Robert1-Dec-11 3:51 
QuestionAX CLR Interop Question Pin
stationhill19-Oct-10 13:20
memberstationhill19-Oct-10 13:20 
AnswerRe: AX CLR Interop Question Pin
abhishek pareek200922-Oct-10 10:09
memberabhishek pareek200922-Oct-10 10:09 
GeneralRe: AX CLR Interop Question Pin
stationhill22-Oct-10 10:37
memberstationhill22-Oct-10 10:37 
GeneralRe: AX CLR Interop Question Pin
abhishek pareek200925-Oct-10 8:59
memberabhishek pareek200925-Oct-10 8:59 
GeneralGood Job! Pin
danielAus22-Sep-10 1:43
memberdanielAus22-Sep-10 1:43 
GeneralMy vote of 5 Pin
danielAus22-Sep-10 1:38
memberdanielAus22-Sep-10 1:38 
GeneralMy vote of 5 Pin
dyamicsworld18-Sep-10 7:31
memberdyamicsworld18-Sep-10 7:31 
GeneralAwesome Pin
andysymon16-Sep-10 8:45
memberandysymon16-Sep-10 8:45 
GeneralMy vote of 5 Pin
jom0115-Sep-10 10:01
memberjom0115-Sep-10 10:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.181113.4 | Last Updated 25 Sep 2010
Article Copyright 2010 by abhishek pareek2009
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid