[Low Code] Send Translated Message to User using App Notification

Today we will learn how to create a Dataverse Instant plug-in using the AITranslate function. The purpose of AITranslate is to translate a message to the targeted language. For today’s scenario, we will learn how to query the selected Dataverse User’s UI Language and send the translated message using XSendAppNotification. FYI, 2 years ago I once wrote a similar topic that consumed the Azure Cognitive Service and used it in Power Automate Flow which you can read here. Since then, we have had the option to use it directly in Dataverse which is exciting! 😎

For example, I have a user named Demo who set his UI Language to Indonesian:

UI Language set as "Bahasa Indonesia"

UI Language set as “Bahasa Indonesia”

To get this information, we need to retrieve from these 2 tables:

SQL4CDS Query to get language

SQL4CDS Query to get language

Here is the Query to get each user UI Language:

SELECT a.uilanguageid, b.language, b.code, a.systemuserid 
FROM usersettings a JOIN languagelocale b ON a.uilanguageid = b.localeid

Next, I created the below Dataverse Instant plug-in with below parameters and code:

Dataverse Instant plug-in

Dataverse Instant plug-in

Here is the full code from the above Instant plug-in (Dataverse Custom API):

XSendAppNotification(
 	AITranslate(Title, First(Filter(Languages, 'Locale ID'= First(Filter('User Settings', SystemUserId = To.User)).UILanguageId)).Code),
 	To,
 	AITranslate(Message, First(Filter(Languages, 'Locale ID'= First(Filter('User Settings', SystemUserId = To.User)).UILanguageId)).Code),
    []
 )

I’ll try to break it down for you the above PowerFx code. The important part for me is the query:

  1. First(Filter(‘User Settings’, SystemUserId = To.User)).UILanguageId which will retrieve the User Setting from the specified User and get the UILanguageId.
  2. First(Filter(Languages, ‘Locale ID’= #1)).Code which will help us to get the information of the Language Code. FYI, to specify the target language, we need to pass the code e.g.: en-us, id-id which you can read more about here. Luckily for us, this information is already defined in the Language table.
  3. Once we have the information, we can call AITranslate and pass the string message and the Language code #2.
  4. To make the XSendAppNotification work, we pass this information: Title, User, Message, and action. For today’s demonstration, we will not be sending any action.

As you can see from the code above, we need to call 2 times the AITranslate action. At first, I tried to join the Title and the Message and call the AITranslate function 1 time to make the function efficient. But, because of the limitation of the supported PowerFx commands that we have (or probably because my game on PowerFx is still very limited), I can’t do it.

To test it, I will just rely on the Test functionality of the Dataverse Accelerator App, and here is the result:

Demo

Demo

Happy CRM-ing!

Author: temmyraharjo

Microsoft Dynamics 365 Technical Consultant, KL Power Platform User Community Leader, Student Forever, Test Driven Development, and Human Code enthusiast.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.