web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Rename and move file t...
Power Automate
Unanswered

Rename and move file to correct folder based on recognized text from PDF

(0) ShareShare
ReportReport
Posted on by 2

Dear Microsoft Power Automate Community,

The company I work for is currently looking into possibilities to automate repetitive tasks to free up time for other tasks. One of the scenarios that I am working on is the following:

Our export department plans about 9,000 air and 4,000 sea freight shipments per year which are handed over to our contracted freight forwarders. For each air and sea shipment we receive an Air Waybill, respectively Sea Waybill in a PDF format from the freight forwarders by e-mail. Our staff members open each e-mail, then open the PDF file to check the country of destination, click save attachment as, select the correct SharePoint folder (there is a specific folder for each country), rename the file (file name is our shipment number) and save the file.

That takes around 1 minute or so per file. That's 13k minutes or about 217 hours a year spent on simply saving files to SharePoint!

I already managed to create a small scale PA flow that works: When an e-mail arrives from the freight forwarder which includes an attachment and the mail subject includes e.g. "AWB" the attachment is saved to the SharePoint. The recognize text in PDF function reads the file and based on a condition, if the recognized text contains e.g. "Taiwan" as country of destination, the file is moved to the correct SharePoint folder for the relevant country, or, if the first condition is not true, check the 2nd condition which is true if the recognized text contains e.g. "Thailand" as country of destination and so on.

However, what concers me, is that this flow with just 2 conditions takes about 2-4 minutes to complete. We supply over 100 countries so I would have to add more than 100 conditions to this flow, one for each country for the files to be moved to the correct SharePoint folder. So I wonder whether setting so many conditions is the right approach, as it may take a long time for the flow to go through each condition (performance concerns), and if there is a better way to automate this process?

What I have not yet tackled is to rename the file with the actual shipment number. The shipment number is either mentioned in the e-mail subject but is also mentioned in the PDF file itself. Getting it from the PDF file itself would be the safer approach. It is a 7-digit number and I am not sure how to isolate it from the rest of the recognized text and how to get PA to use that number as the new file name.

In short I have two questions:

1) What is the best practice approach to have PA identify the country of destination per file and move the file to the correct SharePoint folder also taking performance into account?

2) How to extract the shipment number from the PDF to rename the PDF file on SharePoint?


Thank you so much in advance for your input.

Regards,

Tobias

Categories:
  • royg Profile Picture
    on at

    Hi @Saibot86,

    To get the country name from the file's content you probably should and already use AI services. Once extracted, Use the Create file action and set the Folder Path to the country (assuming it exists in your library):

    royg_0-1707821906093.png

    If the action fails (the folder doesn't exist for example), you can send a notification email with the attachment to an admin or create the file in a designated folder for such cases.

    To extract the shipment number you can either try to use the AI service or search the text for 7 digit number using regex and office script action or simply by collecting all the words into an array and filter it by word length, then add a property that checks if the value is numeric and return the 1st match.

  • Saibot86 Profile Picture
    2 on at

    @royg and @AlexEncodian 

     

    Awesome! Thank you so much for these very interesting and helpful suggestions. I will try them out in the coming days. 😀

  • Saibot861 Profile Picture
    35 on at

    Hi All, 

     

    Just wanted to say thanks again, even though I ended up going down a different road as suggested above. I have made some progress on my flow, but struggle once again with something that I find very odd about Power Automate.

     

    So I have initialized a variable to which, within the flow, each country name is assigned (apply to each loop) and afterwards using a filter action Power Automate should search for that country name inside the text which was previously extracted from a PDF using the recognize text action. If this country is found in the text (condition), then the country name is assigned to variable "FoundCountry". 

     

    So here is the thing: The country name is successfully assigned to the CurrentCountry var, but the filter action "text contains CurrentCountry var" does not find the country in the text even though it is there (see enclosed screenshots - Body is [ ] ). However, when I type in e.g. JAPAN as the value to filter instead of using the CurrentCountry var, then the country name is found in the text. 

     

    So as many times before, I guess this is some kind of formatting issue, which really drives me crazy in Power Automate and which IMO should be more user friendly. Why does it find the typed in text value (JAPAN) but does not find the exact same value (JAPAN) when it is read from a variable?

     

    I appreciate any suggestions on this. Thank you! 

    CurrentCountry Var and Filter action.jpg
    CurrentCountry Var and Filter action edit mode.jpg
  • Saibot861 Profile Picture
    35 on at
    Never mind, I just got it to work. I was completely unaware that the Append to var action adds values to the variable for each iteration. I replaced the Append to var action with the Set variable action and now it works just fine.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 377

#2
11manish Profile Picture

11manish 292 Super User 2026 Season 2

#3
Henil Profile Picture

Henil 128

Last 30 days Overall leaderboard