How to create custom services in Dynamics 365 Finance and Operations

September 3, 2024

In the modern business landscape, companies must go beyond out-of-the-box features to address unique processes and challenges. Custom solutions ensure seamless integration between ERP systems and third-party applications. This customization is vital for maintaining operational efficiency and data accuracy, aligning with organizational needs, and driving success.

If your organization uses Microsoft Dynamics 365 Finance and Operations ERP, Dynamics 365 custom services offer powerful capabilities to facilitate system integrations through custom services.

Looking to implement integration scenarios? This blog explores the essentials of creating and utilizing Dynamics 365 F&O custom services, allowing you to extend the platform’s functionality and streamline data exchanges.

Understanding custom services in Dynamics 365 Finance and Operations

Custom services in Dynamics 365 Finance and Operations enable developers to expose custom business logic via service endpoints. These endpoints facilitate the integration of external systems with Dynamics 365 Finance and Operations, offering a standardized method for data exchange. Custom services are especially useful for scenarios that require specialized business logic beyond the capabilities of standard data entities. Dynamics 365 Finance and Operations integration with other systems enhances operational efficiency and benefits businesses in several ways.

Implementing Microsoft Dynamics 365 for Finance and Operations apps, including PDF resources and free downloads, is essential for comprehensive solutions.

Benefits of custom services in Dynamics 365 F&O

Before we dive into the steps of creating custom services in Dynamics 365 Finance and Operations, let’s look at the benefits:

  • Flexibility: Customize data exchange processes using Dynamics 365 Finance and Operations custom development to meet specific business needs. By implementing bespoke solutions, you ensure the system aligns perfectly with your needs.
  • Efficiency: Streamlined data transfer processes enhance overall operational efficiency and minimize errors.
  • Scalability: Easily scale to accommodate growing data integration needs with custom Dynamics 365 Finance and Operations extensions and Dynamics 365 Finance and Operations APIs.
  • Security: Leverage the robust security features of Dynamics 365 F&O to protect data integrity and confidentiality by following best practices for customizing Dynamics 365 Finance and Operations.

Steps to create custom services in Dynamics 365 Finance and Operations

A custom service that is deployed in Dynamics 365 acts similarly to an API. Dynamics 365 custom service is deployed at the two endpoints: JSON and SOAP. In this blog, we will focus on the JSON-based custom service.

This feature allows X++ classes to be used as JSON services, meaning the returned data is formatted in JSON format. JSON, or JavaScript Object Notation, is a compact and lightweight format widely used for data exchange between clients and servers.

Now let’s dive into the steps to create Dynamics 365 custom services:

Step 1: Define the service contract

A service contract in Dynamics 365 Finance and Operations is defined using Data Contracts, which specify the data structure to be exchanged. To define the service contract, follow these steps:

  1. In Visual Studio, open your Dynamics 365 project.
  2. Right-click on your project and select Add > New Item.
  3. Choose Dynamics 365 Items > Class and name it MyCustomContract.

Here is a sample X++ code:

Step 2: Implement the service operations

Service operations contain the business logic to be executed. They are implemented in classes with methods marked with specific attributes. To implement service operations:

  1. Right-click on your project and select Add > New Item.
  2. Choose Dynamics 365 Items > Class and name it MyCustomService.

Here is a sample X++ code: 

Step 3: Create the service and service group

To make the service available, you must create a service definition and service group in the Application Object Tree (AOT) using Visual Studio.

Creating service definition

  1. Right-click on your project and select Add > New Item.
  2. Choose Dynamics 365 Items > Service and name it MyCustomService.
  3. Select the class in service properties.
  4. Add a new service operation and name it MyServiceMethod.
  5. Select method “MyServiceMethod” in service operation properties.

Creating service group

  1. Right-click on your project and select Add > New Item.
  2. Choose Dynamics 365 Items > Service Group and name it MyCustomServiceGroup.
  3. Add your service to the service group in the MyCustomServiceGroup.

Step 4: Deploy and consume the service

Once registered, deploy the service and generate the necessary artifacts. External systems can consume the service via standard protocols like REST.

Calling Custom Services with Postman (A testing technique)

After completing the initial Dynamics 365 Finance and Operations development, which results in an API, thorough testing is essential. Among the various tools available for API testing, Postman stands out as a popular choice. Here’s a guide on how to use Postman to call your custom services in Dynamics 365 Finance and Operations.

1: Get the authentication token

Request: POST https://login.microsoftonline.com/{tenant}/oauth2/token
Headers: Content-Type: application/x-www-form-urlencoded
Body (x-www-form-urlencoded):

  • grant_type: client_credentials
  • client_id: your-client-id
  • client_secret: your-client-secret
  • resource: https://your-dynamics-url 

Response: Access token

2: Call the custom service

Request: POST https://your-dynamics-url/api/services/MyCustomServiceGroup/MyCustomService/MyServiceMethod
Headers:

  • Authorization: Bearer {access_token}
  • Content-Type: application/json

Body (raw JSON):

Response:

JSON

Best practices for creating custom services in Dynamics 365 Finance and Operations

  • Design for performance: Optimize the service logic for high performance, especially for large data volumes.
  • Ensure robust error handling: Implement comprehensive error handling to manage and log exceptions gracefully.
  • Secure your services: Use role-based security and encryption to protect data integrity and privacy.
  • Maintain documentation: Document your custom services thoroughly to facilitate maintenance and future enhancements.

Use cases of Dynamics 365 custom services

Custom services in Dynamics 365 can be applied across various use cases to address specific business needs and enhance system capabilities. Here are some common use cases:

  • Third-party integrations: Integrate with third-party logistics providers to automate shipment tracking and updates.
  • Custom reporting solutions: Aggregate data from various sources and expose it through custom services for advanced reporting tools.
  • Mobile applications: Integrate with third-party logistics providers to automate shipment tracking and updates.

Final words

Dynamics 365 Finance and Operations integration through custom services provides a powerful mechanism to extend the ERP’s capabilities, enabling seamless and secure data integration. By following best practices and leveraging the flexibility of custom services, businesses can enhance their operational efficiency and responsiveness in an ever-evolving digital landscape.

For any queries about customizing Dynamics 365, including creating custom services in Dynamics 365 Finance and Operations or Dynamics 365 Finance and Operations implementation, please reach out to us at marketing@confiz.com.