08 February 2021

How to achieve Currency Conversion in Power Automate with Dynamics 365 CRM

Dropped in Dynamics 365 CRM

Jon
Formulated by Jon

I’m working on a project which requires a dizzying combination of currencies – we’re a long way away from working in just GBP. In fact, if it was just two currencies it’d be straight forward. Microsoft Dynamics 365 CRM, traditionally, has supported multiple currencies and the concept we’ve all been used to of the ‘Value’ and ‘Value_Base’ fields that we get and how we’d interact with them in a workflow would’ve gone some way towards what we wanted to achieve.

However, just to put the kibosh on that idea, here at Tecman, all new projects, where possible are being done with Power Automate rather than workflows (to be fair it’s the future!). When I started looking at the options available, one thing that was notably missing was the ‘base’ fields – I could only see the local currency fields. So, clearly, I’ve got to do my own currency conversion. I’ve also got to do it in a lot of places so something repeatable would be useful.

I decided to go for a child Flow which made sense considering the problem. Firstly, the inputs.

We will certainly need the value that’s being sent in and, as this could be a conversion from any of the available currencies to any of the others, we clearly need two currencies.

Next, a couple of decimal number variables to hold the values while we work on them.

For the next step, we need to get the exchange rate for what’s there.

And while we’re at it, let’s also get the currency for what we need the output to be in.

In terms of the conversion, because we’re going to be dealing GBP for the majority of the time, it seemed sensible to use this as our base. We have the value and we have the currency that’s being passed to us so it made sense to convert this to GBP.

If the currency being passed is GBP, we can put that straight into the MoneyIn variable. If it’s not GBP then we have access to the exchange rate in the Currency entity so we can just divide the value being passed in by the exchange rate and we’ve got the value in GBP which we can put in the variable. Now, this step is complete, we have the value being passed in GBP.

Next, we use the same logic but in reverse.

If the output currency is GBP then we already have this value in the MoneyIn variable so we can send this back. If it’s not GBP then we do another calculation of multiplying the GBP value by the exchange rate.

Finally, we need to send the figures back.

I didn’t have to include the GBP value but it didn’t make sense to not include it – it may be needed. With everything you’ve seen above, the structure of the Flow is below:

Let’s give it a test. But first, here’s a snapshot of the data in CDS that we’re going to use.

If we start a test and enter the following information (you’ll have to trust me that the CurrencyPassed is the guid for Euros and the CurrencyReqd is the guid for Polish Zloty).

I won’t go through all of the stages, hopefully, it’s fairly clear what’s happening in the Flow so we’ll just skip straight to the output.

Some simple maths will tell us whether we’re correct with these. As we were passing 1000 Euros to start with, the calculation was 1000 / 1.07 which is, indeed, £934.58. We then multiply this by the rate for Zloty and, again, £934.58 * 4.77 comes to zł4457.94.

I think that shows it’s successful. Power Automate for the win…

Get in touch with one of the UK's best Microsoft Dynamics partner

Start your journey towards excellence with Microsoft Dynamics 365

Let us know your details and we'll get in touch with you to learn how we can transform your business processes and operations with Microsoft Dynamics 365 Business Central & Dynamics 365 Customer Engagement:

*

*

*

*

*

*

Protected by GDPR. We'll never share your personal data.

0
Years established
0
Happy customers
0
Projects
0
People supported
Brandauer
Pipers Crisps Co
Aden + Anais
Costa Coffee
Charlton & Jenrick
World Animal Protection

Get in touch

Wolverhampton

St Mark's Church
St Mark's Road
Wolverhampton WV3 0QH

Newcastle

19 Kingsway House
Kingsway
Team Valley
Gateshead NE11 0HW

Call: 01902 578 300
Skype: Call now

Co. Reg. 03100541
VAT No. GB559725692

Follow us

If you want even more, you can stalk us on any of our social media platforms: