I’ve written before about the telemetry data now available in D365FO, but is there a way to consume this telemetry data within the application itself? Let’s see how we could do this!

Problem Statement

In our case let’s see if we could automatically disable users that have not logged in within the last 90 days. We should be able to query the telemetry data, see which users have logged in within that time range, determine which users have not logged in, and then disable the affected users. To make this automated we could put this logic within a batch job to execute periodically.

Accessing Telemetry Data

As I wrote in my previous blog post there are a couple different ways to gain access to this data, in our case since we want to do this from a batch job the easiest way will be to use the Application Insights API which has an endpoint where we can execute a query we pass in.

For testing purposes I always test my queries in the Azure App Insights portal to ensure the correct results are returned. Here is the query we are using:

Project Setup

The project I came up with would contain two parts, one is a batch job to execute the user disable process on a set basis. The second is a .NET project to actually make the call to the App Insights telemetry data. The reason I did it this way was because the call to Azure’s App Insights is much easier done via C#/.NET because of the nuget packages available.

.NET Project Setup

On the .NET side I first took the query from above and allowed for the dynamic input of the number of days we wanted to execute the query for. I then perform the query and return the user Id and date time of the last usage of that user.

This is the class that is exposed to the X++ side (which is why it is ‘static’). In a real production version I would not store the client Id, client secret, or tenant Id values here but would instead look to use something like Azure Key Vault or some other secure way to store credentials. In this case the class returns a list of user Ids found to have logged in during a specified number of days.

Batch Job Setup

In this case, the batch job I created allows for a parameter input of the number of days we want to execute this process for. By default we are looking to find any user that has accessed the system within the last 90 days.

Once this set of users are found we compare that to all of the users within the UserInfo table, if a user exists in the UserInfo table but does not exist in the user result set from the telemetry data, we disable the user and commit that to the database.

Within D365FO

We can now navigate to the Batch Jobs form within D365FO and setup our batch job there. If we search for the class name from above (FpTelemeteryBatchJob) we can see the system can successfully find it and fills in the class description set in the batch job setup.

Since we allowed for parameters on this batch job, when you click on the ‘Parameters’ menu button you are able to provide a set number of days you would like to execute the batch job for.


While this is a fairly simple example, I hope this shows the overview of how you would be able to consume the Application Insight telemetry from within D365FO itself.

If you have any questions feel free to reach out.