Dynamics 365 Customer Engagement instance has to have a base currency in which all transactions are priced. Even if a foreign currency is used, Dynamics 365 will always convert it back to be valued to the base currency; however, the exchange rate is not dynamically updated. Generally, Dynamics 365 CE is a CRM platform, and having an accurate conversion rate for each transaction is not required for many organizations. Meanwhile, some companies with international operations need to have an automatic and more frequent multi-currencies’ update. Therefore, a Power Automate flow is required to get the exchange rate updated.
External exchange rate API provider service updating the exchange rate.
First of all, it is essential to mention that this post is not sponsored by any organization, and the example used can be replaced based on the user’s preference.
To be fully agnostic, a list of service available below.
All the above services have a free plan. I will be using https://openexchangerates.org/, which I found sufficient for my example as I will be running an hourly update.
For reference, I joined with a free plan, which gives 1000 inquires per month and generated the following link, shown below.
The link App ID should be changed as per your free account, and the target currencies should be the currency codes, that you want to target. Instead, if the symbols section is dropped, the API will return all the currency codes.
Note! The free account allows enquiring using USD as the base currency. If you want to change the base currency, a paid account is required, or additional formula should be added to the Power Automate. In order to change the base currency, an additional attribute should be added to the link, such as “&base=EUR” to base on EUR.
Build the Power Automate Flow.
To build the flow, a number of steps have to be added as follows.
1. Trigger step, look for “Schedule.”
Set the interval and frequency based on your business case. In our example, while considering the limitations of the free account, we set the interval to “One” and the frequency to “Hour.”
2. Initiate variables
To pass the new value of each currency, we need to initiate two variables. The first one holds the new value (String) and the other one will be created to convert the value into a float to match data type.
-The first variable will be named “exchangerate” with the type “String”, and the value will be passed once the API is called.
-The 2nd variable will be named “FloatExchange” with the type “Float”, and the value will be passed once the API is called.
3. Add an “HTTP” action in the following. Set the method to get.
In the URL use the link generated using your codes.
Returns a JSON file as below
4. Add a “Common Data Service” action “List records.”
To return all the currency records added to D365 -> set the Entity name to “Currencies.”
To exclude USD from the list as it is the base currency and cannot be edited, in the filter query add (isocurrencycode ne ‘usd’). If your base currency is not USD, use the ISO code of your instance’s base currency.
5. Loop through the currency records using “Apply to each” control.
Under the “Apply to each” tile, the following actions needs to be added.
A. Set Variable tile to set the value of “exchangerate” from the JSON file.
Using dynamic content and from the expression tab, add the following code.
body(‘HTTP’)?[‘rates’]?[body(‘Get_record’)?[‘isocurrencycode’]]
to assign the right value from the JSON to right record.
B. Convert the string value to float.
Using dynamic content and from the expression tab, add the following code.
float(variables(‘exchangerate’))
C. Add a “Common Data Service” action “Update a record.”
To update the currency records added to D365 -> set the entity name to “Currencies.”
Record identified -> List records -> Transaction currency
Exchange rate -> Variable “FloatEchange.”
6. Test the flow.