Forum Discussion

Tom_By's avatar
Tom_By
Copper Contributor
May 18, 2021
Solved

Sharepoint Library notify when there are items expiring within the next 7 days

Hi all, 

 

I've search everywhere and I cannot seem to find an answer to my question.  

 

I have a document library (Not a list) on my sharepoint site and I'd like to set up a flow to notify me if there are items Expiring at any point in the next 7 days.

 

I've got the flow to remind me x days before an item expires, but I want to extend this to search all items and if there are any items that will be expiring in the next 7 days(so if it expires on Days, 1,2,3,4,5,6 or 7) to email me a list of those items. 

 

I know the solution will be very simple, but it has eluded me so far.  

 

For reference, my Document library has a column called (Expiry Date) and using a list to store the documents is not is not suitable for our use case. 

 

Any help would be enormously appreciated.  

  • 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

  • uu06070gmailcom's avatar
    uu06070gmailcom
    Copper Contributor
    We are sorry, the page you requested cannot be found. The URL may be misspelled or the page you're looking for is no longer available.
  • RobElliott's avatar
    RobElliott
    Silver Contributor

    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

    • AaronLakin's avatar
      AaronLakin
      Copper Contributor

      RobElliott 

       

      I'm getting an error relating to the "Get files (properties only)" step.

       

      Error Details:

      The expression "ExpiryDate ge'formatDateTime(utcNow(),'yyyy-MM-dd')' and ExpiryDate le'formatDateTime(addDays(outputs('ComposeToday'),7),'yyyy-MM-dd')'" is not valid. Creating query failed.
      clientRequestId: faa23a5c-42b7-4d80-b41e-f2def2623e7a
      serviceRequestId: faa23a5c-42b7-4d80-b41e-f2def2623e7a

       

      Have I got a typo or a space somewhere i'm missing?

    • mmartini1's avatar
      mmartini1
      Copper Contributor

      RobElliott 

      Hello, for me the array is not bring all documents inside the due date window only one of them, I reviewed all the workflow and found nothing.... 

    • oroberts55's avatar
      oroberts55
      Copper Contributor
      Sharepoint newbie here....

      I have used this to successfully create an alert when files are out of date, thanks for the guide. You mention that it's possile to format the email by adding another compose action. Sorry for what is probably a stupid question, but could you explain how to do this please?

      Thanks in advance!
      • Rob_Elliott's avatar
        Rob_Elliott
        Bronze Contributor

        oroberts55 you can format the html table by adding the following CSS inside a compose action, changing it to taste:


         

        You can copy the CSS from the spoiler below:

        Spoiler
        <style>
        table {
        border: 1px solid #1C6EA4;
        background-color: #EEEEEE;
        width: 80%;
        text-align: left;
        border-collapse: collapse;
        }
        table td, table th {
        border: 1px solid #AAAAAA;
        padding: 3px 2px;
        }
        table tbody td {
        font-size: 13px;
        }
        table thead {
        background: #1C6EA4;
        border-bottom: 2px solid #444444;
        }
        table thead th {
        font-size: 15px;
        font-weight: bold;
        color: #FFFFFF;
        border-left: 2px solid #D0E4F5;
        }
        table thead th:first-child {
        border-left: none;
        }
        </style>
        @{body('Create_HTML_table')}

        Then use the outputs of that compose in your email. Becauase I've also included a company logo in the email I have turned on the code view </> button and added html tags to the email

         

         

         

        Rob
        Los Gallardos
        Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

Resources