cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jleung
Frequent Visitor

Manipulate filename from email attachment

I used the SharePoint create file action to save file to SharePoint library from email attachments. It overwrites the file if it already exist. I then try to add with timestamp to the filename but only as prefix because the "Name" dynamic content from email attachment includes file extension. Ideally, the new filename should be [filename]-[timestamp].[file extension]

 

I am still new to use Flow. Anyone has suggestion or work around for this? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
faustocapellanj
Memorable Member
Memorable Member

Hi @jleung,

 

This is the approach I took to achieve your desidred outcome. I will make the assumption that you want to create the files in the SharePoint library from attachments every time a new email arrives.This may be a lengthy post since it includes screenshots.

 

  1. The first step is "When a new email arrives". Make sure the options Has Attachments and Include Attachments are set to Yes.
    FileName-1.png

  2. In the next two steps, add an "Initialize variable". I used the first variable for the AttachmentName and the second for the Timestamp.
    FileName-2.png

  3. In the next step, add an "Apply to each". In the output field, select Attachments from the Dynamic content.
    FileName-3.png

  4. Within the "Apply to each", you will add all the remaining steps for the Flow.
  5. The first step is "Set variable". For the Name, select AttachmentName and for the Value, select the Name(Attachment name) from the Dynamic content.
    FileName-4.png

  6. The next step is another "Set variable". For the Name, select Timestamp and for the Value, build the Expression below. This Expression uses the formatDateTime function to format the utcNow() date time to the following format: 'yyyyMMdd-hhmmss'.
    formatDateTime(utcNow(),'yyyMMdd-hhmmss')

    FileName-5.png

  7. The next step is a "Data Operations - Compose" - (Compose-GetFileName), which is used to extract the File Name of the attachment without the extension by using the Expression below. The Expression splits the AttachmentName variable at the period(.) and retrieves all the text before it.
    first(split(variables('AttachmentName'),'.'))

    FileName-6.png

  8. The next step is another "Data Operations - Compose" - (Compose-GetFileExtension). This is similar to the step above, but the Expression retrieves the file extension after the period(.)
    last(split(variables('AttachmentName'),'.'))

    FileName-7.png

  9. The next step is another "Data Operations - Compose" - (Compose-ConcatFullFileName). This step concatenates the output from the Compose-GetFileName step, the Timestamp variable, and the output from the Compose-GetFileExtension step. The Expression below has all the details for the concat funcion.
    concat(outputs('Compose-GetFileName'),'-',variables('Timestamp'),'.',outputs('Compose-GetFileExtension'))

    FileName-8.png

  10. And the final step is the SharePoint "Create file". Select the Site Address and the Folder Path. For the File Name, select the output from the Compose-ConcatFullFileName. And for the File Content, select the Content(Attachment content) from the Dynamic content. Set the name of your Flow, save it, and test it.
    FileName-9.png

Please let me know if it works or if you have any questions.

 

Regards,

Fausto Capellan, Jr

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

View solution in original post

43 REPLIES 43
faustocapellanj
Memorable Member
Memorable Member

Hi @jleung,

 

This is the approach I took to achieve your desidred outcome. I will make the assumption that you want to create the files in the SharePoint library from attachments every time a new email arrives.This may be a lengthy post since it includes screenshots.

 

  1. The first step is "When a new email arrives". Make sure the options Has Attachments and Include Attachments are set to Yes.
    FileName-1.png

  2. In the next two steps, add an "Initialize variable". I used the first variable for the AttachmentName and the second for the Timestamp.
    FileName-2.png

  3. In the next step, add an "Apply to each". In the output field, select Attachments from the Dynamic content.
    FileName-3.png

  4. Within the "Apply to each", you will add all the remaining steps for the Flow.
  5. The first step is "Set variable". For the Name, select AttachmentName and for the Value, select the Name(Attachment name) from the Dynamic content.
    FileName-4.png

  6. The next step is another "Set variable". For the Name, select Timestamp and for the Value, build the Expression below. This Expression uses the formatDateTime function to format the utcNow() date time to the following format: 'yyyyMMdd-hhmmss'.
    formatDateTime(utcNow(),'yyyMMdd-hhmmss')

    FileName-5.png

  7. The next step is a "Data Operations - Compose" - (Compose-GetFileName), which is used to extract the File Name of the attachment without the extension by using the Expression below. The Expression splits the AttachmentName variable at the period(.) and retrieves all the text before it.
    first(split(variables('AttachmentName'),'.'))

    FileName-6.png

  8. The next step is another "Data Operations - Compose" - (Compose-GetFileExtension). This is similar to the step above, but the Expression retrieves the file extension after the period(.)
    last(split(variables('AttachmentName'),'.'))

    FileName-7.png

  9. The next step is another "Data Operations - Compose" - (Compose-ConcatFullFileName). This step concatenates the output from the Compose-GetFileName step, the Timestamp variable, and the output from the Compose-GetFileExtension step. The Expression below has all the details for the concat funcion.
    concat(outputs('Compose-GetFileName'),'-',variables('Timestamp'),'.',outputs('Compose-GetFileExtension'))

    FileName-8.png

  10. And the final step is the SharePoint "Create file". Select the Site Address and the Folder Path. For the File Name, select the output from the Compose-ConcatFullFileName. And for the File Content, select the Content(Attachment content) from the Dynamic content. Set the name of your Flow, save it, and test it.
    FileName-9.png

