GuruGroup logo
Microsoft Dynamics 365 F&O Technical Guide

Creating Custom Services in Dynamics 365 Finance and Operations: A Comprehensive Guide

Executive Summary & Key Architectural Takeaways
  • Extensible Integration Framework: Exposing core Dynamics 365 Finance & Operations business logic externally via standardized REST endpoints.
  • X++ Service & Service Group Architecture: Developing service classes, binding operations in AOT, and grouping services into deployed endpoints under /api/services/.
  • Microsoft Entra ID (Azure AD) Security: Registering service applications, acquiring OAuth 2.0 Bearer tokens, and authorizing API access in D365FO.
  • JSON Parameter Contracts: Passing complex parameters (e.g. Sales Order and calculation amounts) and returning structured calculation payloads.
  • Postman Verification: End-to-end testing of authentication, token handling, and automated computation of computeTotalTax and computeOnlyTax operations.

Overview: Custom Services in Dynamics 365 F&O

In this blog post, we’ll explore the process of creating custom services in Dynamics 365 Finance and Operations, empowering you to extend the capabilities of your ERP system to meet the unique needs of your business. Whether you’re looking to integrate with external systems, automate processes, or enhance user experiences, custom services offer a flexible and powerful solution.

Custom Services Concept in D365FO
Figure 1: Custom service communication model connecting D365FO with external applications.

Let’s take a scenario where Dynamics is holding the data and that data can be exposed outside by using a service. We will explore how to create a service from Dynamics, expose it externally, and test it within Postman to ensure seamless third-party interaction.

Tools Required:

Visual Studio 2022

Visual Studio 2022 / D365 Developer Tools

For authoring X++ classes, services, and service groups in the AOT.

Postman API Platform

Postman API Client

For OAuth 2.0 token acquisition and RESTful service endpoint validation.

“Custom services provide the cleanest, most performant approach when external enterprise systems need to trigger transactional business logic inside D365FO and receive synchronous computation results.”

— Muhammad Haroon, Dynamics 365 & ERP Solutions Consultant
Architecture Comparison: OData Entities vs. Custom Services
OData Data Entities (CRUD-Focused) Best for standard entity record access, CRUD operations, and light data manipulation. However, running complex transactional business calculations through OData actions introduces performance overhead.
Custom Services (Logic-Focused) Ideal for running complex X++ algorithms (e.g., tax calculation, pricing engines, journal posting) with custom JSON request/response contracts and zero overhead on standard entity pipelines.

Step 1: Create Project & X++ Service Class

Open Visual Studio and create a new Dynamics 365 project:

Creating Visual Studio Project
Figure 2: Creating a new Dynamics 365 project in Visual Studio.
Project created in Solution Explorer
Figure 3: Project initialized in Solution Explorer.

Add a new class to your project by selecting Add > New Item > Dynamics 365 Items > Code > Class:

Adding Class to Project
Figure 4: Adding a new X++ class to the project.

Paste the following X++ code into the class. The class defines two service operations: computeTotalTax (returning total amount including tax) and computeOnlyTax (returning exclusively the computed tax amount):

internal final class CalculateTaxServiceClass
{
    public str computeTotalTax(str _salesOrder, RealBase _amount)
    {
        RealBase computedTotal = _amount + (_amount/10);
        return strFmt("Computed tax for sales order %1 with amount %2 is %3", _salesOrder, _amount, computedTotal);
    }
    public str computeOnlyTax(str _salesOrder, RealBase _amount)
    {
        RealBase computedTotal = _amount/10;
        return strFmt("Computed tax for sales order %1 with amount %2 is %3", _salesOrder, _amount, computedTotal);
 }
}
X++ Service Class Implementation
Figure 5: Service class implementation in Visual Studio editor.

Step 2: Create Service & Service Operations

Right-click your project, select Add > New Item > Dynamics 365 Items > Services > Service. In the service properties, specify your class name in the Class property:

Creating Service Node
Figure 6: Creating a Service node in the Visual Studio AOT.
Configuring Service Class Property
Figure 7: Setting the Class property on the Service node.

Next, create two Service Operations under the Service node matching the method names in your class:

Creating Service Operations
Figure 8: Creating service operations for computeTotalTax and computeOnlyTax.
Setting Operation Properties
Figure 9: Configuring the Method property on each service operation.

Step 3: Create Service Group & Deploy

To expose the service via HTTP REST endpoints, we must bundle it into a Service Group. Add a new Service Group item, drag and drop your Service into it, and set the properties:

Creating Service Group
Figure 10: Adding Service into the Service Group node.
Configuring Service Group Properties
Figure 11: Configuring Service Group properties for deployment.

Once built, the custom service endpoint follows the standardized Dynamics 365 URL pattern:

https://[DynamicsURL]/api/services/[ServiceGroup]/[Service]/[ServiceOperation]

Step 4: Register App in Microsoft Entra ID (Azure Portal)

Navigate to portal.azure.com to register the application that will authenticate API requests:

Navigating to Azure Portal
Figure 12: Navigating to App registrations in the Azure Portal.
Registering New App in Azure
Figure 13: Registering a new application for API access.

Record the Application (client) ID, Object ID, and Directory (tenant) ID:

Azure App Registration Overview
Figure 14: App overview page displaying Client ID and Tenant ID.

Configuring API Permissions

Click API permissions > Add a permission. Configure both Delegated and Application permissions for Dynamics ERP, and have your tenant administrator grant consent:

Adding API Permissions
Figure 15: Configuring delegated and application permissions.
Selecting Delegated Permissions
Figure 16: Selecting delegated API permissions for Dynamics ERP.
Selecting Application Permissions
Figure 17: Configuring application permissions.
Admin Consent Granted in Azure
Figure 18: Admin consent granted successfully for all configured permissions.

Generating Client Secret & Authorizing in D365FO

Navigate to Certificates & secrets, click New client secret, and copy the Secret Value:

Creating Client Secret
Figure 19: Creating a new client secret in Azure.

Now open D365FO, navigate to System administration > Setup > Microsoft Entra ID applications, and add the Client ID mapped to an authorized integration user ID:

Configuring Entra ID Application in D365FO
Figure 20: Registering the Client ID in Dynamics 365 Microsoft Entra ID applications setup.

Step 5: Testing & Verification via Postman

Launch Postman, create a workspace and collection, and configure an OAuth 2.0 token request using the Client Credentials flow:

Creating Workspace in Postman
Figure 21: Setting up an API testing workspace in Postman.
Configuring Token Request in Postman
Figure 22: Generating Azure AD OAuth 2.0 Bearer token via Postman.

Copy the returned Bearer Token. Now execute the POST request targeting the custom service endpoint:

POST https://[DynamicsURL]/api/services/CalculateTaxServiceGroup/CalculateTaxService/computeTotalTax
Calling computeTotalTax Service Operation
Figure 23: Executing computeTotalTax with JSON payload parameters.
Verifying computeTotalTax Output in Postman
Figure 24: Successful execution and return payload verifying total tax computation.

Similarly, execute the second service operation computeOnlyTax to verify tax-only calculations:

Calling computeOnlyTax in Postman
Figure 25: Executing computeOnlyTax and verifying returned tax value.
Ready to Move Forward?

Turn Your Business Goals into Measurable Results

Partner with Guru Group to design, deliver, and scale secure technology solutions for your organization.