Power Community

Power Community

Integrating Dynamic 365 CRM with Third party API via custom connector using Power Automate – Part2

Integrating Dynamic 365 CRM with Third party API via custom connector using Power Automate – Part2

 

This article is in continuation of Part1 where I tried to give you a comprehensive description of Creating Custom Connectors in Power Automate for third party system API which enables a clearer understanding of custom connectors and its functionality. In Part2, I will give you a brief idea about how to integrate Dynamic 365 CRM with a third-party API via custom connector using Power Automate with a real time business use case.

 

I will take few moments to explain about multi-currency handling in Dynamic 365 CE.

 

The base currency is set while setting up the instance or the environment. There can only be one Base currency for instance or environment. Most importantly, the base currency cannot be updated.
But you are selling your products in the global market. It is important to understand that you will have prospects using multi-currencies. Dynamic 365 CE OOB supports you to create multi-currencies seamlessly. The below mentioned screenshot illustrates the default currency record in Dynamic 365 CE which consists of currency code, currency symbol, currency name and exchange rate.

 

ShanmugaRaja_0-1675316161403.png

To define additional currency, navigate to setting -> Business Management

ShanmugaRaja_1-1675316208233.png

ShanmugaRaja_2-1675316217891.png

 

We can create additional currencies either system or custom. To create system currency, we can select any of the existing currency codes.

 

ShanmugaRaja_3-1675316259674.png

For instance, while we create an opportunity record, Dynamic 365 CE automatically sets the default currency for the user.

ShanmugaRaja_4-1675316292064.png

Based on the customer, the Rupee currency is set in opportunity record.

ShanmugaRaja_5-1675316344908.png

While calculating the base amount, Dynamic 365 CE considers the Exchange Rate defined in the currency record.

ShanmugaRaja_6-1675316396245.png

Unfortunately, Dynamic 365 CE does not update Exchange Rates automatically. We should have some mechanism to update the exchange rate on a daily basis.

Let’s Start!!

Our primary goal is to capture live Exchange Rate from third party API and update the currencies records in the Dynamic CE on a daily basis. So, it is better to create a scheduled cloud flow which runs every day.

 

Step#1: Create a Recurring flow

 

ShanmugaRaja_7-1675316512559.png

In the next step, we must provide the trigger timing details. Define the starting date and time and repeat frequency. As per our requirement, we want to run it daily so choose to repeat every 1 day at 1:00 PM.

 

ShanmugaRaja_8-1675316567511.png

Step#2: Initialize Variable
Now we will add an action to initialize the variable to set the base currency code.

ShanmugaRaja_9-1675316616329.png

Step#3: Retrieve Currencies detail from Dynamic 365 CE
Add a new action to retrieve Currencies records from Dynamic 365 CE by using Dataverse connector and action as List rows.

ShanmugaRaja_10-1675316689685.png

Select columns:

Enter a comma-separated list of columns to return. In our case, selected few columns like “transactioncurrencyid,currencyname,isocurrencycode,exchangerate” from currencies table.

 

Filer Rows:

Filter expression to narrow down the set of rows that Dataverse returns such as “statecode eq 0” for rows with state code is equal Active.

To exclude base currency, the added condition to check “isocurrencycode ne USD” for rows with currency code is not equal to USD.

 

Step#4: Create Currency Code Array

Add Data Operation – Select action to create a new array from a list that contains currency code. 

 

ShanmugaRaja_0-1675420943821.png

Note: Although you can add or remove elements by using the select action, you can’t change the number of objects in the array.

Step#5:

Time has come to use our custom connector to get a live exchange rate for a given currency code list. Select Currency Exchange Rate action from choose an operation template.

 

ShanmugaRaja_1-1675421056665.png

As we know, the currency exchange rate takes two parameters.

1. Source – Base currency is passed.

2. Currencies – Specify a comma-separated list of currency codes. So, I used join expression to join array values with separators of comma delimiter (,).

 

Expression:

join(body(‘Select_Currency_Code’), ‘,’ )

 

ShanmugaRaja_2-1675421388880.png

ShanmugaRaja_3-1675421412692.png

In the background connector calls the API, and you get the response, which includes the live Exchange rate for a given currencies list.

ShanmugaRaja_0-1675429819477.png

My initial thought is to create a cloud flow which runs on a daily basis to capture live Exchange Rate against currencies and update in the Dynamic 365 CE. But my thought processes evolve to add more capabilities to match with real time business process flow. Updating Currencies Exchange Rate is not quite that simple. It will go through several levels of approval process before the exchange rate is reflected in the Dynamic 365 CE. So, I decided to incorporate a PDF file generation and approval processes functionalities.

 

