Some thoughts on programming stuff

Auto archive files in SharePoint with Power Automate

A pretty common use case scenario where you might want to auto archive files in SharePoint with Power Automate. Sometimes it is important to move some files from one place to other, reducing the size of a library and the number of rows returned in a search. You can always explore the retention policies available out-of-box in SharePoint, of course. But sometimes this feature can present some problems depending on the content type or data type you are working with.

So if you have the option to work with Power Automate, why not using it? Power Automate is great when you need to automate one specific task and it is a very intuitive to use. It is fully integrated with SharePoint and you can take advantage of its connectors to do your tasks.

Prerequisites before you archive in SharePoint

  • Create the target library which will be the Archive;
  • Ensure you have an account with access in Source and Target libraries;
  • Ensure the Content Types match between both libraries. It’s is a good practice to have Content Types configured in the Site Collection level.

Automating the archive using Power Automate

The automated flow can be scheduled in the way you want. You decide when you want to run, if it runs daily or if it runs manually depending on user input, but the main archive logic is built with two commands: Trigger + Compose Date, Get Files and Move Files.

Trigger + Compose Date command

Trigger + Compose Date command - Archive files in SharePoint using Power Automate
Trigger + Compose Date command – Archive files in SharePoint using Power Automate

The initial part of the Flow will have the Trigger and one Compose command. The trigger is pretty straightforward and it’s up to you what to define. In our case, we are making it run once a day. After that, we will have the Compose Date which is declaring a date equals to “Today minus 18 months”. This means we are going to archive anything older than one and a half year.

Compose inputs: @{addToTime(utcNow(),-18,’Month’)}

Get Files command

Get files command - Archive files in SharePoint using Power Automate
Get files command – Archive files in SharePoint using Power Automate

In our example, the Get files command is going to get Pages from one specific Library, ordering by Created column , taking the first 30 results and filtering anything without Check out and Created before the date generated in Compose command, in other words, anything older than 18 months.

Move Files command

Move file command - Archive files in SharePoint using Power Automate
Move file command – Archive files in SharePoint using Power Automate

Finally, the move command! Here you are going to reference the Full Path of every file returned by the Get Files properties. The Target folder will be the path of the Target library, in our case, I created a library called Archive. Not only that, I added a logic to move to folders inside Archive library based on the year the file was created.

The formatDateTim… expression represents: @{formatDateTime(items(‘Apply_to_each’)?[‘Created’],’yyyy’)}

Conclusion

That’s it! You can explore a more advanced logic with different folders, routing rules and even tagging the documents once you have a scenario where you want to auto archive files in SharePoint with Power Automate. Also you might find useful checking other posts related to Power Automate here.

References:
Power Automate documentation

2 Comments

  1. Brice

    Thanks for this, this is exactly what I’m looking for, I have only one problem here!
    I don’t have the possibility to select the “Full Path” Sharepoint object in the move..
    Do you know why I don’t have this?

    Thanks!

    • Wiliam Rocha

      Hey Brice,
      Hope you are dong great!
      If you want, you can send me a message in wiliammbr@gmail.com with a print of your flow. Probably it has something to do with a wrong connector or a dynamic path to your file.
      Best,
      Wiliam

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2024 wiliammbr's blog

Theme by Anders NorenUp ↑