January 24, 2025

Custom web service in D365FO - Part-I

Introduction

Custom services in Dynamics 365 Finance and Operations (D365FO) allow you to expose custom business logic and data to external systems. This first part of the blog post will walk you through the basics of creating and consuming custom services in D365FO. Custom services are used to expose X++ business logic to external systems via SOAP or RESTful endpoints. They are ideal for scenarios where you need to implement complex business processes that are not covered by standard services.

In later posts, we will discuss some complex scenarios and best practices around web services.

Architecture

Service Request Contract

The service contract defines the operations that the service will expose. This is done by creating a new class with the [DataContractAttribute] and [DataMemberAttribute] attributes. There must be two contract classes: one for the request message and another for the response message. (We will cover this in detail in future posts).

Example:

[DataContractAttribute]
public class TheAxaptaRequestContract
{
    private boolean isShipped;
    private String255 dataAreaId;
    private String255 storeNumber;
    private String255 trackingNumber1;

    [DataMember("TrackingNumber1")]
    public String255 parmTrackingNumber1(String255 _trackingNumber1 = trackingNumber1)
    {
        trackingNumber1 = _trackingNumber1;
        return trackingNumber1;
    }

    [DataMember("IsShipped")]
    public boolean parmIsShipped(boolean _isShipped = isShipped)
    {
        isShipped = _isShipped;
        return isShipped;
    }

    [DataMember("DataareaId")]
    public String255 parmdataAreaId(String255 _dataAreaId = dataAreaId)
    {
        dataAreaId = _dataAreaId;
        return dataAreaId;
    }

    [DataMember("StoreId")]
    public String255 parmStoreNumber(String255 _storeNumber = storeNumber)
    {
        storeNumber = _storeNumber;
        return storeNumber;
    }
}

Service Response Contract

Example:

[DataContractAttribute]
public class TheAxaptaResponseContract
{
    private boolean success;
    private str errorMessage;
    private str debugMessage;
    private System.String salesOrder;

    [DataMember("Message")]
    public str parmMessage(str _value = errorMessage)
    {
        if (!prmIsDefault(_value))
        {
            errorMessage = _value;
        }

        return errorMessage;
    }

    [DataMember("Success")]
    public Boolean parmSuccess(Boolean _value = success)
    {
        if (!prmIsDefault(_value))
        {
            success = _value;
        }

        return success;
    }

    [DataMember("DebugMessage")]
    public str parmDebugMessage(str _value = debugMessage)
    {
        if (!prmIsDefault(_value))
        {
            debugMessage = _value;
        }

        return debugMessage;
    }
}

Service Class

This is the class where the actual business operation executes. It takes the request message from the respective contract class and processes it to create a response message. Create a new class to implement the service. This class should extend the SysOperationServiceBase class and include the business logic for the service operations.

Example:

