In this blog I’m going to show how to use business events to start a Power Automate flow when a batch job finishes and notify an HTTP endpoint. The idea behind this use case is that you need to notify an external system that something has finished running (such as a data import/export job) and now you want to trigger that external system to do something (such as start an integration process from its end). This can be useful so that external systems aren’t polling your integration endpoints at fixed intervals when the data hasn’t changed. 

If you are not familiar with business events, you can click here for the detailed overview. They are designed to send small payloads to signal an external process to do something. These events also contain different fields of data relevant to what the business event is intended for. For example, the event for a batch job finishing will include the batch id of the job. You can view a full catalog of the business events in System administration > Setup > Business events > Business events catalog. Developers can also extend business events for use cases where one is not already available.

Use business events with care. These are not designed to move large amounts of data or serve as an integration point. Also consider how often the event will be executing as business events and batch job processing share the same server threads. 

Below, I have put together a walk through to configure the different pieces to make this scenario work.

The pre-requisites are:

  • Your user is assigned the System administrator role in Dynamics 365 Finance and Operations for demonstration purposes (there are business event privileges that can be assigned in a production scenario).
  • A premium Power Apps subscription which is needed for business event connectors to use with Dynamics. You can register for a demo if you don’t have one, but that demo licensing should be applied to the same tenant as your F&O environment.
  • If you apply a Power App subscription license to your tenant you will need rights to do this.

Here is a high-level overview of each section of this walkthrough:

  • Creating a Batch Job
  • Creating a Power Automate Flow
  • Testing the Solution

Creating a Batch Job

Now we’re going to create a batch job in the DAT company to trigger a Batch job has finished business event with. We’re not concerned with what this job does, and this is only meant to be a simple job for demonstration purposes.

  1. Launch F&O and set the Company to DAT. For the purposes of this walkthrough, I am using a system batch job to trigger the flow. For other scenarios, a batch job and the Power Automate flow can be configured for any company.
  2. Navigate to System administration > Inquiries > Batch jobs.
  3. Click Switch to enhanced view (you may not have to do this if you are already using the enhanced view. If you see Switch to legacy form as a menu option, you are already in the correct view).
  4. Click New.
  5. Enter Business Event Test in the Job description field.
  6. Click New under Batch tasks.
  7. Enter My task under Task Description,
    Enter SysUserLicenseEstimatorBatchProcessor for Class name,
    Then enter DAT under Company.
    Note: SysUserLicenseEstimatorBatchProcessor is unrelated to this project. This was only selected as something simple to run so the batch job has a task and will execute. This class only populates report tables used by the license estimator report. Click Save.
  8. Click BusinessEvents and set Ended to Yes for this batch job. Click OK and then click Save.

    This is a screen shot with the Business Events button highlighted towards the top of the page.
    This is the batch job business events parameters. The option for ended is highlighted and is toggled to Yes.
  9. From the Batch jobs screen, type Business Event Test in the filter field.
  10. Copy the Job ID and save it someplace you can easily retrieve later. We will need this when we build our Power Automate flow.

    This is a screenshot of the batch job screen and the Business Event Test batch job. The Job ID field is highlighted indicating to copy this job id for later use.

Creating a Power Automate Flow

Next, we will create the Power Automate flow that will be initiated from the Batch job has ended business event. The flow will parse a JSON payload using a schema for the business event and use a case statement to evaluate a match on the batch job id we created. If the batch job id matches, we will initiate an HTTP POST on an endpoint.

Note: Creating Power Automate flows with a business event connector requires a premium Power Apps subscription for licensing. This licensing must also be on the same tenant that the F&O environment is hosted in for the endpoint and activated business event to automatically appear in F&O. Without it, you will still be able to build and save the flow, but it won’t activate. To work around this, you can activate a Power Apps per user plan demo. After you’ve applied a demo license, you can create a Power Apps demo environment, assign a Power Apps license to your user in the M365 Admin Center, and you should be able to activate the flow in the Power Apps demo environment.

