Saturday, March 28, 2015

Creating Exchange Rate Providers in Microsoft Dynamics AX 2012 for JSON 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 JSON Rates. They offer a free API, which has the functionality needed for basic currencyPair conversion rate retrieval.

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 JSON Rates API.

The provider class we will create will support the JSON Rates API.

Create the class as ExchangeRateProviderJSONRates 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 XML response string from the provider, and storing the exchange rate and currency information in the Lists.



A JSON to XML converter class will also need to be added as a dependency, which is coded as follows:

classdeclaration

loadFromFile

convert2xml
convert
getTag


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




currency2







No comments: