Practical Examples of Power Automate with Business Central
September 25, 2024
|
63 minutes
Automating business events and integrating external data with Microsoft Dynamics 365 Business Central can be complex. This is relevant for IT professionals and Business Central users seeking practical insights into building reusable, efficient Power Automate flows.
Chapters
0:00 — Intro + what you’ll learn (Power Automate + Business Central)
1:05 — Two core patterns (BC → outside world, outside world → BC)
4:08 — Scenario 1 overview: when a test finishes → PDF → OneDrive → Teams
5:37 — Build Scenario 1 flow: Business Central trigger + generate PDF
12:25 — Save PDF to OneDrive + create share link
19:30 — Post message to Teams + test run (run history + timing)
27:56 — Scenario 2 overview: file uploaded → parse → update test values in BC
32:50 — Build Scenario 2 flow: trigger + extract lot # + find test record
42:48 — Parse file with compose + loop + conditionals
53:06 — Write values back to Business Central (run action: set test value)
56:49 — Demo run + debugging a failure (run history, fix, re-test)
1:02:26 — Wrap-up + key takeaways
Executive Summary
Integrating Microsoft Power Automate with Business Central enables automated workflows that improve operational efficiency and data management. Understanding how to trigger flows from Business Central events and update records based on external file uploads offers practical knowledge for building robust, reusable integration patterns using standard connectors.
- Power Automate integration patterns with Business Central
- Business Central business event triggers
- Generating PDF reports and using OneDrive for document storage
- Posting notifications in Microsoft Teams with dynamic content
- Parsing external files and updating Business Central records
- Troubleshooting Power Automate flows
- Using connector actions for data updates
- Debugging techniques in Power Automate flows
Ask a Question
Welcome and Session Overview
Welcome to practical examples of Power Automate using Business Central. We’re going to use Quality Inspector as part of this example, but the lessons and techniques are generic, and you should be able to apply them to other concepts inside Business Central.
A little bit about myself: my name is Tim. I’ve been working with Insight Works for about 15 years, and I design and build apps primarily in the manufacturing space—things like Enhanced Planning Pack, MxAPS, Shop Floor Insight, Graphical Scheduler, and Quality Inspector. In general, I’m here to help you find ways of using technology and apps within our manufacturing ecosystem.
In this session, we’re going to walk through two general scenarios. When we’re talking about Power Automate and Business Central, we’re really talking about two fundamental scenarios: one is something within Business Central happened and you have to tell the world, and the other is something outside of Business Central has happened and you have to do something inside Business Central as a consequence.
This presentation is not a lab. You don’t need your VM—this is purely a show-and-tell presentation.
Skills and Tools Used
To get the most out of this, you’ll need some technical knowledge, but you don’t need to be a developer. Power Automate is positioned as a low-code solution, so it’s largely drag-and-drop blocks, but you do need a basic understanding of logic concepts, and you do need a general understanding of some Business Central concepts.
For this session, the tools we’re going to use are Business Central, Microsoft Teams, Microsoft Power Automate, Microsoft OneDrive for Business, and in our case, the Quality Inspector app.
Scenario 1: Business Central Event to External Notification
For the first concept—something within Business Central happened—we’re going to use the example of “when a test has finished,” and we’re going to notify someone in Teams. This is the most common scenario: something inside Business Central happens, like a sales order is posted, a document is approved, or something similar, and then you need to interact with the outside world.
In our flow, when a quality inspection test is finished, we’ll generate a PDF, save it into OneDrive, create a shareable link, and post that link along with some content into Microsoft Teams. It doesn’t have to be Teams—it could be email or another messaging system—but Teams is the example we’ll use.
Creating the Flow Trigger
We start in Power Automate by creating an automated cloud flow and selecting a trigger from Business Central. We use “When a business event occurs,” which has a nice benefit: it can provide additional context in one place. We select the environment and company, then choose the specific event.
There are many built-in Business Central business events, like when a sales order is posted, when an invoice is posted, or when an order is released. In our example, we’ll use “when a quality inspection test is finished,” which is simple and straightforward for demonstrating what’s happening.
Generating the PDF from Business Central
Next, we add an action to call back into Business Central to get the PDF. We use the Business Central connector and choose the “Get an image, file, or document” type of action that streams data from Business Central.
We choose the API category for Quality Inspections and select the report path (the OData path) for the Quality Inspection test report. The connector asks for the ID of the quality inspection test. In Power Automate, entities are commonly referenced by GUIDs, and in Business Central, we can use the record’s System ID. We grab that System ID from the event context and pass it into the PDF generation call.
If you haven’t used Quality Inspector before, all you really need to know for this presentation is that a quality inspection test stores values and can be finished. The generated PDF is just a report showing those collected values.
Saving the PDF to OneDrive
Now that we have the PDF content, we connect it to OneDrive for Business and use “Create file.” We select a folder we created ahead of time for PDF output.
For the file name, we demonstrate Power Automate functions by using concatenation. For example, we prefix with something like “TechWorks” and then add values from the business event context—like the test number, item number, and lot number—then append “.pdf” at the end. The file content is simply the output body from the Business Central PDF action.
Creating a Shareable Link
After the file is created, we create a share link in OneDrive. We use “Create share link” (not “by path”) so we can use the file’s unique identifier directly. This keeps the flow simpler because we don’t have to regenerate names or paths. We create a view link, and for this example we use an anonymous link scope.
Posting the Notification in Microsoft Teams
Finally, we post a message in Teams using the Teams connector. We post as the Flow bot and choose a team and channel that were set up ahead of time. The message includes the test details (test number, item number, lot number) and the share link URL.
Once saved, the flow is immediately available. When a test is finished in Business Central, the flow runs, creates the PDF, uploads it to OneDrive, generates the share link, and posts the message in Teams.
Run History and Timing Notes
When the flow runs, there can be a lag. It’s not instant. In our example, the run took seconds, and in many cases you may see delays of a few minutes depending on throttling and connector behavior. This is fire-and-forget: finishing the test in Business Central doesn’t wait for Power Automate to complete before the transaction commits.
Run history is useful for troubleshooting. You can see each step, how long it took, and where it may have failed. You can also rerun a flow instance using the test feature with a recently used trigger, which can help while debugging.
Scenario 2: External File Upload to Business Central Update
In the second example, we flip the direction. Something outside of Business Central happens, and we need to do something inside Business Central as a consequence. In our case, a file is uploaded to OneDrive—specifically, a text file containing measurement data—and we parse it, find the right quality inspection test in Business Central, and update test values.
This example has simpler system interaction (just OneDrive and Business Central), but more complex flow logic. We’ll demonstrate capabilities like Compose blocks, Apply to each loops, and Condition blocks.
We’re not advocating that this is the best way to solve imports into Business Central. There are other approaches, including capabilities inside Business Central itself. This is simply a practical Power Automate example of an external system talking to Business Central.
Goal and File Format
The file is a text file. The file name represents the lot number (for example, “LOT123.txt”). Inside the file, there’s some garbage data we want to discard, and then there are measurement lines we care about. The lines we want start with an “A_” prefix, and those lines contain measurement keys and values separated by semicolons.
The goal is to extract the lot number from the file name, find the matching quality inspection test in Business Central by that lot number, parse the file content, and set the matching test values in Business Central.
Trigger: File Created in OneDrive
We create a new automated cloud flow with a OneDrive trigger for when a file is created in a specific folder (an input folder created ahead of time). Because this is a demo, we reduce the polling interval to the minimum, but in the real world you would consider throttling and appropriate polling frequency.
Compose: Extract Lot Number from File Name
We use a Compose block to create a temporary variable for the lot number. The lot number is the file name without the “.txt” extension, so we use a replace function to remove “.txt” and return just the lot number. Using Compose blocks makes the flow easier to read and troubleshoot compared to embedding complex expressions everywhere.
Find the Matching Test in Business Central
Next, we use the Business Central connector to “Find one record” in the Quality Inspection API category. We set a filter for the source lot number field to equal the lot number extracted from the file name. For this scenario, we assume there is only one test per lot number, so finding one record is enough.
Get File Content from OneDrive
We then get the file content using the file identifier from the OneDrive trigger. Using the ID-based approach keeps the flow simpler than rebuilding paths and names.
Compose: Split File into Lines
We use another Compose block to split the file content into multiple lines. One approach is to split on a line break. A quick trick shown is using decodeUriComponent to represent the carriage return and line feed delimiter, then splitting the file content into an array of lines.
Apply to Each and Condition: Process Only Measurement Lines
We use an Apply to each loop to iterate over each line from the split output. Inside the loop, we add a Condition that checks if the line starts with “A_”. If it does, we process it; otherwise, we ignore it. This allows us to skip all the header and garbage lines and only focus on the measurement data lines.
Compose: Split the Line by Semicolons
For lines that pass the condition, we use another Compose block to split the line by semicolons. This gives us an array of parts we can use to extract the measurement key and the measurement value.
Compose: Extract Measurement Key and Value
We extract the measurement key from the first element of the semicolon-split array, then remove the underscore using a replace function so the key matches the field codes inside Business Central.
We extract the measurement value from the appropriate array index. In the example, the value is taken from a specific position in the semicolon-split array (using zero-based indexing).
Update Business Central: Run Action to Set Test Value
Finally, we call Business Central using “Run action” from the Quality Inspection API category, selecting the action to set a test value. We provide the system ID of the test record (from the earlier “Find one record” step), and we pass the extracted measurement key and measurement value into the action.
Debugging the Flow with Run History
When we test the flow by uploading the file to OneDrive, we can watch the run history. In the demo, the first run fails, which is a good opportunity to demonstrate troubleshooting. Run history shows each step, what succeeded, and where it failed.
We inspect the loop iteration where the first measurement line is processed and identify a syntax issue in the expression used to extract the measurement key. The fix is to ensure we take the first element of the semicolon-split array correctly, then apply replace to remove underscores.
After correcting the expression, we use the Test feature in Power Automate with the recently failed trigger to rerun the flow. This time it succeeds, and when we refresh the record in Business Central, we can see the test values were set correctly.
Wrap-Up
In the first example, we demonstrated how something inside Business Central can trigger actions outside Business Central: finishing a quality inspection test triggers PDF generation, OneDrive upload, share link creation, and a Teams notification.
In the second example, we demonstrated the reverse: something outside Business Central (a OneDrive file upload) triggers parsing logic and updates inside Business Central. Along the way, we demonstrated Compose blocks for clearer logic, Apply to each loops for line-by-line processing, Conditions for filtering, and Business Central actions for setting values—plus how to debug using run history.
That’s it. Thank you for your time, and thank you for your questions.