Here are the steps if you need a demo license. Skip this and continue to Step 1 of this section if you already have a premium subscription to Power Apps.

  • For a temporary Power Apps demo license to use premium connectors, you can click here and click Try free under the Per user plan to apply the licensing. Apply this to the same tenant as F&O to follow this walkthrough.
  • You then must apply a Power App license to a user from the Microsoft 365 admin center. Here is a link.
  • Click Billing > Licenses > Power Apps per user plan.
  • Click Assign licenses and find the desired user in the field labeled Enter a name or email address.
  • Click Assign.

  1. Log into the Power Automate portal and select the appropriate environment. If you are using a demo license, you may only have a Contoso environment.

    This is a screenshot of the batch job screen and the Business Event Test batch job. The Job ID field is highlighted indicating to copy this job id for later use.
  2. Click Flows on the navigation side bar and then click New Flow.
  3. Select Automated cloud flow under the Build your own from blank section for templates.
  4. Name your flow D365FO Batch Job Finished.
  5. Type Fin & Ops in the Choose your flow’s trigger field and select the When a Business Event occurs - Fin & Ops Apps (Dynamics 365) Click Create.

    This is a screenshot of the batch job screen and the Business Event Test batch job. The Job ID field is highlighted indicating to copy this job id for later use.

  6. You will now have a new flow with a When a Business Event occurs The first time this is created you may have to wait a moment as it signs in as your user.
  7. Select your F&O environment from the Instance drop down,
    Select Batch for the Category,
    Select Batch job finished for the Business event,
    Then choose DAT for Legal entity.

    A screenshot of the when a Business Event occurs block in Power Automate. It shows an instance selected, which is your finance and operation environment. The category field is set to Batch. The business event field is set to Batch job finished. The legal entity field is set to DAT.
  1. Click New step and type Parse JSON into the search field for Choose an operation.

    The Choose an operation screenshot is shown. Parse JSON are key words typed into the search box. The PARSE JSON action shows up from the search and is highlighted to show that you should select this action.

  2. Click into the Content field and select body in the Add dynamic content from the apps and connectors window that pops up.
  3. Connect to the F&O environment we will be consuming the business event from and navigate to System administration > Setup > Business events > Business events catalog.
  4. In the Business event catalog highlight BatchJobFinishedBusinessEvent in the Batch category.
  5. Click Download schema. This downloads a file containing the schema of the JSON payload for the business event that will be used in Power Automate.

    This is a screenshot of the business events catalog. The Batch job finished business event is highlighted showing to click it. Then on the right of the screen the download schema link is highlighted. Click this as part of step 12.

  6. Copy the contents of the file you downloaded.
  7. Return to the Power Automate portal and click Generate from sample in the Parse JSON step of your flow.
  8. Paste the schema you downloaded and copied from steps 12 and 13. Click Done.
  9. Click New Step and search for Switch and select Switch – Control.
  10. For the Switch step, click into the field for On and select JobId from Dynamic content.
  11. In the Case control, click into the field for Equals and enter the Job ID of the batch job created in previous steps. The value of JobId is our batch job id.

    A screenshot of the switch control in the power automate flow. It is showing the JobId dynamic content added to the
  12. Click Add an action in the Case block for the Switch expression and search for HTTP.
  13. Select HTTP.

    A screenshot of the choose an operation screen. HTTP is typed as a key word in the search box and a highlight is around the
  14. Select POST under Method and enter an endpoint address into the URI This step will trigger an HTTP POST to an endpoint to simulate creating a request in a third-party system. I don’t have an endpoint to provide you, but there are many developer tools and websites out there with endpoints that are meant to be tested on. Use Bing to search for ‘http request test’ for sites that you can test POST requests with.

    This is a screenshot of the HTTP action. POST is selected for the method and you need to enter an HTTP endpoint in the URI field that is capable of testing POST methods with. Recommendations for finding a public testing endpoint is given in step 12.

  15. Save the flow which will also attempt to activate it with F&O.

Activating the flow will automatically create the endpoint in F&O and activate the business event specified in the When a Business Event occurs block (the first block in our flow). If you can save the flow but cannot activate it, you may have to use a demo for the premium subscription or upgrade your subscription as covered at the beginning of this blog.

Testing the Solution

Now it all comes together, and we will execute the batch job, generate the business event, and start the Power Automate flow. Let’s verify we can see our business event endpoint and that our business event is activated:

  1. In F&O, navigate to System administration > Setup > Business events > Business events catalog.
  2. Click Endpoints and verify an endpoint for Microsoft Power Automate was created.
  3. Click Active events and verify BatchJobFinishedBusinessEvent is associated with the endpoint.
  4. Navigate to System administration > Inquiry > Batch jobs and filter for Business Event Test to find our testing batch job. Click the Job ID link to open your batch job.
  5. Click BusinessEvents and verify Ended is set to Yes for this batch job. Click OK.
  6. Schedule and run your batch job. Enter a date and time into the Scheduled start date/time field that is a few minutes into the future. Click the Change status menu, click Waiting, and then click OK. When the batch job execution finishes, your Power Automate flow should have also been executed.
  7. Go back to the Power Automate portal, click My Flows, and then click into the D365FO Batch Job Finished flow created in previous steps.
  8. Under 28-day run history you should see the run history.

    A screenshot showing the 28 day run hisotry. There is one entry from April 2nd showing a successful execution and took 44ms in duration.
  9. Click the Start date and time in the run history to open the history of this flow execution.
  10. Click once into the When a Business Event occurs block to see the Outputs if you are interested in what F&O sent to the Power Automate flow.

    A screenshot from the 'when a business event occurs' block in run history. The JobId value under outputs is highlighted showing it is the batch job id sent from F&O.

  11. Click the Switch block to expand it, then click the Case block, and then click into HTTP. We can see a successful POST method with a status code of 200 (OK). It worked!

    A screenshot of the HTTP action block from the run history. A Status code of 200 is highlighted, indicating the call was successful.

We made it! Thanks for sticking that out, I know it was a lot of steps. I hope this was helpful to show how you can use a batch job ending to notify an external system using business events and Power Automate.

THANK YOU for reading! Please add me to LinkedIn and I hope to hear from you soon.