I created very simple Power Automate flow for AI Translator custom model that takes file from SharePoint to Azure blob, then translates the document and puts the document back to SharePoint. After couple days usage and testing, the flow got a lot of new functionalities.
- PDF file name check in the start,
- Compose actions for getting the flow run instance url for error handling
- Notify boolean variable for double check that user is not notified in error case
- HTTP error branch and error handling
- Error handling for SharePoint file creation
PDF file name check in the start, notify user and terminate flow
It is very important that there is only PDF files and if user sets a wrong file, you don’t move it to blob and start translating. The solution needs to be user friendly, so message the user and guide to use the solution the correct way.
HTTP error branch and error handling
- If translator service gives error, take the error message (body from actions) and create Parse JSON in separate branch. Set Parse JSON to run only if HTTP – Translate action has failed. Use the error message as from template to get the template for Parse JSON template.
- Notify user who added the file to SharePoint
- Delete file from blob so it does not stay there. This solution translates all files in Azure Blob Container
- Send email to admin and Teams channel with error message and link to this flow run instance. It is much faster to open this directly and see what was the error.
- Terminate flow, there is no need for continue executing this flow
Error handling for SharePoint file creation
- If someone has already tried with a file earlier, there will be error that file already exists
- Take the error message (body from actions) and create Parse JSON in separate branch. Set Parse JSON to run only if Move translated file to SharePoint action has failed. Use the error message as from template to get the template for Parse JSON template.
- Create a condition where you test if error message starts with “A file with the name”
- If condition is yes, then set notify variable to TRUE, meaning we will just pass this error
- If condition is no, then terminate the flow executing with error
- In separate branch where there is no error after action Move translated file to SharePoint set the notify variable TRUE as well.
- Create condition whether to show the notification to user that translation is ready
- Set Notify users that translation is ready to be run after previous actions are successful or skipped, otherwise it might not go to the final notification condition if there is or isn’t error with SharePoint