web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Business Events with an Azure Function and the HTTPS endpoint

JasonLar Profile Picture JasonLar 21

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.

3583.pastedimage1622811490959v1.png

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.

5658.pastedimage1622811530134v2.png

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.

 

 5824.pastedimage1622811673842v4.png

 

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.

4454.pastedimage1622811749008v5.png

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.

4863.pastedimage1622811771637v6.png

Click on Access policies to create a new access policy for the Key Vault.

4503.pastedimage1622811795249v7.png

Click on + Add Access Policy

Add Get and List to the secret permissions.

8030.pastedimage1622811812365v8.png

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.

3833.pastedimage1622811825427v9.png

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.

3463.pastedimage1622811837144v10.png

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.

2084.pastedimage1622811861001v11.png

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.

1524.pastedimage1622811877272v12.png

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.

3225.pastedimage1622811887757v13.png

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.

3755.pastedimage1622811904395v14.png

Click on Active events and verify you see the BusinessEventsAlertEvent is activated.

2476.pastedimage1622811917897v15.png

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.

6644.pastedimage1622811926245v16.png

1537.pastedimage1622811935763v17.png

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.

4705.pastedimage1622811943858v18.png

In Dynamics 365 for Finance and Operations go to Accounts Payable > Vendors > All Vendors

Create a new vendor.

4426.pastedimage1622811953691v19.png

Now verify the Business Event was consumed in the log stream.

3056.pastedimage1622811962447v20.png

Comments

*This post is locked for comments