Please let me know if it works or if you have any questions.

 

Regards,

Fausto Capellan, Jr

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Thanks so much for your approach. Very detail explanation too and really helpful!

 

I modified the expression in the (Compose-GetFileName) step so that if the filename includes a dot (.), it will also include it.

 

The expression is substring(variables('AttachmentName'),0,lastIndexOf(variables('AttachmentName'),'.'))

 

 

Hi @jleung,

 

Glad to hear the approach helped you in completing your Flow.

 

Regards,

Fausto Capellan, Jr

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Excellent solution and works as expected.

 

I was wondering how I could add the ability to change the actual file name in addtion to adding the date. For example the attachment comes in as book1.xls, in the end I'd like it to post to the SP library as Monday Report-(Todays Date).xls

 

Thanks,

 

Kevin

Hi @KevinStef

 

You can check out step 9 and follow a similar approach using the concat() function. You can set any number of parameters to this function to complete the expression you need for your new file name. Please let me know if you have any questions.

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!
Anonymous
Not applicable

Bravo! Exactly what I needed!  Thank you. Would be great if MSFT would simplify this with a simple rename step as the current steps are too many.

Hi Fausto, i tried below format of floe to get attachment and save it on share point document library, but in step 10 in file name field, i am not able to see output option in dynamic content. Please advise.

Hi @RVKONDRA

The file name field in step 10 actually comes from the Compose action in step 9. Were you able to create that step asn shown above? If so, can you please post a screenshot so I can take a look at it?

 

Thanks,

Fausto Capellan, Jr

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Hi Fausto, thanks for coming back. I am unable to put screen shots in this message. Do you know how to put screen shots when you reply?

 

 

Hi Fausto, have you received my message with screen shots of my flow?

 

RVKondra

Hi @RVKONDRA

 

Yes, I did. Please check your inbox when you have a chance.

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

very detail oriented - thanks for the solution.

I know this is an old thread, but wanted to say thank you very much! I've spent a solid 4 hours trying to figure out how to manipulate names of email attachments with no luck. This worked like a charm.

 

Any ideas on how this can be modified to get the extension if the file name is "Purchase order - 0012171 Rev .1.pdf" as the solution provided would result in the extension being .1.pdf

 

I am tring to save only the .pdf files and not the jpg or token files that come with emails but more and more are arriving with extra full stops in the filename that make the current solution report incorrectly as false.

Hi @Kgrange 

 

This post by a community staff shows all the steps needed to achieve your solution. Please try it and let me know.

https://powerusers.microsoft.com/t5/General-Flow-Discussion/Split-period-separated-strings-and-conca...

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Brilliant stuff @faustocapellanj - is there any way you could manipulate an attachment name from a Sharepoint list so that it's accessible as an OFT?

I've tried just about every approach I can think of, but each time I try I get a permissions error. I'm trying to inject Powerapps info into an email, send it to a Sharepoint list then return it as an attachment, where it gets emailed to the original author. 


Capture.PNG

 

Hi @loganl 

Can you please post a screenshot of the Flow you've built so I can take a look? Also, please let me know if I'm right: you're manipulating information thru PowerApps and storing it in a SharePoint list. Once that item is created, you need to get it, create a new attachment, and send it to the person that created the item?

Thanks.

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

That's correct, @faustocapellanj - though I've tried so many different methods now that I'm beginning to believe MS doesn't support manipulating OFTs without getting this error. Here's a stripped-down version of what I'm attempting to do. I understand the mechanics, and can build a workable flow for this, except I can't open the final result!

The only way I know how to directly create the OFT file is simply adding the "OFT" extension to the attachment. I suspect that's where I'm screwing things up.


1.png2.png

Your guidance is so appreciated! I'd love to use a format other than OFT, but this will be for a MS sales contest, and the sellers require a brand-approved template. 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,672)