Step#6:

Using Select – Data Operation action to create a new array which contains currency code, currency name, latest exchange rate and GUID. This array will help us to easily format data, generate a PDF file and update exchange rate values in Dynamic 365 CE.

 

ShanmugaRaja_0-1675422478799.png

To get currency exchange rate from API response JSON object. I have written an expression to parse the response object using the output function by passing currency code to pick the exact exchange rate value from the API response JSON object.

 

Expression:

outputs(‘Currency_Exchange_Rate’)?[‘body/quotes’]?[concat(‘USD’,item()?[‘isocurrencycode’])]

 

Step#7:

I want to present the data in HTML table format. The first and foremost option is to select Create HTML table – Data Operation action. This action will change a JSON array input into an HTML table seamlessly.

 

ShanmugaRaja_1-1675422673659.png

Columns are mapped either automatically or header and values are mapped manually. In our case, we have mapped only essential columns to create an HTML table.

 

ShanmugaRaja_2-1675422745228.png

Step#8:

Create a new step using compose operation action and enter the required CSS style for the table to generate a PDF file.

ShanmugaRaja_4-1675422858719.png

Step#9:

I picked a OneDrive connector to create a file (html file) and convert file (PDF file) seamlessly. As a first step we will use Create file action to create an HTML file in OneDrive.

ShanmugaRaja_5-1675422937680.png

Step#10:

Add convert file action to convert a HTML file into PDF file format using the path.

ShanmugaRaja_6-1675423009915.png

supported file conversion formats are html, htm, docx, msg, ppt, pptx, xls, xlsm, xlsx etc.

while using convert file action, we should be aware of known limitations and file size constraints in place for the protection of the connector’s service. note that attempting to perform operations beyond the limits will result in rejection, errors or timeouts. Few key important limitations are listed below.

  • The maximum archive size for Extract archive to folder action is 50 MB and 100 files inside.
  • Then when a file is created or when a file is modified triggers will skip every file bigger than 50 MB.
  • Some errors, like “Access Denied” usually indicate that the file is locked (e.g., by Excel services). Also, the user, file folder, or tenant may have a policy preventing access.

Step#11:

A PDF file created successfully. Now time to attach the PDF file and send it for approval. 

Create a step using “Start and wait for an approval” action and select “Approve/Reject-First to respond” for approval type.

 

ShanmugaRaja_0-1675446088620.png

Approval type: when a flow with Create an Approval action is configured with Approve/Reject – First to respond, it waits until it’s assigned to approve or assigned to reject the approval request.

 

Step#12:

To evaluate the user response is equal to Approve! then we need to add a “condition” action to handle the response from the previous approval action.

ShanmugaRaja_8-1675423979601.png

on the condition card, select an empty area in box on the left. The dynamic content list opens. Select the Outcome parameter to add it to the box. In the box in the middle of the condition card, select is equal to. In the box on the right, enter the “Approve” text which is mentioned in the approval type.

 

Step#13:

If yes block:

If Outcome is equal to “Approve” then add Apply to each action to loop through each item from live currency exchange rate list and update Dynamic 365 CRM currencies records with latest Exchange rate.

 

ShanmugaRaja_9-1675424256901.png

Step#14:

Finally, I decided to store the exchange rate PDF files in SharePoint for future reference.

Using SharePoint connector, add create file action to enter file name and output of converted PDF file content body is passed to file content for the create file action. Select correct SharePoint site address and folder path where we want to store the file.

ShanmugaRaja_1-1675446154981.png

All set! Let’s see the cloud flow in action.
The Old Exchange Rate cited below

ShanmugaRaja_11-1675424615292.png

Live Exchange Rate is created as a HTML file in OneDrive

ShanmugaRaja_0-1675449415769.png

HTML file is successfully converted to PDF and attached in approval email.

ShanmugaRaja_5-1675446924974.png

When approver approves the Exchange rate then Cloud flow will update the latest Exchange Rate in Dynamic 365 CRM. The Below screenshot is the updated Exchange rate.

ShanmugaRaja_14-1675424898529.png

Finally, Cloud flow will store the approved versions of the Exchange Rate PDF file into SharePoint for future reference.

 

ShanmugaRaja_4-1675446487375.png

`Perhaps this article will also give you some inspiration on other ways to make use of Power Automate.

 

Happy Learning and Happy Sharing. Cheers!!

 

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Microsoft OneNote now available on Apple Vision Pro

Today, we are introducing the newest member of the OneNote family, on the Apple Vision Pro. We have worked closely...

More Articles Like This

- Advertisement -spot_img