Click here to Skip to main content
12,759,979 members (31,134 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 30 Nov 2010

Integrate Microsoft Dynamics Axapta with Temperature Conversion C# Application - Part II

, 14 Dec 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
This article will demonstrate that after sending the data from Axapta to Temperature conversion application, how we can post back the converted temperature to Axapta.


To understand this article, one has to go through Part I. This will be useful for those ISVs or clients who would like to send the data back to Axapta after processing from third party application. As earlier stated in Part I, when temperature will be converted, then the temperature data can be sent back to Axapta by using C# application. My main intention to develop and publish these articles is to help the ISVs and clients for having POC about the integration of their existing applications with Axapta.

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

We have the data in Axapta which needs to operate by some processes. Client or ISV is already having the third party application which has all desired functionalities to process the data. This kind of integration I had published in Part I of this article. Now there is a greater extent of requirement to again update the Axapta with process data from third party application. This functionality is beautifully demonstrated with the help of Temperature conversion application.

To demonstrate this POC, I modified the same application which I developed in my Part I.

To understand this POC, one should be proficient regarding Object oriented concepts for C# and Axapta. One should have extensive working experience in Axapta and C#.

Here, I will not only give the source code but also the description about the code that I added to Part I .

Let’s begin this interesting journey…


To develop the Axapta connector, one should have extensive knowledge of X++ and C#. This means that one should have working knowledge of object oriented programming.

To understand this article, one should go through Part I. In addition to that, one should have Axapta with SQL Server 2005 and Visual Studio 2008 with SP1 installed on their system.

Modification 1: Creation of AxHelper Class

This class contains the code to connect to Axapta from Temperature Conversion application.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Dynamics.BusinessConnectorNet; 
namespace CvrtC2Frnt 
{ Microsoft.Dynamics.BusinessConnectorNet 
class AxHelper:BC 
	BC bc = new BC(); 
	Axapta ax; 
	string tableName = "SalesTable"; 
	AxaptaRecord axRecord; 
	public void SetAxRec(Boolean Farenhite, double Temp, string SalesId) 
		ax = bc.GetAxConnection(); 
		if (ax != null) 
			using (axRecord = ax.CreateAxaptaRecord(tableName)) 
				axRecord.ExecuteStmt("select forupdate * 
				from %1 where %1.SalesId ==" + "'" + SalesId + "'" ); 
				axRecord.set_Field(50001, Temp); 
				if (Farenhite == true) 
					axRecord.set_Field(50002, 1); 
					axRecord.set_Field(50002, 0); 

The above code clearly specifies that we are using Microsoft.Dynamics.BusinessConnectorNet DLL to send the data to Axapta.

Modification 2: Creation of BC Class

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Dynamics.BusinessConnectorNet; 
namespace CvrtC2Frnt 
class BC 
	Axapta ax; 
	AxaptaRecord axRecord; 
	public Axapta GetAxConnection() 
		ax = new Axapta(); 
		ax.Logon(null, null, null, null); 
		return ax; 

The above helps to connect to Axapta.

Modification 3: Modify ConverTemp Class

namespace CvrtC2Frnt 
public class ConvertTemp 
	public static double sourceTemp=0, destTemp=0; 
	public static bool Faren = false; 
	public static string SalesId = string.Empty; 
	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); 
	public void ShowResult( double Temperature,bool Farenhite, string salesId) 
		ShowTemperature sT = new ShowTemperature(Temperature, Farenhite, salesId); 

In the above code, SalesID is added so that we can modify the SalesTable in Axapta for the converted temperature.

Modification 4: Modify Convert Button

private void btnConvert_Click(object sender, EventArgs e) 
	AxHelper axhlp = new AxHelper(); 
	if (ConvertTemp.Faren == true) 
		txtDestTmp.Text = Convert.ToString(ConvertTemp.
		axhlp.SetAxRec(false, ConvertTemp.ConvertFahrenheitToCelsius
	if (ConvertTemp.Faren == false) 
		txtDestTmp.Text = Convert.ToString(ConvertTemp.
		axhlp.SetAxRec(true, ConvertTemp.ConvertCelsiusToFahrenheit
			(double.Parse(txtSourceTmp.Text)), ConvertTemp.SalesId); 

In the above code, ConvertCelsiusToFahrenheit is now taking three parameters to update the SalesTable after converting temperature.

Modification 5: Modify ShowTemperature Constructor

public ShowTemperature(double Temperature, Boolean Fahrenheit, string SalesId) 
	txtSourceTmp.Text = Temperature.ToString(); 
	ConvertTemp.Faren = Fahrenheit; 
	ConvertTemp.sourceTemp = Temperature; 
	ConvertTemp.SalesId = SalesId; 

In the above code, SalesID is now also initializing with value from Axapta so that we can update the SalesTable with the converted temperature by C# application.

Modification 6: Modify the ConvertTemperature Class in Axapta

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

In the above, SalesID is added as a third parameter.

Modification 7: Modify the Clicked Function for ConvertTemperature Button on SalesTable in Axapta

void clicked() 
	Temperature tem = new Temperature(); 
	tem.ConvertTemperature( element.salesTable().Temperature, 
		element.salesTable().Farenhite, element.salesTable().SalesId); 

Now finally let’s have a demo…

Demo 1


On the above SalesTable Axapta form, key in the Temperature as 45 and uncheck Fahrenheit. This means that Temperature is 45 degree Celsius. Click on Convert Temperature button on the above form.

Click on Convert button on Convert Temperature C# form.


On the above Sales Order form in Axapta, Temperature is converted to Fahrenheit.

This is it!

In this article, not only temperature is converted but also posted to Axapta SalesOrder.

I have another surprise in this article. Upto now, I had integrated ConvertTemperature application with SalesOrder Card form but now in Demo 2, one can see how easily we can integrate it to SalesListPage of Axapta.

Let us start …

Demo 2

On the above SalesOrderList page, one can see the Temperature Add-on tab on Action page. Two command buttons one can see, i.e.:

a) Refresh – To refresh the SalesOrderList page.

Convert Temperature- This will populate the same Convert Temperature form from C# as it was coming from SalesCard form.


On the above form, click on Covert button to convert the 45 degree Celsius to Fahrenheit.


We can see that 45 degree Celsius is converted to 113 Fahrenheit. The converted temperature is also updated in SalesList Page. To see that, click on refresh button on SalesList Page.


You got the converted temperature in Axapta SalesList page too via C#.

I am providing complete C# code and Axapta code so that any ISV, client and developers can understand that how we can use the UI and logic of any third party application in C# with Axapta records to process it and again posting back to Axapta. Big and small organization always looks for this kind of two way integration to save time and effort for implementing new functionalities in ERP. Instead of implementing new functionality in ERP, we can integrate the third party application to ERP for achieving the desired functionality.

Please note that this Temperature conversion application can also easily be integrated with Microsoft Dynamics Navision by writing only 8 lines of code. This means that developers should have working knowledge of C# and Axapta. They should also follow the best practices prescribed by Product owner. In our case, it is Microsoft. As I had worked on lot of integrations project for Axapta and Navision for Various ISV's, developers should know the ERP very well technically. If the ERP is Axapta, then one should know the Object oriented concepts and at least 2 years of Axapta experience with at least 1 year of C# experience. C# is important as without the C# experience, developers who only know Navision or Axapta will be 95% idle. Now a days integrating Axapta and Navision is becoming very easy, matter of 8 hours only with any other application. We should give full credit to Microsoft as they had exposed the business logic and code of Axapta and Navision through web service. So folks, happy coding, but be very careful as you going to play with the financial data which is very crucial to any client... 


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

GeneralPlease format Pin
tec-goblin6-Dec-10 13:16
membertec-goblin6-Dec-10 13:16 

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 | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 15 Dec 2010
Article Copyright 2010 by abhishek pareek2009
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid