Configure D365 fo and event grid

Overview on how to publish data entity changes from Dynamics Finance and Operations to Azure Event Grid.

Step 1

In D365FO, Navigate to the Business Events Catalogue page 

image

Step 2

Navigate to the endpoints tab and select ‘Azure Event Grid’

image

Step 3

In Azure, create an application service registration

image

Take note of the Application Id and the Secret Id

Step 4

In Azure,  create an Azure Event Grid Topic

https://customers.westus2-1.eventgrid.azure.net/api/events

Copy the Access Key

image

Step 5

In Azure,  create an Azure Key Vault with a key called

key-eventgrid-topic-d365fo-customers

image

The secret value is the Access Key for the Event Grid Topic

Step 6

On the key vault – grant access to the secret for the Application Registration

image

image

Step 7

In D365FO ‘configure an endpoint’ and enter the Azure Event Grid Topic endpoint

It now requires the Application Id & Application secret + the key vault name + name of secret in key vault (to get the Access Key)

image

Step 8

An endpoint should now display

image

Step 9

Activate the following 2 business events

  • BusinessEventsAlertEvent
  • BusinessEventsDueDateAlertEvent

image

select your newly created endpoint

Step 10

From the customers list, create a custom alert

image

Configure the alert to happen when the record is created, deleted or a field changes

image

Ensure ‘Send Externally’ is true

Step 11

Edit the customer and change the field with the alert on it & save the record

Step 12

view an alert & business event arrives in the following table

https://XXXXX.dynamics.com/Default.htm?mi=SysTableBrowser&cmp=YYYY&tablename=eventcud

XXXXX == your organisations URL
YYYY == your company

image

if no record appears here – you might need to fix your batch jobs

Step 13

Verify that your Azure Event Grid Topic has received the customer change events

image

Step 14

The below payload structure is sent to Event Grid

image

Subscribing to published Events in Flow

image

Sample extract (which was pushed to teams)

  • ID = BULK-002
  • Event = LocationChanged
  • Payload = {“BusinessEventId”:”BusinessEventsAlertEvent”,”ControlNumber”:5637145330,”Email”:”[email protected]”,”EventId”:”D60A8657-E87C-43A8-8D7D-826EBF0490D7″,”EventTime”:”/Date(1570769681000)/”,”FieldId”:3,”Link”:””,”MajorVersion”:0,”Message”:”LocationChanged”,”MessageDetails”:”View Location: BULK-002, 24″,”MinorVersion”:0,”ParentTableId”:8565,”RuleId”:”000428″,”Subject”:”LocationChanged”,”TableId”:8565,”TypeTrigger”:”FieldChanged”,”UserId”:”Chris.McKelt”}

Exported Flow Sample

