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 / PA rule to notify when...
Power Automate
Answered

PA rule to notify when files are added or modified for a (sub)folder

(1) ShareShare
ReportReport
Posted on by 46
I am struggling to create a power automate rule to do the following:

1. Send a single email once during a file editing session or when a file is created

The email SHOULD contain the full path and name of the file

It should NOT occur for every edit - just once - whenever a file is created or modified within a folder AND subfolders of a library in a particular sharepoint site

 

It seems somewhat difficult to achieve because if you do not start with the correct trigger and subsequent components, you end up down a rabbit hole.

Copilot has only been partially helpful because the solutions offered result in a flood of emails which just destroys the rules purpose.

Clearly, the correct question has not been asked properly, because the answer is wrong.

Any help in refining the question to get CoPilot to offer the right solution, or indeed the right solution flow, would be much appreciated.

 

IT Support

Categories:
I have the same question (0)
  • Suggested answer
    Tomac Profile Picture
    4,105 Moderator on at
    Seems like you want to start with this trigger:
     
    and then have a control that checks if that specific file triggered the flow recently and not resend the email for a specific amount of time.
     
    By default, the online editor and even the apps will save the file as soon as you stop typing, which triggers a file edit and will run your flow. Since you don't want all of those extra triggers, you'll need to keep track of recent triggers. I suggest using a SharePoint List, recording the file ID and timestamp after sending the email. At the beginning of the flow, query the list to see if that file ID exists with a timestamp in the last, say, hour. If yes, update that row to the new timestamp (so you have another hour before it will send an email) and if no, send the email.
     
    Your flow would be structured like this:
     
    Trigger: When a file is created or modified (properties only)
    Actions:
    1.  Get Item targeting your recording list, with an ODATA query for the current file ID and timestamp less than the current time minus one hour, and set Order By to timestamp desc
    2.  Condition: If the length of the returned value array is greater than 0
      1.  If yes, use an Update Item action on that row's ID to update the timestamp to the current time
      2.  If no, Send An Email with the file details (you can get the file path and filename from the trigger dynamic content)
    It would look something like this:
     
    You'll need to fill in all of the details for these actions, but I'm sure you can get there.
  • VS-03091503-0 Profile Picture
    46 on at
    Hi There Tomac
     
    Apologies for the delay getting back.
     
    I've spent some time interpreting the very detailed description but am still having difficulties. Not a single developer bone in my body.
     
    I've attached a series of screenshots beginning Flow x - Component name/function. I've used Copilot as much as I can but I've saturated out. Any debug assistance would be appreciated. i've not included the send email details because I've got that part working.
     
    Cheers
    Flow 1 -  When file is created-modified.png
    Flow 5 - Update Item.png
    Flow 2 - Get Items Filter Query & Order By.png
  • Suggested answer
    Tomac Profile Picture
    4,105 Moderator on at
    Looks like Copilot led you wrong. AI is not great at this stuff, so I wouldn't recommend letting it write your code for you. Use it to validate complex formatting if needed, or use it to search for resources, but not for direct code suggestions.
     
    I just went and built this flow so here's how I made it work:
     
    Let's start with the SharePoint List created for this. My list has two fields that I added and am using:
     
    I added the fields FileID and LastModified. I'm not using the built in ID and Modified fields because those track the list item itself, not the file properties we want to compare to. Note we can't use the properties of the file itself either, because Modified will always be within the last hour because that modification is what triggers our flow.
     
    Next up is the Get Items action:
     
    Note that the "Order By" value is not an expression, it's just plain text. The filter query is:
    FileID eq '@{triggerOutputs()?['body/{Identifier}']}' and LastModified gt datetime'@{formatdatetime(addhours(utcnow(),-1),'yyyy-MM-ddTHH:mm:ssZ')}'
    Note that the above code is formatted to copy/paste directly into the text field.
     
    This filter query is an ODATA formatted filter, checking two things:
    1. If the trigger's file identifier is listed in our SP List
    2. If our custom LastModified field is within the last hour (greater than the current time minus one hour and formatted the way we want)
     
    After that we move to our Condition:
     
    That expression is:
    length(outputs('Get_items')?['body/value'])
    Note that this is formatted to be copy/pasted into the Expression Editor
     
    This is checking to see if we got anything back from our Get Items action.
     
    Now we move into the results of our Condition:
    If yes, we update the existing List row to set the LastModified time to the current time, formatted the way we want:
    formatdatetime(utcnow(),'yyyy-MM-ddTHH:mm:ssZ')
    The ID expression is:
    outputs('Get_items')?['body/value']?[0]?['ID']
    This expression will skip the need for a loop by directly referencing the first ID value
     
     
    On the If No side, first we send the email and then we create the list item so future runs will know that this file was recently modified. We're using the trigger's Identifier value and setting our LastModified time to now in the format we want:
    formatdatetime(utcnow(),'yyyy-MM-ddTHH:mm:ssZ')
     
     
    Note that if you browse into the list the timestamps may not show in your expected timezone, but we're storing it as UTC and comparing UTC against it so the math will math.
  • VS-03091503-0 Profile Picture
    46 on at
    Hi Tomac
     
    I've created a flow as described but although the flow debugs and tests "successfully", it is neither sending an email nor updating the list.
     
    Have attached a PDF of the flow. In the Get Items component, I've entered the top folder value as well as leaving it blank for the whole list.
     
    The flow runs but it always goes down the False route and skips sending an email and updating the list. (Have tried the format of the Last Modified column in the SP list as text and Date and Time)
     
    It feels very close but clearly I have gone "Flow Blind". Apologies for missing what is probably very obvious.
     
    If the flow output would be useful, let me know and I'll output to a PDF.
     
    Kind Regards
     
    Vangelis - IT Support
     
     
  • Tomac Profile Picture
    4,105 Moderator on at
     
    The PDF hasn't gone through virus scans yet so we can't see it, but from your description you've reversed the If Yes and If No parts of the Condition action - in my example, If Yes updates the existing "file is being edited and email was recently sent" list item, If No sends the email and creates that list item.
     
    In the future, please paste screenshots directly into the comment box on these forums, so the images show up immediately.
  • Tomac Profile Picture
    4,105 Moderator on at
    @VS-03091503-0 Ok the PDF is finally available. On review, your flow looks correct. Can you screenshot a completed flow run and post that so we can see how the logic of the app was followed? Be sure to include the Outputs of your Get Files action and the trigger. Also include a copy/paste of the SP List you're using to track these File IDs so we can verify what is and is not in the list.
  • VS-03091503-0 Profile Picture
    46 on at
    Hi Tomac
     
    Because of the 3 file attachment limit, I've done a Part 1, 2, 3 set of uploaded files for the whole flow. This is Part 1.
     
    The List is blank/empty, so I've not screenshot that.
     
    Thanks again.
     
     
    Flow 1 - Created-Modified 1a.png
    Flow Run 1-screenshot.png
    Flow 1 Created-Modified 1b.png
  • VS-03091503-0 Profile Picture
    46 on at
    Part 2 of 3
    Flow 1 Created-Modified 1c.png
    Flow 1 - Condition.png
    Flow 1 - Get Items.png
  • VS-03091503-0 Profile Picture
    46 on at
    Part 3
    Flow 1 - For Each.png
    Flow 1 - Email Skipped.png
    Flow 1 - Create Skipped.png
  • Tomac Profile Picture
    4,105 Moderator on at
    @VS-03091503-0 I'm not downloading and opening a bunch of PDFs. Please copy/paste the screenshots directly into the comment box on this forum.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 816

#2
Valantis Profile Picture

Valantis 603

#3
Haque Profile Picture

Haque 566

Last 30 days Overall leaderboard