22) Dynamics 365 for Finance and Operations Integrations using Logic Apps and Business Events

Despite Power Automate (formerly called Flow) being handy to deploy integrations, the platform has limitations this is the reason a lot of the D365FO integrations are using Logic Apps. Logic Apps can enable advanced integrations scenarios like B2B processes where enterprise-level Azure DevOps and security practices are required.
Logic Apps  is a cloud service that helps you schedule, automate, and orchestrate tasks, business processes, and workflows when you need to integrate apps, data, systems, and services across enterprises or organizations
Every Logic App workflow starts with a trigger, which fires when a specific event happens, or when newly available data meets specific criteria. Many triggers provided by the connectors in Logic Apps include basic scheduling capabilities so that you can set up how regularly your workloads run. For the Dynamics 365 for Fin & Ops Connector, the triggers are the Business Events. On D365FO a Business event lets external systems receive notifications using small payload messages. Since these events happen in the context of business processes, they are called business events that enable business process integration.
 The business event can be used by:
  • Azure Service Bus
  • Azure Logic Apps
  • Microsoft Automate
  • Azure Functions
  • HTTPS Trigger
I will show you step by step on how to create a Logic App using a D365FO  Business event as a Trigger. At a high level in this example, every time that a new Free text invoice is posted it will trigger Logic App to send a notification email:

Create a new Logic Apps

1. Sign in to Azure portal
2.Select Create a resource > Logic Apps > Create
 3.Select a Resource Group, write down a Logic App Name and click on Review+Create
 
 4. On the Logic App page select the Logic app designer option and then select Blank Logic App
5. Search for Dynamics 365 for Finance and Operations and select the connector.
6. You will notice a trigger named When a Business Event occurs. Select this trigger.
7. Sign in to create a connection to Dynamics 365 for Fin & Ops.
8. Select your environment instance, category, event name, and click to Add a new parameter to add a legal entity.
9. Select the New Step button to add a new action
10. Search for the Parse JSON data operation. This step is needed to parse the message with the schema of the data contract.
11. Select the content field of Parse Jsonaction, then the Body output from the previous step should appear as an option. Select Body.
 
12. Enter the schema of the contract. They schema is found in Dynamics 365 for Finance and Operations. Go to System Administration - > Business Events -> Business Events Catalog. Because the app provides only a sample payload you can use the Logic App capability to generate a schema from a payload. Select Free text invoice posted and select the Download schema This will download a text file. Open the text file and copy the content.
 
13. Go Back to Logic App page on the Azure Portal and select the Use sample payload to generate schema Paste your text file content and select Done.
Depending on the quality of your sample payload, your generator will not be able to distinguish between an integer and a real number. This is true if the real number is provided as a whole number in the sample payload. Review your generated schema and check if you need to change an “integer” into “number” on the InvoiceAmountInAccountingCurrency and InvoiceTaxAmount parameters. In JSON, a “number” data type means real number.
14. Choose another final action to consume the business event content. For instance, you can send an email (or post a text message to Teams) to notify the customer about payment details. Search for email and select Office 365 Outlook
15. Select Send an email (V2) and change the TO and create a subject and Email body based on the schema of the parsed json.
16. Save the logic App.

Trigger a Business Event

After you save your Logic App, it creates an endpoint, then it activates the business event for you. There is no remaining configuration step apart from verifying that the endpoint has been correctly configured before triggering an event.
  1. From Dynamics 365 for Finance and Operations navigate to System Administration > Setup > Business Events.
  2. Select Endpoints.
  3. Verify that a new endpoint has been created with a GUID appended in the name.
  4. If you check the Active eventstab you can also verify that “Free text invoice posted” is activated for legal entity USMF.
  5. The final step is to trigger the business event of a posted customer payment and check whether the flow runs, and you receive an email with customer payment details.
    Go to Accounts Receivable > Invoices > All Free text invoices.
    In this example, I will select invoice US-001 and click Post
  6. Click Ok on the posting screen.
  7. Review if the Logic App runs automatically on the Logic app page of the Azure Portal
  8. In this case, we can see that the Logic App ran successfully

  9. Check your email for the message.

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++