Forum Discussion
Sharepoint Library notify when there are items expiring within the next 7 days
- May 18, 2021
Tom_By yes you can do this using an array variable as shown in the screenshots below. In my Documents library there are 4 documents that are due for review in the next 7 days:
The flow runs at 13.00 every day and the first action is to initialize an array variable. When doing date comparisons you need to have the date format as yyyy-MM-dd. So next we add 2 compose controls, one for today's date and one for the date 7 days ahead and format them a shown:
Next, add a get files (properties only) action. But we only want to bring those items back from the library where the NextReview date is greater than or equal to the ComposeToday and less than or equal to the Compose7Days. So in the Filter Query field add NextReview ge '{output of the ComposeToday}' and NextReview le '{output of the Compose7days}'
So that we can have them in order in the email we add NextReview into the Order By field:
Next, add an Apply to each and select value from the dynamic content. I want to convert the NextReview date back to UK format but you might not need these next steps: inside the apply to each add a compose control and add the NextReview column. Then add another compose and format it as shown.
Next add an append to array variable and add the name and review date - I've used the output from the ComposeFormatDate compose for this:
Next, - outside the apply to each - if you want to you can add a create html table action and add the array.
Finally send the email and use the output from the create html table action.
The email looks as shown below. It is possible to add another compose action to add formatting to the table but I've not done that on this occasion.
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Worked a treat, thanks! I'm only testing at the moment, I get this:
Is there a way to format the dates so that they show as dd/mm/yyyy?
And how do I change the font?
Thanks again 🙂
- Rob_ElliottJul 19, 2023Silver Contributororoberts55 you'll see in my earlier post that I have the compose renamed to ComposeFormatDate which puts the date into dd/MM/yyyy format which is used in the append to array variable.
- oroberts55Jul 25, 2023Copper Contributor
I have everything working as it should, thanks again for your help so far.
I am getting a daily email, but often this is blank as there are no files that are due to expire - I was wondering if there is a way of only sending the email if necessary? i.e. if there are no items that are due to expire then no email is sent?
- JonathanWeaverJul 27, 2023Copper ContributorYou can use a Condition for this check. However, I'll offer 2 ways to make it work.
1. Depending on how you have the Array Variable setup, you can check the length of the variable. Use a Compose action with the expression "length(variables('arrayName')). Then in the Condition, If outputs(compose) is greater than 0 | Yes = Send Email, No = do nothing.
2. Add a counter Integer variable that increments inside the Apply to Each. Then in the Condition, If intVariable is greater than 0 | Yes = Send Email, No = do nothing.
- oroberts55Jul 20, 2023Copper Contributor
Sorry, my bad, turns out I hadn't followed the instructoins properly and was just pulling through Expiry Date from the file properties - I've changed it now and it works perfectly.
Final question (for now) - how can I change the font of the table so that it matches the rest of the email please? Again, probably very simple for someone who knows what they're doing!
- oroberts55Jul 20, 2023Copper ContributorDon't worry, I've got it sorted.
Thanks again for all your help 🙂