Business Events with an Azure Function and the HTTPS endpoint
I recommended everybody read Todd Jeska’s blog on Consuming Business Events with Power Automate.
Consuming Business Events with Power Automate - Microsoft Dynamics AX Community
This blog will be similar, but I will use a HTTPS endpoint and show what Azure components need to be deployed for the HTTPS endpoint.
Business events provide a mechanism that lets external systems receive notifications from Finance and Operations applications. In this way, the systems can perform business actions in response to the business events.
Business events occur when a business process is run. During a business process, users who participate in it perform business actions to complete the tasks that make up the business process.
You can read more about business events here.
In this blog I am going to show how to use business events to send a message to an HTTPS endpoint. Endpoints let you manage the destinations for sending business events to. The following types of endpoints are currently supported. Endpoints can be created for these messaging and event brokers out of the box.
Azure Service Bus Queue
Azure Service Bus Topic
Azure Event Grid
Azure Event Hub
HTTPS
Microsoft Power Automate
In my experience, HTTPS is the least understood endpoint for Business events from our customers.
Here is a high-level overview of each section of this walkthrough:
- Creating an Azure Function to consume the business event from Finance and Operations. The Azure Function will be our HTTPS endpoint
- Create Application Registration and Client Secret in Azure Active Directory
- Configure an Azure Key Vault
- Create a new HTTPS endpoint in Dynamics 365 Finance and Operations
- Activate a Business Event in Dynamics 365 Finance and Operations
- Testing the Business Event
Creating an Azure Function that will be our HTTPS endpoint for consuming the business event
Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date resources needed to keep your applications running. A key business scenario for an Azure Function is to build a web API.
The following are a common, but by no means exhaustive, set of scenarios for Azure Functions.
|
|
|
|
If you want to... |
then... |
|
Build a web API |
Implement an endpoint for your web applications using the http trigger |
|
Process file uploads |
Run code when a file is uploaded or changed in blob storage |
|
Build a serverless workflow |
Chain a series of functions together using durable functions |
|
Respond to database changes |
Run custom logic when a document is created or updated in Cosmos DB |
|
Run scheduled tasks |
Execute code at set times |
|
Create reliable message queue systems |
Process message queues using Queue Storage, Service Bus, or Event Hubs |
|
Analyze IoT data streams |
Collect and process data from IOT devices |
|
Process data in real time |
Use Functions and SignalR to respond to data in the moment |
If you are not familiar with an Azure Function you can read more about them here.
I also recommend you go through one of the Azure Function tutorials to create a function.
Create a Python function using Visual Studio Code - Azure Functions | Microsoft Docs
Create a C# function using Visual Studio Code - Azure Functions | Microsoft Docs
For this example, I have deployed the following Python code to an Azure Function.
import logging
import json
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
dump = json.dumps({
'method': req.method,
'url': req.url,
'headers': dict(req.headers),
'params': dict(req.params),
'get_body': req.get_body().decode()
})
logging.info(dump)
return func.HttpResponse(
dump
)
The full steps for creating an Azure Function are not documented in this blog, but the above code sample and tutorial I pasted should work for you.
Create Application Registration and Client Secret in Azure Active Directory
Go to Azure portal > AAD > App registrations > New registration
Click on New Registration and provide a name for the application and click Register.
Once the Application ID is generated note the ID that was created from Application (client) ID in the Azure portal. You will need the Application ID later.
Click on Certificates & Secrets. Click on New client secret.
Provide a Description and an Expires on option and click Add. Take note of the client secret that is generated because you will not be able to retrieve the secret again and we will need the client secret and the Application ID to configure Finance and Operations later.
Now you should have an Application ID and a client secret in your notes.
Configure an Azure Key Vault
Go to Azure portal > Key Vaults > Create
Choose a resource group or create a new resource group and provide a unique key vault name. Click on review and create and then create.
Note the Vault URI that is created once the key vault is created. The Vault URI will be used to configure the HTTPS endpoint in Finance and Operations.
Click on Access policies to create a new access policy for the Key Vault.
Click on + Add Access Policy
Add Get and List to the secret permissions.
Additionally, add the principal. The principal is the name of the Application ID created in the Create Application Registration and Client Secret in Azure Active Directory section of this blog.
Make sure you click save to save the access policy.
Click on Secrets and click on +Generate =/Import. Provide a name for the secret and the value is the HTTPS URL for the endpoint that was created in section Creating an Azure Function that will be our HTTPS endpoint for consuming the business event section of this blog.
Click Create.
Note the Name of secret. The secret name will be used to configure the HTTPS endpoint in Finance and Operations.
Create a new HTTPS endpoint in Dynamics 365 Finance and Operations
In Dynamics 365 for Finance and Operations go to System Administration > Setup > Business Events > Business Event Catalog
Click on Endpoints and +New. Choose HTTPS as the endpoint type and click Next.
On the next screen fill in the values we have created so far.
Endpoint name: Any name you want for your endpoint.
Azure Active Directory application ID: Application ID from section Create Application Registration and Client Secret in Azure Active Directory.
Azure application secret: Client Secret from section Create Application Registration and Client Secret in Azure Active Directory.
Key Vault DNS name: This is the URI that was noted in section Configure an Azure Key Vault.
Key Vault secret name: This is the secret name that was noted in section Configure an Azure Key Vault.
Click OK.
Activate a Business Event in Dynamics 365 Finance and Operations
In Dynamics 365 for Finance and Operations go to System Administration > Setup > Business Events > Business Event Catalog
Choose a business event from the list and click +Activate. For this example, we will use BusinessEventsAlertEvent which is a change based alert business event.
Next, choose a legal entity and the HTTPS endpoint you created under the section Create a new HTTPS endpoint in Dynamics 365 Finance and Operations. Click OK.
Click on Active events and verify you see the BusinessEventsAlertEvent is activated.
Testing the Business Event
In Dynamics 365 for Finance and Operations go to Accounts Payable > Vendors > All Vendors
Click on Options and Create a custom alert.
Choose to Send email and Send externally and click OK.
In the Azure Portal go the Azure Function you created in the section Creating an Azure Function that will be our HTTPS endpoint for consuming the business event. Now click on Log Stream. Once you see Connected! You can test the Business event.
In Dynamics 365 for Finance and Operations go to Accounts Payable > Vendors > All Vendors
Create a new vendor.
Now verify the Business Event was consumed in the log stream.

Like
Report
*This post is locked for comments