Friday, March 27, 2015

Creating Exchange Rate Providers in Microsoft Dynamics AX 2012 for Open Exchange Rates



Microsoft Dynamics AX 2012 has the frame work for integrating currency exchange rates from exchange rate providers. Please reference Creating Exchange Rate Providers for Microsoft Dynamics AX 2012. The referenced document from Microsoft shows how to customize the frame work to work with Oanda Exchange Rates .

There are other providers, some which offer a fee based API and others which offer a free API. Doing research on these providers led me to Open Exchange Rates. They offer an API at no cost for personal use, and a fee based API for Enterprise users, which is fairly competitive with other providers.

This blog entry uses the referenced document from Microsoft as a guide to create a provider class in Dynamics AX specifically for use with the free version of Open Exchange Rates, and the fee based Open Exchange Rates API.


A challenge with using this provider is that it uses JSON instead of XML.

The provider class we will create will be the fee based provider. The fee based provider allows for selection of base currency, and specific currency pairs.

Create the class as ExchangeRateProviderOpenExchRates and have it extend the ExchangeRateProvider as shown in the class declaration below.

Note: The ExchangeRateProviderIdAttribute is a unique ID that you will need to supply. You can obtain a unique ID from http://createguid.com


Now create a method called getConfigurationDefaults. This method will provide the default URL used to make requests to the provider.


Next create the getExchangeRates method. This method is responsible for constructing the URL to request the currency information from the provider, and store the results in the currency exchange rate tables of Dynamics AX.



Next create the getName method. This method is used by Dynamics AX to populate the list of providers that Dynamics AX has been modified to support.


Once the getName method is created, create the getProviderId method. This method simply returns the unique GUID that was assigned in the class declaration.

Next create the getSupportedOptions method.


The last method that needs created is the readRate method. It is responsible for parsing the JSON response string from the provider, and storing the exchange rate and currency information in the Lists.


The version of the class that supports the free API is basically the same except for the URL request string. The free version only supports 2 options. The APPId, and the date parameter. The result is a currency list for all supported currencies but it is USD based. However the class filters to just the currency conversion needed by date. To modify the class to use the free version, simply change the getConfigurationDefaults method as follows:


Now that the class has been created, it can be used in currency configuration and setup within Dynamics AX.




currency1


currency2







4 comments:

Dynamics AX blogger said...

Hi Joe,

I am also trying to create new provider for exchange rate but not getting the new provider in lookup. I am working on client, I ran incremental CIL, changed GUID. and Restart my AOS. anything else that I am missing plz advise.

Leo Neves Monteiro said...

Hi Pramod, I had the same issue creating a new provider.

Solution: go Tools -> Cache -> Refresh Elements

I've discovered this after compiling, generating CIL a lot of times with no success, so I trying to clear the AX cache.

I hope that solve your problem.

Leo

Joe Hodge said...

After extending the class, make sure to add it to the list of configured exchange rate providers. Since it is a new class you may have to refresh the elements or restart the AOS. Then you must run the Import currency exchange rates.

palaniqu said...

Stainless Steel vs Titanium Apple Watch | iTaniumArts
The Apple Watch is an open-source version titanium mens wedding bands of the Watch which titanium dental allows you to set citizen titanium dive watch the minimum titanium pot bet, then add the babylisspro nano titanium hair dryer required amount to your bet slip.