Move Old documents in SharePoint Automatically using Power Automate Scheduled Cloud Flow

Best way to work with Scheduler Power Automate: Move Old documents in SharePoint Automatically using Scheduled Cloud Flow – Microsoft 365

No comments

Loading

In this “Scheduler Power Automate (Scheduled Cloud Flow)” article, we will learn how to move old documents in SharePoint online automatically to another site using the Power Automate scheduled Cloud Flow step by step.

Step by step developing a scheduler flow in Power Automate – Scheduler Power Automate (Move Old documents in SharePoint)

Login to your flow environment For an example: https://india.flow.microsoft.com/manage/environments/Default-8bde4d0e-9bbb-42a2-86ca-46884a08df50/flows

Click on the Scheduled cloud flow from the New Flow -> Build your own from blank navigation.

Then configure the below:

Name the flow name.

In the run flow configuration, configure the flow starting date and time.

For repeat, every, configure the second/minute/hours/day/week/month.

Click on the “Create” button.

Scheduler Power Automate - Build a scheduled cloud flow in Power Automate
Build a scheduled cloud flow in Power Automate

Scheduled Cloud Flow – When to use scheduled cloud flow?

Stay on top of what’s important without the effort—you choose when and how often the flow runs.

Examples:

Automate team reminders to submit expense reports
Auto-backup data to designated storage on a regular basis

By now we have learned the purpose of the scheduled flow, and now we will learn how to develop this Power Automate Flow.

Here is our scheduled Power Automate Flow:

Scheduler Power Automate - Recurrence or scheduler flow in Power Automate

Scheduler Power Automate - Condition in recurrence or scheduler flow - Power Automate

Scheduler Power Automate to perform automatic job

Now we will explain each action/step individually.

Recurrence or scheduler configuration in Power Automate

Recurrence or scheduler configuration in Power Automate
Recurrence or scheduler configuration in Power Automate

Get files (properties only) – from the source site library

Get files (properties only) - from source site library
Get files (properties only) – from the source site library

Here we need to pass the below two parameters:

  • Site Address: Source site address
  • Library Name: Source site library display name

Apply to each – For each loop in the get file properties collection

Apply to each - For each loop in the get file properties collection - Scheduled Cloud Flow
Apply to each – For each loop in the get file properties collection

Now onwards, whatever actions we are going to show will be inside for each loop.

Is Greater Than Equal To Condition in Power Automate For Each Loop

Is Greater Than Equal To Condition in Power Automate For Each Loop
Is Greater Than Equal To Condition in Power Automate For Each Loop

Here we are checking the condition when the file was created, for this example, we are all files that were created 365 days ago (one year ago), for this we have given the below condition for the modified column with the below expression:

formatDateTime(addDays(utcNow(),-365),'yyyy-MM-ddThh:mm:ssZ')

We can check the condition in other ways also.

The below condition will return the document created 60 days ago.

@lessOrEquals(items('Apply_to_each')?['Modified'],addDays(utcNow(),-60))

If you want to move the file from one library to another library (within the same site or a different site) when the file is older than 5 years, the conditional expression should be as below:

@lessOrEquals(items('Apply_to_each')?['Modified'], subtractFromTime(utcNow(), 5, 'Year'))

Get File Content Action in Power Automate inside for each loop

Get File Content Action in Power Automate inside the for each loop
Get File Content Action in Power Automate inside for each loop

If the modified date condition returns the true value – this part of the flow will be executed otherwise it will go to the no section.

Using the get file content, we will get the actual file content for the source site.

Here we need to pass the below two parameters:

  • Site Address: Source site address
  • File Identifier: Identifier (unique id of the file) – this will get automatically from the dynamic content selection tab.

Move the file to another site in SharePoint using Power Automate

Move file to another site in SharePoint using Power Automate - Scheduled Cloud Flow
Move the file to another site in SharePoint using Power Automate

Here conditionally file will be moved to the destination site – in the move file action we need to pass the below parameters:

  • Site Address: Source site address
  • Destination Site Address: Destination/target site address
  • Destination Folder: Folder path – here we have given the default documents library root path.
  • If another file is already there: Dropdown selection – here we have selected “Move with a new name”

Other options in the “If another file is already there” dropdown list are:

We can see the below options in the “If another file is already there” move action:

  • Fail this action
  • Move with a new name
  • Replace
  • Enter custom value
If another file is already there in power automate move action - Scheduled Cloud Flow
If another file is already there in power automate move action

How to delete a particular file using Power Automate in the SharePoint document library?

In this PoC, the delete file action is not relevant or needed but to showcase how to use delete the particular file conditionally in SharePoint using Power Automate flow, we have added this delete file action – you may ignore this action while you are referring to this article and trying moving older files to newer library location.

How to delete a particular file using Power Automate in SharePoint document library
How to delete a particular file using Power Automate in the SharePoint document library

Here in the delete file action, we need to pass the below two parameters:

  • Site Address: Source site address
  • File Identifier: Identifier (unique id of the file) – this will get automatically from the dynamic content selection tab.

Scheduled Cloud Flow – Few-Recommendation

  • Instead of passing the site URL and document library name directly to the action parameter – create a corresponding dynamic variable and pass the variable name to the actual action parameter. Here, we have just used the Site URL and Document library name as is direct to the flow action which is not recommended.
  • While querying the file properties action – do not get all properties to value instead use the query count or camel query to limit the query result. If the query returns more than five thousand items, it will through a threshold limit error.

Disclaimer – Scheduled Cloud Flow

Do not use this flow (move or delete action) as is – first create this flow in your test environment, and if you find it is working as per your expectation, then you may deploy this flow to the production environment.

Summary: Scheduler Power Automate

Thus in this article, we have learned the below with respect to Scheduled Cloud Flow using Power Automate:

  • How to move older files to a different site in SharePoint Online based on the condition using Power Automate?
  • How to delete older files in SharePoint Online using Power Automate?
  • How to develop a scheduler flow in Power Automate which runs periodically?
  • How to work with move file action in Power Automate?
  • How to work with the delete file action in Power Automate?

See Also: Power Automate Tutorial

You may also like the below Power Automate tutorials:

 

 

 

 

 

About Post Author

Do you have a better solution or question on this topic? Please leave a comment