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 / Attaching a PDF docume...
Power Automate
Unanswered

Attaching a PDF document that has a new file name each month

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi guys

 

I hope this post/ thread is okay. I want to find out if it is possible to automate a Outlook process whereby a file is attached, but the file name changes each month. In my scenario, I want to send an invoice, but the filename is not going to be the same each month. How do I go about successfully implementing this, if it is possible?

I have the same question (0)
  • Pstork1 Profile Picture
    69,543 Most Valuable Professional on at

    Have you considered doing this in regular Power Automate instead?  Then you can create a variable with the filename for that month (depending on what naming convention you use) and then give the attachment that name when you attach it to Outlook.  

  • VJR Profile Picture
    7,635 on at

    Hi @BarendGoussard 

     

    Both Power Automate and Power Automate Desktop has the provision to pass the changing name variables while sending an email.

    But is there a pattern in the changing file name each month?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @VJR 

     

    Yes, there is a pattern. The client/ company initials as text is first followed by the date of invoice generation. E.g. ABC301121.

    So each month the first 4 digits will vary. Would it be possible to automate such task in the first place, as the task would have to look at the current month and then send that file associated with it.

     

    I hope this makes sense...

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @Pstork1 

     

    You are referring to the Power Automate web app? Yeah it doesn't really matter where it happens, I just can't seem to get to the point where I can attach a file that has a ever-changing name. My naming convention is rather simple, it is client initials followed by date of invoice creation, i.e. ABCDddmmyy e.g ABCD301121

  • VJR Profile Picture
    7,635 on at

    Hi @Anonymous ,

     

    Would it be possible to automate such task in the first place, as the task would have to look at the current month and then send that file associated with it.

     

    Yes, that's possible.

     

    Your flow would look like this.

    As example I have taken the client name and the folder path in variable.

     

    VJR_0-1638263695049.png

     

     

    The line number 4 above will display the complete path of the file that you want to attach.

    VJR_3-1638263958627.png

     

     

    Then use that variable in your Email action

     

    VJR_1-1638263817210.png

     

     

    You can copy paste the below code in a new PAD editor and check the same.

    Make sure to add those variables shown in the right.

     

     

    DateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDate
    Text.FromCustomDateTime DateTime: CurrentDate CustomFormat: $'''ddMMyy''' Result=> FormattedDate
    SET FileToAttach TO $'''%MyFolder%\\%ClientName%%FormattedDate%.txt'''
    Display.ShowMessage Message: FileToAttach Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
    Outlook.SendEmail Instance: `` Account: `` SendTo: `` IsBodyHtml: False Attachments: FileToAttach

     

     

    PS: I have used txt as an example. You need to change it to pdf in line number 3.

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks @VJR . I will give it a shot later and let you know. The clientname and myfolder variables, did you make then input variables?

  • Pstork1 Profile Picture
    69,543 Most Valuable Professional on at

    As long as the client initials are available creating the filename using that convention should be fairly easy in regular Power Automate using the Concat() and FormatDateTime() functions.  You may be able to do it in PAD as well, but I find the string manipulation functions to be much more limited in PAD.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @VJR 

     

    how did you create the flow variable FileToAttach? I have created the two standalone input variables ClientName and MyFolder.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi again @VJR 

     

    So I was able to get it to work, somehow. The only issue I have is that the process attaches ALL the files. I have created a flow variable that sorts all the files in the specified order, but I need to select only the most recent file in that folder. There are multiple files that start with ABC, but each is for a different month. So close yet so far.

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Since you told it how to write the filename, you should be able to tell it which file you want to attach.

     

    If you are getting a list of files and trying to attach from there, in "Get Files" make sure it is sorted by Date Modified Descending in the drop down options of Get Files, then, you can use %Files[0]% to reference the latest file.

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 410

#2
Vish WR Profile Picture

Vish WR 289

#3
David_MA Profile Picture

David_MA 282 Super User 2026 Season 1

Last 30 days Overall leaderboard