MES Integration with Dynamics 365 for Supply Chain Management
Microsoft Dynamics 365 Supply Chain Management has native functionality in Dynamics 365 to control manufacturing activities for machines, equipment, and personnel. However, some manufacturing organizations, use a third-party manufacturing execution system (MES) to support their advanced manufacturing requirements.
For those organizations that use the native production shop floor experience, here are the steps to configure the interface.
In this blog post, I will focus on Integrating 3rd part MES to D365 SCM using the new MES integration Framework. This framework reduces overall implementation and operating costs. It helps manufacturers to establish end-to-end visibility and control over the production floor.
In the integrated solution, data exchange is fully automated and near real-time, which keeps data current in both systems and eliminates the need for manual data entry.
To use this Framework, we need to enable the feature in Feature Management Workspace:
- Go to?System administration > Setup > License configuration.
- Make sure that the?Time and attendance?license key is enabled (shows a checkmark). This license key is required because it controls the manufacturing execution system's functionality and data. If it isn't enabled, do the following steps:
- Put your system into maintenance mode, as described in?Maintenance mode.
- On the?License configuration?page, select the?Time and attendance?check box.
- Turn off maintenance mode, as described in?Maintenance mode
- Go to the?System administration > Workspaces > Feature management.
- Turn on the feature that is listed in the following way:
- Module:?Production control
- Feature name:?Manufacturing execution system integration
To receive notifications to the MES system when a Production Order is Released the framework includes a business event Production Order Released. The business events catalog can be accessed from?System administration > Set up > Business events.
Business events can be consumed using Power Automate, Service Bus, Event Grid, or other endpoint types. I am using the Azure Service Bus endpoint to notify the MES.
Configure Azure Service Bus as Endpoint for Business Event:
- Create a new Service Bus namespace
- Sign in to the Azure portal.
- Select All services > Integration > Service Bus.
- Select Add to create a new Service Bus namespace and set the parameters. Select the Standard pricing tier. You can create a new resource group, or you can use an existing resource group.
- When you've finished setting all the parameters, select Review+Create, Then Create.
2. Create a new Service Bus Queue
a. In the Azure portal, select the Service Bus that you just created, and then create a new queue.
b. Navigate to Shared access policies, click RootManageSharedAccessKey (or create a new policy with the necessary permissions), and copy the Primary or Secondary Connection String.
3. Set up the Azure Active Directory (Azure AD) application ID and application secret
a. Go to App registrations in the Azure Portal and click + New registration. Give your app a name and click Register.
b. Open the app you just created in Azure Portal and navigate to Certificates & secrets. Click + New client secret, give it a description and click Add.
c. Save the Secret value, we need to use it later. It will be visible only once.
4. Create a new key vault
a. In the Azure portal, select?All services > Security > Key vaults.
b. Create a new key vault in your resource group and set the default parameters.
c. Click Next: Access policy.
d. Click + Add Access Policy. Under Configure from template, select Secret management. Under Principal, select the Application ID of the app from step 1. Click Review + create and Create
e. One Key Vault is created. Select?Overview, then copy and save the?Vault URI?value for the key vault. You will use this value later.
f. Click Secrets > Generate/Import. Enter a name for your secret, and paste the Service Bus connection string that you saved earlier.
5. Create an Azure Service Bus Queue endpoint
a.On the?Business events?page, on the?Endpoints?tab, select?New?to create an endpoint.
b. In the?Configure new endpoint?dialog box, in the?Endpoint type?field, select the appropriate endpoint type. To create an endpoint to a Service Bus queue, select?Azure Service Bus Queue.
c. Select?Next.
d. Give the Endpoint a name, then enter the Queue name from Step 2, Service Bus SKU from Step 1, Azure Active Directory application ID, and secret from Step 3.
e. For the Key Vault DNS name copy the Vault URI from the Overview page of the Key vault and the secret name created in Step 4.
f. Click OK - this will send a test message to the queue. To verify that the message has been received, Go to the Azure Service Bus Queue you created earlier and verify that the message count shows a value of 1.
g. Navigate back to the Business event catalog tab, select the BusinessEventsAlertEvent and the ProductionOrderReleasedBusinessEvent and click + Activate. Select the Legal entity (e.g. USMF) and the Endpoint you just created, and click OK.
Consume the Business Event
You can include the service Bus Listener logic in your application or You can use Logic App to send a notification when a message is received in Service Bus. Here are the steps to use the logic app.
Test the MES Integration Framework using third party Utilities Like Postman
Before you can test a service by using an external application, you must register the application in Microsoft Azure, and in Finance and Operations.
- Go to App registrations in the Azure Portal and click + New registration. Give your app a name and click Register.
- Open the app you just created in Azure Portal and navigate to Certificates & secrets. Click + New client secret, give it a description, and click Add.
- Save the Secret value, we need to use it later. It will be visible only once.
- Click on API permissions, Add Permission and select Dynamics ERP under Microsoft APIs and grant the permissions as below.
- In D365 SCM, go to?System administration?>?Setup?>?Azure Active Directory applications.
- Select?New.
- Fill in the fields for the new record:
- In the?Client Id?field, enter the application ID that you registered in Azure AD.
- In the?Name?field, enter a name for the application.
- In the?User ID?field, select an appropriate service account user ID. For this example, we have selected the?Admin?user. However, as a better practice, you should provision a dedicated service account that has the correct permissions for the operations that must be performed.
- When you've finished, select?Save.
Acquire Access token to access D365 SCM from Postman:
- Start Postman.
- create an environment. Enter a name for the environment
- Add the following Environment variables:
Variable |
Value |
tenant_id |
The Azure tenant ID that you looked up during the setup of prerequisites |
client_id |
The Azure AD application ID that you registered during the setup of prerequisites |
client_secret |
The secret key that you generated during application registration during the setup of prerequisites |
grant_type |
client_credentials |
resource |
The base URL of the instance without the trailing '/' |
4. To retrieve an Azure AD token, create a POST request that has a URL in the format?https://login.microsoftonline.com/[tenant ID]/oauth2/token.
5. On the?Body?tab, add body elements as request parameters that refer to the environment variables that you created earlier. Select?Bulk Edit, enter the keys from the previous table, enter a colon (:), and then enter the key name again but enclose it in double braces ({{}}). Enter one request parameter per line. For example, enter?grant_type:{{grant_type}}. Here is an example.
6. On the?Tests?tab, create a test that validates that the response is reasonable, and that stores the returned authorization token in an environment variable. Here is an example.
C#
var json = JSON.parse(responseBody);
tests["Get Azure AD Token"] = !json.error && responseBody !== '' && responseBody !== '{}' && json.access_token !== '';
postman.setEnvironmentVariable("bearerToken", json.access_token);
7. Select?Save, enter a name and collection for the request, and then select?Save?again.
8. Select?Send?to make the authorization request. The?Body?tab should now contain an Azure AD token together with other response details.
9. Because of the test code, the token is now in an environment variable. You can see that the token is an environment variable by selecting the?Environment quick look?button.
Test MES messages to D365 SCM using Postman
The following diagram shows a typical collection of business events, processes, and messages that are exchanged in an integrated solution.
To call the MES integration API, send a POST request to the following endpoint URL:
baseURL/api/services/SysMessageServices/SysMessageService/SendMessage
The body of the request should resemble the following format.
Depending on the message you want to send to D365 SCM from MES, create a POST request with the same URL and update the _messageType and _messageContent parameters in the body of the request. Here are the different message formats that could be sent to the D365 SCM from MES.
Once you send the above message successfully, the message is available in the Message dashboard in D365 SCM. In D365 SCM, go to?Production Control?>?Setup?>?Manufacturing Execution > Manufacturing Execution System Integration.
As shown below the message dashboard contains all the messages with their status and log. It also shows the message content which helps troubleshoot any slips.
We can have a Batch Job that processes these messages(SysMessageProcessor) at a set recurrence, I had it disabled to show the queue and different message statuses. To manually process the message, we can click process. For messages like Picking List, we also have the option to create and post journals manually from the dashboard.
Once the message is Processed, the production Order status changes to Started in D365 SCM.
This is how the MES Integration Framework feature makes it faster, easier, and cheaper for Supply Chain Management users to integrate with third-party MESs.
Additional resources:
*This post is locked for comments