Skip to main content

Notifications

Announcements

No record found.

Using Azure Application Insights to monitor license usage in D365 Finance and Operations

The licensing related reports in D365FO can provide license assignment information but they don't really tell us if the user that is assigned a particular license type is using it. For example, you can navigate to Modules > System administration - Inquiries - License (User license counts report) and License reports (User license estimator report) and these reports can tell you what license type a user should have based on the security role they are in. 

The business case I will use for this blog post is the following: You have determined a custom role or a user in the Accounts payable clerk role uses the Vendor invoice form to maintain invoices. The menu item requires a Finance license when you view the Security configuration form. One of the core business processes in this use case example, is to work with vendor invoices by creating and editing them and submitting them to workflow. The business concern is that maybe some users have this license and are not using the functionality enough or at all to justify the license cost. So how can we determine this using data points? Keep in mind that you can use the license reports to see what other license types you are interested in. For example, you may want to check into the usage of Operations and SCM licenses. This type of licensing information is in the D365 licensing guide here and the MS Docs site

One approach to utilizing real data is we can log to Azure Application Insights when users access menu items for this role. In our case, we will log an entry when the VendEditInvoice form is initialized. This form is known as the Pending vendor invoice form. Let's get this to work using the below steps:

Create the Application Insights instance

1. In the Azure portal search for Application Insights and select it:

1033.App-Insights-Search.png

2. Click the Create button which will allow you to enter the resource group, name, region, subscription, and workspace.

3. After it is created there is an Instrumentation Key value that will allow you to connect to it. This is a value that you could store encrypted in a parameter table in D365FO.

7713.App-Insights-Instrumentation-Key-value.png

 

Create the Application Insights C# library

1. Create a C# Class Library project that will allow you to write to the Application Insights instance when the Pending vendor invoice form is initialized. The project will need to use the Microsoft Application Insights Base API package that you can install from using the NuGet Package Manager. After installing the package, you will see a reference to the Microsoft.ApplicationInsights.dll library in the Class Library project.

App-Insights-Base-Package.png

7318.ApplicationInsightsReference.png

2. The code is very minimal that you can use to start writing events to the Application Insights instance. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#trackevent
using Microsoft.ApplicationInsights;

namespace CPR.Integration.Telemetry
{
    public class D365FOLogger
    {
        string          apiKey;
        TelemetryClient telemClient;

        public D365FOLogger(string _apiKey, string _userId, int _sessionId)
        {
            apiKey = _apiKey;

            telemClient = new TelemetryClient();
            
            telemClient.InstrumentationKey = apiKey;
            telemClient.Context.User.Id = _userId;
            telemClient.Context.Session.Id = String.Format("{0}", _sessionId);
        }

        public void trackPageView(string _formName)
        {
            telemClient.TrackPageView(_formName);            
        }

    }
}

The Finance Operations project

1. One approach is to use a Form extension class on the VendEditInvoice form like below. The below custom code will run after all calls to the init method are executed. Also, it would be a good idea to use a parameter table where you can enable\disable the logging to Application Insights. Something like the screen shot below.

using CPR.Integration.Telemetry;

[ExtensionOf(formStr(VendEditInvoice))]
internal final class CPR_VendEditInvoice_Form_Extension
{    
    void init()
    {
        next init();

        // Log to application insights if enabled
        AppInsightsParameters appInsParams = AppInsightsParameters::find();
        if (appInsParams.AppInsightsEnabled)
        {
            D365FOLogger logger = new CPR.Integration.Telemetry.D365FOLogger(appInsParams.AppInsightsKey, curUserId(), SessionId());

            logger.trackPageView(this.form().name());
        }
    }

}

The Finance Operations project will have a reference to the C# library project and the code from the C# library can be leveraged in the X code with a using statement like above. Below are screen shots of the References folder in the Finance Operations project and the References node in the Application Explorer. When you add a reference to a .NET project in a Finance Operations project, the DLL is added to the References node in your custom model (Package).

6761.CsharpLibReference.png

4034.ReferencesNode.png

 loggingparams.png

Viewing the Application Insights Data

There are many ways to view the data once it is captured. You can see it fairly quick by going to the Application Insights instance in Azure Portal and selecting Events. In this screen shot you can see the user initialized the VendEditInvoice form 11 times in the past 30 days.

30-day-view.png

What do you think about this approach of using Application Insights for solving these types of licensing usage concerns? I hope this has given you some ideas on how to tackle this type of question or maybe sparked another type of use case for Application Insights integration with Finance and Operations.

P.S. - I would like to thank Ryan Sandness for assistance on this post also.

Comments

*This post is locked for comments