{
     “$schema”: “https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,
     “contentVersion”: “1.0.0.0”,
     “parameters”: {
         “logicAppName”: {
             “type”: “String”,
             “metadata”: {
                 “description”: “Name of the logic app.”
             }
         },
         “logicAppLocation”: {
             “defaultValue”: “[resourceGroup().location]”,
             “allowedValues”: [
                 “eastasia”,
                 “southeastasia”,
                 “centralus”,
                 “eastus”,
                 “eastus2”,
                 “westus”,
                 “northcentralus”,
                 “southcentralus”,
                 “northeurope”,
                 “westeurope”,
                 “japanwest”,
                 “japaneast”,
                 “brazilsouth”,
                 “australiaeast”,
                 “australiasoutheast”,
                 “southindia”,
                 “centralindia”,
                 “westindia”,
                 “canadacentral”,
                 “canadaeast”,
                 “westcentralus”,
                 “westus2”,
                 “[resourceGroup().location]”
             ],
             “type”: “String”,
             “metadata”: {
                 “description”: “Location of the logic app.”
             }
         },
         “teams_Connection_Name”: {
             “defaultValue”: “teams”,
             “type”: “String”,
             “metadata”: {
                 “description”: “Name of the connection.”
             }
         },
         “azureeventgrid_1_Connection_Name”: {
             “defaultValue”: “azureeventgrid_1”,
             “type”: “String”,
             “metadata”: {
                 “description”: “Name of the connection.”
             }
         }
     },
     “resources”: [
         {
             “type”: “Microsoft.Logic/workflows”,
             “name”: “[parameters(‘logicAppName’)]”,
             “apiVersion”: “2016-06-01”,
             “location”: “[parameters(‘logicAppLocation’)]”,
             “properties”: {
                 “state”: “Disabled”,
                 “definition”: {
                     “$schema”: “
https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#”,
                     “contentVersion”: “1.0.0.0”,
                     “parameters”: {
                         “$connections”: {
                             “defaultValue”: {},
                             “type”: “Object”
                         },
                         “$authentication”: {
                             “defaultValue”: {},
                             “type”: “SecureObject”
                         }
                     },
                     “triggers”: {
                         “When_a_resource_event_occurs”: {
                             “splitOn”: “@triggerBody()”,
                             “metadata”: {
                                 “flowSystemMetadata”: {
                                     “swaggerOperationId”: “CreateSubscription”
                                 }
                             },
                             “type”: “ApiConnectionWebhook”,
                             “inputs”: {
                                 “host”: {
                                     “connection”: {
                                         “name”: “@parameters(‘$connections’)[‘azureeventgrid_1’][‘connectionId’]”
                                     }
                                 },
                                 “body”: {
                                     “properties”: {
                                         “topic”: “/subscriptions/62b6ef06-81e9-468f-9bc5-133ef44f5e3f/resourceGroups/test/providers/Microsoft.EventGrid/topics/customers”,
                                         “destination”: {
                                             “endpointType”: “webhook”,
                                             “properties”: {
                                                 “endpointUrl”: “@{listCallbackUrl()}”
                                             }
                                         }
                                     }
                                 },
                                 “path”: “/subscriptions/@{encodeURIComponent(’62b6ef06-81e9-468f-9bc5-133ef44f5e3f’)}/providers/@{encodeURIComponent(‘Microsoft.EventGrid.Topics’)}/resource/eventSubscriptions”,
                                 “queries”: {
                                     “x-ms-api-version”: “2017-09-15-preview”
                                 },
                                 “authentication”: “@parameters(‘$authentication’)”
                             }
                         }
                     },
                     “actions”: {
                         “Post_a_message_(V3)”: {
                             “runAfter”: {
                                 “Init_EntityId”: [
                                     “Succeeded”
                                 ]
                             },
                             “metadata”: {
                                 “flowSystemMetadata”: {
                                     “swaggerOperationId”: “PostMessageToChannelV3”
                                 }
                             },
                             “type”: “ApiConnection”,
                             “inputs”: {
                                 “host”: {
                                     “connection”: {
                                         “name”: “@parameters(‘$connections’)[‘teams’][‘connectionId’]”
                                     }
                                 },
                                 “method”: “post”,
                                 “body”: {
                                     “body”: {
                                         “content”: “<ul>\n  <li>@{variables(‘EntityId’)}</li>\n  <li>@{variables(‘EventType’)}</li>\n  <li><br></li>\n  <li>@{variables(‘Payload’)}<br>\n<br>\n\n\n</li>\n</ul>”,
                                         “contentType”: “html”
                                     }
                                 },
                                 “path”: “/v3/beta/teams/@{encodeURIComponent(‘7b341171-e9de-4981-986c-e78ab8faa1ba’)}/channels/@{encodeURIComponent(’19:[email protected]’)}/messages”,
                                 “authentication”: “@parameters(‘$authentication’)”
                             }
                         },
                         “Init_EventData”: {
                             “runAfter”: {},
                             “type”: “InitializeVariable”,
                             “inputs”: {
                                 “variables”: [
                                     {
                                         “name”: “EventData”,
                                         “type”: “Object”,
                                         “value”: “@triggerBody()”
                                     }
                                 ]
                             }
                         },
                         “Init_AlertString”: {
                             “runAfter”: {
                                 “Initialize_variable”: [
                                     “Succeeded”
                                 ]
                             },
                             “type”: “InitializeVariable”,
                             “inputs”: {
                                 “variables”: [
                                     {
                                         “name”: “AlertString”,
                                         “type”: “String”,
                                         “value”: “@{variables(‘Payload’)}”
                                     }
                                 ]
                             }
                         },
                         “Init_Alert”: {
                             “runAfter”: {
                                 “Init_AlertString”: [
                                     “Succeeded”
                                 ]
                             },
                             “type”: “InitializeVariable”,
                             “inputs”: {
                                 “variables”: [
                                     {
                                         “name”: “Alert”,
                                         “type”: “Object”,
                                         “value”: “@json(variables(‘AlertString’))”
                                     }
                                 ]
                             }
                         },
                         “Initialize_variable”: {
                             “runAfter”: {
                                 “Init_EventData”: [
                                     “Succeeded”
                                 ]
                             },
                             “type”: “InitializeVariable”,
                             “inputs”: {
                                 “variables”: [
                                     {
                                         “name”: “Payload”,
                                         “type”: “String”,
                                         “value”: “@{variables(‘EventData’).data}”
                                     }
                                 ]
                             }
                         },
                         “Init_EventType”: {
                             “runAfter”: {
                                 “Init_Alert”: [
                                     “Succeeded”
                                 ]
                             },
                             “type”: “InitializeVariable”,
                             “inputs”: {
                                 “variables”: [
                                     {
                                         “name”: “EventType”,
                                         “type”: “String”,
                                         “value”: “@{variables(‘Alert’)[‘Message’]}”
                                     }
                                 ]
                             }
                         },
                         “Init_EntityId”: {
                             “runAfter”: {
                                 “Init_EventType”: [
                                     “Succeeded”
                                 ]
                             },
                             “type”: “InitializeVariable”,
                             “inputs”: {
                                 “variables”: [
                                     {
                                         “name”: “EntityId”,
                                         “type”: “String”,
                                         “value”: “@{split(split(variables(‘Alert’)[‘MessageDetails’], ‘:’)[1], ‘,’)[0]}”
                                     }
                                 ]
                             }
                         }
                     }
                 },
                 “parameters”: {
                     “$connections”: {
                         “value”: {
                             “teams”: {
                                 “id”: “[concat(‘/subscriptions/’, subscription().subscriptionId, ‘/providers/Microsoft.Web/locations/’, parameters(‘logicAppLocation’), ‘/managedApis/’, ‘teams’)]”,
                                 “connectionId”: “[resourceId(‘Microsoft.Web/connections’, parameters(‘teams_Connection_Name’))]”,
                                 “connectionName”: “[parameters(‘teams_Connection_Name’)]”
                             },
                             “azureeventgrid_1”: {
                                 “id”: “[concat(‘/subscriptions/’, subscription().subscriptionId, ‘/providers/Microsoft.Web/locations/’, parameters(‘logicAppLocation’), ‘/managedApis/’, ‘azureeventgrid_1’)]”,
                                 “connectionId”: “[resourceId(‘Microsoft.Web/connections’, parameters(‘azureeventgrid_1_Connection_Name’))]”,
                                 “connectionName”: “[parameters(‘azureeventgrid_1_Connection_Name’)]”
                             }
                         }
                     }
                 },
                 “runtimeConfiguration”: {
                     “lifetime”: {
                         “unit”: “Day”,
                         “count”: 30
                     },
                     “collections”: {
                         “maximumItemCount”: 100000
                     },
                     “performanceProfile”: {
                         “throttles”: {
                             “mode”: “Medium”
                         }
                     }
                 }
             },
             “dependsOn”: [
                 “[resourceId(‘Microsoft.Web/connections’, parameters(‘teams_Connection_Name’))]”,
                 “[resourceId(‘Microsoft.Web/connections’, parameters(‘azureeventgrid_1_Connection_Name’))]”
             ]
         },
         {
             “type”: “Microsoft.Web/connections”,
             “name”: “[parameters(‘teams_Connection_Name’)]”,
             “apiVersion”: “2016-06-01”,
             “location”: “[parameters(‘logicAppLocation’)]”,
             “properties”: {
                 “api”: {
                     “id”: “[concat(‘/subscriptions/’, subscription().subscriptionId, ‘/providers/Microsoft.Web/locations/’, parameters(‘logicAppLocation’), ‘/managedApis/’, ‘teams’)]”
                 },
                 “displayName”: “[parameters(‘teams_Connection_Name’)]”
             }
         },
         {
             “type”: “Microsoft.Web/connections”,
             “name”: “[parameters(‘azureeventgrid_1_Connection_Name’)]”,
             “apiVersion”: “2016-06-01”,
             “location”: “[parameters(‘logicAppLocation’)]”,
             “properties”: {
                 “api”: {
                     “id”: “[concat(‘/subscriptions/’, subscription().subscriptionId, ‘/providers/Microsoft.Web/locations/’, parameters(‘logicAppLocation’), ‘/managedApis/’, ‘azureeventgrid_1’)]”
                 },
                 “displayName”: “[parameters(‘azureeventgrid_1_Connection_Name’)]”
             }
         }
     ]
}