Dynamics 365 Business Central telemetry report as Adaptive Card on Teams

During my telemetry session at last Directions EMEA in Hamburg and also on my latest Telemetry workshop in Microsoft Italy some weeks ago, when talking about being proactive with Dynamics 365 Business Central telemetry data, I’ve done a demo creating advanced alerts and one of them used Teams as a channel to redirect notifications of tenant’s anomalies.

The created alert used Azure Logic Apps for sending a Teams message when a job queue task fails on Dynamics 365 Business Central. After the demo, some of you asked the following question: is it possible to receive in Teams a summary of failures? Instead of receiving a message on every failure, I would like to receive a table showing the Job Queue tasks failed in the last N hours.

I promised a solution after the conference and the live training events and here it is…

To send a message in Teams with the possibility to format the appearance and also to have interactions with the notifications, I think that the best way is by using Adaptive Cards.

Adaptive Cards are actionable snippets of content that you can add to a conversation through a bot or message extension. Using text, graphics, and buttons, these cards provide rich communication to your audience. The Adaptive Card framework is used across many Microsoft products, including Teams.

Adaptive Cards are a platform-agnostic method of sharing and displaying blocks of information without the complexity of customizing CSS or HTML to render them. You author Adaptive Cards in JSON format and when delivered to a specific host, such as Microsoft Teams, the JSON is transformed into native UI that automatically adapts to its host. Therefore, process designers can now offer consistent UI patterns whenever they need to display information as part of a business process/automation.

What I would like to do here is the following:

  • My Azure Logic Apps-based alert will run the KQL query on my Azure Application Insights instance to discover job queue failures
  • If there are failed job queue tasks, the Logic Apps creates an Adaptive Card that includes an header, a descriptive text and a table of data (list of failed tasks with details)
  • The Adaptive Card is sent to a Teams channel

My KQL query that shows the failed job queue tasks on my Dynamics 365 Business Central tenant gives the following output:

and I would like to send on Teams an Adaptive Card showing a table listing the Object Type and Object Id of the job queue tasks failed.

To design an Adaptive Card and discover how the JSON is composed (various building blocks etc) I suggest to go to https://adaptivecards.io/designer/ and start creating. Here I’ve created a simple Adaptive Card with a ColumnSet of 2 columns:

When you have discovered the JSON format, the process of creating the Adaptive Card via an Azure Logic Apps workflow (or you can use Power Automate too) could appear quite easy, but in the real world it’s not so simple and it requires some steps. The main problem here is that my Adaptive Card must display tabular data in a dynamic way (I don’t know how many tasks are failed, so how many rows are returned by my KQL query).

The full Azure Logic Apps workflow is defined as follows:

In this workflow I’m initializing 2 array variables and to each variable I append the column definition in JSON format accordingly to the Adaptive Card column format (first row of the ColumnSet) using the Append to array variable action:

This creates the column titles.

Now for each records returned by the KQL query on my Azure Application Insights instance, I use the Compose action for creating the TextBlock object for each returned value. On each TextBlock I’m dynamically passing the KQL field to display (ObjectType and ObjectId fields returned by the KQL query):

Then I need the final Compose action (outside the For Each loop) for creating the final Adaptive card JSON schema. Here I’m using ther JSON schema from the Adaptive Card designer and then I’m injecting the columns dynamically defined in the previous actions:

In the last workflow step, I use the Post adaptive card in a chat or channel action of the Teams connector for sending the Adaptive card to my Teams channel:

That’s all!

If you run the workflow, this is the result on your Teams channel:

Obviously you can improve the Adaptive Card table with more details, but now you have a more elegant notification on your Teams channel.

The complete workflow is deployed as an ARM template here: https://github.com/demiliani/D365BCTelemetry and you can directly deploy it in your Azure Subscription.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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