Workaround Flow and Canvas App restrictions by using CDS
Background
In this article, you will learn the details of how I've managed to work around some of the current restrictions that don't allow some integrations of Power Automate flows in a Power Apps canvas app. NB: this article was due to be posted in the Power Apps blog, but the site is currently being reviewed so, in order to reduce delays, it's being posted here in the related Power Automate blog.
I've recently added a Solution package in the Power Apps Gallery for a sample License Plate Reader.
Since the Power Automate flow uses AI Builder's text recognition Predict action, it requires to be in a solution (since it's part of the CDS - Current environment connector). From that point on, the Canvas app that I use to capture the image to be analyzed cannot run that flow, because it's a known limitation that Canvas app triggered flows are not available in solutions.
That is why I've used a CDS entity and related trigger as a workaround to process the image via a flow and then display the result back in the app.
Get the know-how by reading on!
Resources
YouTube: overview of the solution
GitHub: solution package to install the app and required resources in your environment.
Blog post: the story behind the app and overall solution.
The Recipe
At this point, I'll presume you have read the blog post that explains the app and flow. The focus in this current post is about the integration between the two and it is possible to have an app post an item to CDS then wait for a flow to process it.
The steps are as follow:
- Create a CDS entity that will store the new request (in this case, with an image to process), with the following fields in my sample app:
- Name: where the extracted text is to be posted
- [optional] Image to process: a file or image datatype where the image to process is posted. Yes, the new datatype! 😀
- Processed by flow: a two option (boolean) field that is set to true once the flow has done its processing so the app can be aware the process has ended
- Create a Power Automate flow that will process the image (in the sample app via AI Builder's text recognition) and update back the entity's record with a "processed" status, the key steps are:
- Trigger on CDS - Current environment (When a record is created, updated or deleted)
- [optional] Action on CDS - Current environment (Get file or image content), to retrieve the image to process
- [any other process that is specific to your flow] in my sample app, this is where I call the text recognition prebuilt model from AI Builder and then extract the most predominant text portion
- Update the record that triggered this flow instance to confirm the flow has processed it
- Trigger on CDS - Current environment (When a record is created, updated or deleted)
- Create a Power Apps canvas app that creates the record (in this case, after selecting a new image) and then start a timer to periodically refresh its data source and identify when the record has been processed by the flow to surface the updated information to the end-user
- Create a connection to the CDS entity the flow is triggered on
- Using a SubmitForm(formname) or a Patch() statement, insert a new row in the entity
- Start a refresh process / loop as follow:
- Insert a Timer Control in the app
- Use a variable to start the timer
- Use a variable to set if the timer is to be repeated or not
- Set a duration for the timer that is applicable to your scenario
- When the timer ends (OnTimerEnd event), Refresh() the datasource and then validate if the "Processed" field has been updated for that newly created row. Based on the result, update the repeat variable
- Display the new data
- Insert a Timer Control in the app
- Create a connection to the CDS entity the flow is triggered on
Voilà !
This is just another example that even in a low code platform we can work around some of the current limitations and still be able to use the power of the AI Builder capabilities that are only available in Power Automate within a Power Apps canvas app.
Some of you may wonder why in the current scenario, it's not using the new Text Recognizer component that has been released in preview just prior to the holidays. The use of a Power Automate flow still makes sense because the only data currently provided by the control is the recognized text but no information about the size of the text and thus determine if it's the License Plate number.
Don't hesitate to download the solution from the gallery, edit the app or flow, adapt it, comment below, etc..
Learn and explore
About me
You can reach me on:
Keep on Diving!
*This post is locked for comments