public class TheAxaptaService extends SysOperationServiceBase
{
    TheAxaptaResponseContract response = new TheAxaptaResponseContract ();
[AifCollectionType('salesOrder', Types::Class, classStr(TheAxaptaRequestContract)),
AifCollectionType('return', Types::Class, classStr(TheAxaptaResponseContract ))]
public processMsg() { TheAxaptaRequestContract request;
// Now you can access the parm methods of the request class to get different values from the request Str StoreId = request.paramStoreNumber(); response.parmSuccess(True); response.parmMessage("Message read"); } }

Register the Service

Register the service in the AOT (Application Object Tree) by creating a new service node. Set the class and method properties to point to your service implementation.

  1. In the AOT, right-click Services and select New Service. (e.g. TheAxaptaInterface)
  2. Set the Class property to your service class (e.g., TheAxaptaService).
  3. Set the Method property to the service method (e.g., processMsg).

Deploy the Service

Deploy the service to make it available for consumption. This can be done by right-clicking the service node in the AOT and selecting Deploy Service Group.

Consume the Service

A third part can consume this service using the below syntax

<EnvironmentURL>/API/services/TheAxaptaInterface/TheAxaptaService/processMsg

and send the request message in body.

If you want to setup postman to test your services by yourself, I would recommend to checkout this blog post, 

Here is complete code uploaded on Git Repository

December 16, 2024

Error while converting .bak file to backpac

Hi Folks, 

I have to restore the Sandbox DB to dev box and was trying SqlPackage utility for the same, 
I Tried with below command, 

SqlPackage.exe /a:export /ssn:localhost /sdn:AxDB.bak /tf:J:\Capgemini\AxDB.bacpac /p:CommandTimeout=1200 /p:VerifyFullTextDocumentTypesSupported=false /SourceTrustServerCertificate:True

But Got error as below

Can you please try below ways


Option 1: (Remove extension from source database)
SqlPackage.exe /a:export /ssn:localhost /sdn:AxDB /tf:J:\theaxapta\AxDB.bacpac /p:CommandTimeout=1200 /p:VerifyFullTextDocumentTypesSupported=false /SourceTrustServerCertificate:True

 

Option 2: (Along with that use user name and password)
SqlPackage.exe /a:export /ssn:localhost /sdn:AxDB /su:axdbadmin /sp:XXXX /tf:J:\Capgemini\AxDB.bacpac /p:CommandTimeout=1200 /p:VerifyFullTextDocumentTypesSupported=false /SourceTrustServerCertificate:True

-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta

October 29, 2024

[Solved] Service update 10.0.40 The specified module 'C:\Program Files\Microsoft Security Client\MpProvider


Service update 10.0.40 The specified module 'C:\Program Files\Microsoft Security Client\MpProvider





Log file error: The specified module 'C:\Program Files\Microsoft Security Client\MpProvider' was not loaded because no valid module file was found in any module directory.

Suggested solution:

Do a get latest on your VM and full build and synch, once system is error free try to resume this. 

-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta

September 03, 2024

Installing Planning Optimization Add ins in D365FO

Hi Folks, 

In this post lets understand how we can enable Planning optimization in D365FO sandbox. 

What is Master planning

Master planning fundamentally enables companies to forecast and align the future demand for raw materials and capacity with their objectives. It evaluates:

Current Availability: What raw materials and capacities are presently on hand?
Required Resources: What raw materials and capacities are needed to finalize production? 

This includes items that must be manufactured, purchased, transferred, or reserved as safety stock.
Using this data, master planning calculates the necessary requirements and generates planned orders.

For more details check Master planning home page

Prerequisite: Ensure the following prerequisites are met before installing the Planning Optimization Add-in:
  • Only works on an LCS-enabled high-availability environment (tier 2 or higher). OneBox environments are not supported.
  • Ensure your system is set up for Power Platform integration.
  • Your Microsoft Entra account must have a Supply Chain Management license. No extra license is needed for Planning Optimization, but a Supply Chain Management license is required.
  • Sign in to your Power Platform environment with an account that has administrator privileges and Read-Write access.
  • All the steps should be followed by one admin user.
Installing the Add-in

1. Check the right environment and verify current status of this, you can do this as showing in below image. 



2. Login into LCS with admin access and navigate to respective Sandbox environment. Under Power platform Integration, click on Setup, this is step to Install Power Platform Environment (not actual Add in yet)




Next screen,  Here you will see two template available, I would recommend to use with dual write so you still have option to use more features of it while doing this setup once. Here is quick difference in both

'Dynamics 365 standard' means this Finance and Operations environment will be connected to a Power Platform environment with Data verse. While Platform solutions for Dual-write and Virtual Entities will also be installed but not enabled. Data will not be written via Dual-write to the Power Platform environment by default, but can be configured to do so as part of a later step.'



You will be asked for confirmation and verification as this step can be reversed, so make sure you are on the right environment with right requirement. 

This step may take an hours to finish. Once this step is finish you will see Environment URI available there which means the Power plateform is configured for this environment. 

3. [This is an option step, as we are not using Dual write for this Add in]The next step is to Enable Dual write connection to start synch with Dataverse. (And  yes you are not along in this NAME changing game, we all are same boat dealing with new names every year , Almost.) 

4. Now when we have connected with Power platform environment, you are ready to install Add-ins.


Click on 'Install a new add-in' , you will a list of all available solutions/Add-in to install on this environment. Scroll to bottom in list and you will find 'Planning optimization', select that


And on next screen click on Install button. It will start the installation. Again it may take just few mins to finish. Once done you can see this under 'power Platform Intergation' tab in LCS environment page. 


5. Now lets validate things, Login to FO environment and Navigate to 'Master Planning > Setup > Planning Optimization Parameters'. You will find connection status = Connected. 




Common Issues and tips:
1. Missing user permissions: 
If you get an error message regarding missing user permissions while installing the Planning Optimization Add-in, follow these steps: (Validation failed. You must be an environment administrator in Microsoft Dataverse to perform this action. If the issue persists please contact Microsoft support)

Go to the Power Platform admin center.
Open the environment where you want to install the add-in.
Go to Settings > Users and select your user account from the list to see its details.
From your user details page, select the Client Access License (CAL) information link.
On the Client Access License (CAL) information page, make sure that Access Mode is set to Read-Write.

2. Enable configuration key
Put your system into maintenance mode from LCS portal.
Go to System administration > Setup > License configuration.
On the Configuration keys tab, select the check box for Planning Optimization.
Turn off maintenance mode.

3. Connection Status is not showing Connected
If the Connection stats is Connected, then you're ready to enable Planning Optimization. Use the Use Planning Optimization option to choose which planning engine is used for master planning. Below are other option you may see and what's the meaning of each, 

Read more:

-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta