Proactive License Validation in Dynamics 365: Streamlining with RetrieveUserLicenseInfoRequest

By | July 9, 2025

Proactive License Validation in Dynamics 365 Streamlining with RetrieveUserLicenseInfoRequest

Introduction

While working on a recent feature for one of our Dynamics 365 solutions, we ran into an issue where users with the right security roles were still facing unexpected “access denied” errors. After some investigation, we realized the root cause wasn’t missing permissions—it was missing licenses. This highlighted a common gap in how ISVs and organizations manage access: relying solely on security roles without validating whether users have the required Dynamics 365 or Power Platform licenses.

In Microsoft Dynamics 365 and Power Platform, managing user access effectively is critical for ensuring a seamless user experience and maintaining license compliance. Traditionally, organizations use security roles to manage and restrict access to various features and entities. However, this approach can fall short when a user’s license, rather than their role, determines their ability to perform certain actions.

For example, a user might have the correct security role but still face “access denied” errors if they lack the appropriate Dynamics 365 or Power Platform license (e.g., DYN365_SALES_PRO or POWERAPPS_DYN_APPS). This can lead to vague error messages, user frustration, and increased support overhead.

ISVs often create custom roles to manage access to their solutions, but this becomes inefficient when users without valid licenses, such as service accounts or non-CRM users, end up assigned those roles. Until now, there was no straightforward way to programmatically check a user’s license status. That’s when we discovered RetrieveUserLicenseInfoRequest, a powerful request that allows developers to retrieve detailed license information for any user and use it to enforce license-based logic more reliably.

In this blog, we’ll explore how RetrieveUserLicenseInfoRequest can be used to validate licenses, share practical server-side and client-side implementation examples, and highlight the benefits of proactive license validation for any Dynamics 365 environment.

Approach: Enhancing Dynamics 365 Solutions with License Validation

Proactive license validation ensures users have the required licenses (e.g., DYN365_SALES_PRO, DYN365_ENTERPRISE, or POWERAPPS_DYN_APPS) before accessing features. This is valuable for organizations and ISVs managing complex user environments or custom applications.

Understanding RetrieveUserLicenseInfoRequest

The RetrieveUserLicenseInfoRequest class, from Microsoft.Crm.Sdk.Messages namespace, retrieves a user’s license information to validate access to features or entities, ensuring compliance and preventing errors. The RetrieveUserLicenseInfoResponse returns detailed license data for verification.

  • RetrieveUserLicenseInfoRequest Properties:

SystemUserId (Guid): The user’s unique ID for the license check.

  • RetrieveUserLicenseInfoResponse Properties:

licenseInfo (LicenseInfo): Contains the user’s license details.

           a. ServicePlans (Collection of ServicePlan): Lists licenses with:

1. Name (String): License internal name (e.g., “DYN365_SALES_PRO”).

2. DisplayName (String): User-friendly name (e.g., “Dynamics 365 Sales Professional”).

By integrating RetrieveUserLicenseInfoRequest, you can validate licenses server-side (in plugins) or client-side (in model-driven apps), offering flexibility for various scenarios.

Server-Side License Validation

For server-side validation, developers can incorporate license checks into plugins to ensure users have the required licenses before performing operations. Below is a code snippet demonstrating how to use RetrieveUserLicenseInfoRequest in a plugin:

try
{
tracingService.Trace("Checking license for user ID: {0}", context.UserId);
var request = new RetrieveUserLicenseInfoRequest { SystemUserId = context.UserId };
var licenseResponse= (RetrieveUserLicenseInfoResponse)service.Execute(request);
// Trace the license information for debugging
if (licenseResponse?.licenseInfo?.ServicePlans != null)
{
_tracingService.Trace($"Found {licenseResponse.licenseInfo.ServicePlans.Count} service plans for user {userId}:");
foreach (var plan in licenseResponse.licenseInfo.ServicePlans)
{
_tracingService.Trace($"Service Plan - Name: {plan.Name}, DisplayName: {plan.DisplayName}");
}
}
else
{
_tracingService.Trace("licenseResponse or ServicePlans is null.");
}
_tracingService.Trace("RetrieveUserLicenseInfoRequest executed successfully.");
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException($"License check failed: {ex.Message}");
}

Trace Output:

Proactive License Validation in Dynamics 365

Client-Side License Validation with Web API

For client-side applications, such as JavaScript-based customizations in model-driven apps, Developers can use the Dynamics 365 Web API to call the RetrieveUserLicenseInfo function.

This enables license validation in scenarios where server-side plugins are not applicable. Below is a code snippet demonstrating how to perform license validation via the Web API.

async function checkUserLicense(systemUserId) {
const orgUrl = Xrm.Utility.getGlobalContext().getClientUrl() + '/api/data/v9.2/';
systemUserId = systemUserId || Xrm.Utility.getGlobalContext().userSettings.userId.replace(/[{}]/g, '');
const requestUrl = new      URL(`systemusers(${systemUserId})/Microsoft.Dynamics.CRM.RetrieveUserLicenseInfo`, orgUrl);
const response = await fetch(requestUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'OData-MaxVersion': '4.0',
'OData-Version': '4.0'
}
});
const data = await response.json();
const hasValidLicense = data.licenseInfo?.ServicePlans?.some(sp => ['DYN365_SALES_PRO', 'DYN365_ENTERPRISE', 'POWERAPPS_DYN_APPS'].includes(sp.Name));
if (!hasValidLicense) {
throw new Error('You do not have the necessary license to use this feature.');
}
return true;
}

Usage Tip: Call checkUserLicense() in the form’s onload events or ribbon button actions to validate licenses before enabling features.

Conclusion: Real Productivity Gains

By integrating RetrieveUserLicenseInfoRequest, organizations can build a robust and reliable licensing framework for Dynamics 365 and Power Platform. This approach ensures users have the appropriate licenses (e.g., DYN365_SALES_PRO, DYN365_ENTERPRISE, or POWERAPPS_DYN_APPS) to access features seamlessly, enhancing user satisfaction and operational efficiency.

Key benefits include:

  • Streamlined Access Control: Validates licenses upfront, ensuring users can perform intended actions without disruptions.
  • Enhanced Compliance: Ensures adherence to licensing requirements, supporting governance and auditability.
  • Adaptable Implementation: Offers flexible integration for plugins, scripts, or custom applications.

For Dynamics 365 developers, administrators, or ISVs, RetrieveUserLicenseInfoRequest is a vital tool for creating a dependable and user-centric licensing strategy. Try implementing this solution and share your experience in the comments!

Category: Dynamics 365 v9 Technical Tags:

About Sam Kumar

Sam Kumar is the Vice President of Marketing at Inogic, a Microsoft Gold ISV Partner renowned for its innovative apps for Dynamics 365 CRM and Power Apps. With a rich history in Dynamics 365 and Power Platform development, Sam leads a team of certified CRM developers dedicated to pioneering cutting-edge technologies with Copilot and Azure AI the latest additions. Passionate about transforming the CRM industry, Sam’s insights and leadership drive Inogic’s mission to change the “Dynamics” of CRM.