Skip to main content

Notifications

Power Automate - Building Flows
Suggested answer

Compare Email Subject and Save Attachment

Posted on by 4
Hello Team,
 
Looking for your support to build the flow which help us to compare and math the email subject and save attachment into SharePoint folder with respective folders.
 
Fo example, if we create a folder in SharePoint with name "A" and user A send email with subject "Invoice Customer A" then if email subject contains username A and save the attachment into folder "A" only. 
  • Suggested answer
    Nived_Nambiar Profile Picture
    Nived_Nambiar 16,591 on at
    Compare Email Subject and Save Attachment
     
    Try like as shown in below demo flow
     
    I have created a folder Invoices inside which have many subfolders, each subfolder representing Customer Name as shown below
     
    Now try as per below steps
     
    1. Use trigger when email arrives with below params 
     
    I assume mail subject starts with Invoice Customer.
     
    2. Use filter array to filter the non inline attachments from attachments array as shown below
     
    3. Use Compose action to remove the Invoice Customer sentence to get customer name from mail subject
    Expression used: 
    trim(replace(triggerOutputs()?['body/subject'],'Invoice Customer',''))
     
    4. Now use get files action to check whether the folder with customer name exists in given location
     
    5. using condition - check whether the folder exists or not 
    Expression used: 
    length(outputs('Get_files_(properties_only)')?['body/value'])
     
    6. If condition is True- follow Yes branch
     
    Under Yes branch - do the following
     
    7. use apply to each to loop attachments list 
     
    7.1 - use get attachment to get attachment content
     
    7.2- use create file action to create file 
    The folder path is dynamic to include customer name in path at the end 
     
     
     
    Hope it helps !
     

    Thanks & Regards,
    Nived N

    Stay connected:
    LinkedIn | YouTube | Blogs

    Was this answer helpful?
    If yes, please mark it as the solution by selecting the checkbox in the discussion thread.
    Your feedback motivates me to keep contributing. Thank you!

  • MM-15111256-0 Profile Picture
    MM-15111256-0 4 on at
    Compare Email Subject and Save Attachment
    Hi Nived,
     
    Yes, customer names like Invoice Customer A (A = John Smith) & so on. We have more around 60 customers.
  • Mark Nanneman Profile Picture
    Mark Nanneman 329 on at
    Compare Email Subject and Save Attachment
    IMO, this isn't the best way to do something like this.  You can have multiple people with the same common name, people can mispell names or even just use alternate spellings, people can get married then the name changes, etc.  You really want to have a unique key of some sort, some sort of customer id number to use.
     
    That said you can do what you're saying, you just need to use string manualation actions / expressions in your flow.

    For instance if your subject was "Invoice for Customer John Smith" something like "Trim(Last(Split(<reference to email subject string>,' Customer ')))" would output "John Smith".

    You can then list your root sharepoint folder and filter on items that are folders, and also filter on folders that have the customer name in the folder name to find the customer's folder.

    But, as I hinted before, this would not be a best practice.  Best practice would be to store the customer names in some sort of Database, even a sharepoint list, and give each one a unique id, and use that unique id in your emails.  Your SharePoint list or other database could have the path to their sharepoint folder stored in a column, and you just lookup the customer by their ID from the email, then grab their sharepoint folder path, then save the attachments to that folder.

    Hope that helps!

    If this helped you, please click "Does this answer your question" and give it a like to help others in the community (+ close the ticket)!

    Power Platform Developer | LinkedIn: Mark Nanneman | Blog: Power Stuff  | YouTube: Mark's Power Stuff  | Buy me a coffee
  • Nived_Nambiar Profile Picture
    Nived_Nambiar 16,591 on at
    Compare Email Subject and Save Attachment
    Hi,
     
    would email subject would be in format of Invoice Customer A , Invoice Customer B like that ?....
     
    Just to confirm 

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,487

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,014

Leaderboard