Dynamics 365 and Cognitive Services – Code-less Implementation – Translation

Reading Time: 7 minutes

Microsoft Cognitive services offer a range of services that can use the power of Azure to undertake tasks that used to require a considerable amount of code to conduct. In this example, I am going to use the out of the box translation service to demonstrate how using Microsoft Dynamics, Cognitive services and FLOW to translate emails on the fly as they are created in Dynamics. This shows how you can implement these three services without the need for any code.

The Scenario

In the global business community, we are going to encounter situations where we receive communications that are not in our native language. In this scenario, a multinational organisation receives emails that are not in English. What we want to achieve is on the fly translation to allow an operator who only speaks English to understand email communication.

The Solution

Configuring Cognitive Services

The first component that you will require to implement the solution is an Azure subscription to allow the deployment of cognitive services. As part of the flow setup, you will need to provide an API key to enable the connection to Azure.

As an individual, you can sign up for a free Azure account which gives you £150 of free credits to get you started. – https://azure.microsoft.com/

Currently, the cognitive translator service is part of the 25+ always free services, though there is a character limit within the free quota.

From the Azure portal, you are able to set up the translator service by creating a new resource.

  1. Select Create a Resource
  2. Search for the Translator Text service
  3. Click Create

You are then able to configure the details of the translator service.

Name: Specify a clear name, so you are able to identify your service in the list of Azure services.

Subscription: Select the subscription that you wish to use – this will be your free trial subscription if you have used the free trial option.

Pricing: Depending on the volume you are expecting select the correct pricing tier. I have chosen the free allowance.

Resource Group: This where you configure the resource group that the service sits within – this is purely a way of grouping services in Azure.

Resource Group Location: Select the region that is closest to you in order to ensure the best performance of the service.

Once the service has been deployed, you will be able to view your new service and access the API keys that will be required in order to configure FLOW.

Save the generated key as you will need this later.

Configuring Dynamics 365

In order to allow the translation of the email to be written back to Dynamics 365, I have added a new translation text box to the email activity entity. This will allow the translation to be updated onto the email while ensuring the original email message is maintained. The other option would be to overwrite the original email, but I decided against this as I want to maintain the data integrity by keeping the received email message.

The other option I considered as to create a translation entity and create a lookup to the email. This will, however, involve additional clicks to see the translation.

This solution I implemented is as simple as adding a new multi-line of text field.

The field has then been added into a section of the form.

Configuring FLOW

To tie together the Dynamics 365 email and the Cognitive Services, we are going to implement a FLOW. It will be triggered when an email is created, for the purpose of this I explanation I am going to trigger the FLOW when an email is created. In a production environment, I would suggest adding a number of parameters so that the flow only translates emails that are not in the source language.

The first step of the FLOW is to configure the trigger. FLOW has a number of out the box Dynamics 365 trigger points.

We are going to trigger this FLOW when an email record is created. We select the option “When a record is created.”

The organisation name is the Dynamics 365 instance you wish the FLOW to look at, and the entity is the name of the record that the FLOW should trigger against.

Email that is created in Dynamics 365 carries all of the HTML tags you would expect from an email. The translator service does not deal with HTML code therefor the first step the FLOW is going to undertake to convert the HTML message to plain text.

There is a FLOW function available to perform this task. We need to tell the function what text to convert, on the email record the email content is stored in the Description field.

FLOW has access to all of the fields on the triggering entity, so you are able to set this dynamically.

Once the FLOW has converted the HTML to plain text, we need to detect what the source language is that we are translating for. This information is required in order to allow the translate function to understand what language it needs to translate from.

FLOW is clever enough to keep the data from the previous step to allow you to pass it into the following functions.

We are now at the stage where the translation magic happens. The Translate text function is used, again we pass in the plain text from the previous steps and also the language which has been detected from the detect language function.

Now we have the translation held we now need to update the newly created field in Dynamics 365. We have to undertake this action in two steps. When an email is received into Dynamics 365 the record is created in an inactive state, therefore in order to update it we first have to reactivate it. This is done by calling the “Update a record” function.

Like on the record creation function we need to set a number of parameters including the Dynamics instance and the entity that we want to update. The other key parameter here is to pass the Email message that was identified in the first step to the function, so it knows which record to update.

Under Show advanced options we need to set the update we wish to occur. In this instance, we are going to update the status of the record to open.

We can now add a second update to the flow in order to update the translated text field and close the record again.

The updates have to be done in two different steps as it will try to perform all the updates in one action and if the record is inactive, it will not be able to update the translation field as it will reject due to the record being in an inactive state.

Conclusion

With the release of FLOW, you are able to easily implement functions that would have previously required substantial amounts of code. Combining flow with cognitive services allows you to call prebuilt AI features to enhance your user’s experience and workflows.

Additional Enhancements

Conditional Branches

You are able to add logic to your FLOWS using the condition function. This would be useful after the detect language function to ensure that you are not translating from English to English for example.

The other key branch that would be required is to detect if the email is incoming or outgoing as the FLOW detailed her will run against both and close the email message as completed.

Share

You may also like...

Leave a Reply