You are currently viewing Problem Solved: Managing Exchange Rates Between Dynamics GP and Dynamics CRM
MS Dynamics Currency Exchange Rates4

Problem Solved: Managing Exchange Rates Between Dynamics GP and Dynamics CRM

Ever have one of those days? You know those days. The kind where you cannot find any useful documentation on given functionality, i.e., currency exchange rate in Microsoft Dynamics CRM or Dynamics 365? It happened to me just earlier this week. A client of ours pushes data from Microsoft Dynamics GP to Dynamics CRM 2015 on-premise. Both applications are set up to use multiple currencies with US dollars as the base currency. In Dynamics 365 there are currency fields and their *_base amount fields. For example, an invoice may have a Total Amount field and a totalamount_base field. Along with these fields is the exchangerate field. The exchangerate field on the record holds the current exchange rate for the currency being used based on the transactioncurrency record at the time any currency field is updated. Remember this point.


The client’s problem was ensuring the _baseamount fields in Dynamics CRM match the base amounts found in Dynamics GP. We don’t want Dynamics CRM users misquoting a base amount. Of course, the simple solution is to integrate the currency exchange rates from Dynamics GP to Dynamics CRM. However, in our case, a record created in Dynamics GP may not create a record in Dynamics CRM right away. Invoices aren’t always pushed to Dynamics CRM upon creation. The invoice is processed, then integration occurs at some point in the future. The processing may take days if not weeks. This means the invoice may have a currency exchange rate of X but when the record is integrated with Dynamics CRM, the exchange rate is different.


Use the exchange rate stored with the Dynamics GP invoice and bring over to Dynamics CRM. And now the fun begins! The Microsoft Dynamics CRM exchangerate field on a record is not editable. Not through the UI, API, or plugins. We can’t update the field with normal means. What we can do is update the data being placed into the field. OK, before you say I’m using Sanford Speak, let me explain…

Searching the Dynamics forums, I found references to the RetrieveExchangeRate message. What is that, you say? This message reads the currency record retrieving the exchange rate for the given currency. We (techno geeks) can create a plugin to fire against the message and add a new exchange rate to the output parameter of the message to insert our new exchange rate. Here is how we did it.

Our integration process stored the Dynamics GP exchange rate in a custom field – xrm3_gpexchangerate. The custom field is defined as the out of the box exchangerate field.

Microsoft Dynamics 365 Partner

The plugin will check the parent context to determine if it is running for an Invoice or invoice detail record.

Microsoft Dynamics 365 Partner

It also confirms the existence of the above custom field with a value. Using the value from the above field, set the Output Parameter to the Dynamics GP exchange rate.


Microsoft Dynamics GP to Dynamics CRM

The plugin is registered against the RetrieveExchangeRate message in the post-operation synchronous mode.

Microsoft Dynamics 365 Partner

While this registration means the plugin will fire when any currency field is updated, the logic in place only runs when the parent context entity is either an invoice or invoice detail. To gather more information about this message, I had to debug using the plugin profiler. While debugging I viewed the contents of the context and the parent context.

If something about Dynamics 365 is bugging you, reach out to us here at Dyn365Pros. We can help.

By problem solver Sanford Mosby, Microsoft Dynamics 365 Technical Consultant, Dyn365Pros, Microsoft Dynamics 365 Partner, San Diego, Southern California