We had a use case where one of our clients had two different SharePoint sites. One SharePoint site was where team members create and modify content.
Another SharePoint site was used by the CEO where team members manually update the finalized content from their site since the CEO wants to only see finalized content.
This allowed for final published content aggregation for review by the CEO in one location.
This way the CEO did not need to go across multiple sites, allowing for a single location for making business decisions easily.
It is quite a tedious process to manually replicate and update content on the CEO’s site in real time. Our client was looking for a way to automate the whole process.
One option is to create a Power Automate workflow on a document library of the source site which will sync the data to the destination-defined document library.
This will work perfectly fine for one source document library. However, challenges will appear when we want to implement the same solution for more than one source document library.
It is not scalable or recommended to create a Power Automate workflow every time we create a new document library on multiple sites, so this approach would not easily be scalable.
There is no out-of-the-box or straightforward way to achieve the requirement of replication across a growing number of source document libraries.
We, therefore, implemented a reliable solution using SharePoint lists and Power Automate which can sync data from multiple document libraries and their folders across multiple sites to the destination folders (CEO Consolidated content).
By using this approach we are able to manage the replication of thousands of folders/files across multiple sources and destinations.
SharePoint Lists structure
- Create one central Mapping List. In this list, we are managing the source location of different sites and the destination location of the CEO Site.
- Add Source path and destination path in the central mapping list as per the below example
- Added an InternalID column in the destination library in which we will store the ID of the source’s folder/file. This InternalID will be used to check whether a folder/file exists or not at the destination location. This will be the key column between the source and the destination.
Power Automate Solution Structure
We need to create a Power Automate solution and will need to create three different Power Automate flows inside the solution as shown below. The Content Replication Parent Flow will run first and inside that flow, we will run two child flows for content replication and for cleaning up files
- Content Replication Parent Flow (Parent Flow])
- Content Replication (Child Flow)
- Clean-up Files (Child Flow)
Power Automate Schedule
From an operational perspective, we schedule the Content Replication Parent Flow daily at midnight.
It will further call the Content Replication and Clean up Flows and will pass the current mapping ID in it.
Content Replication Parent Flow
This Flow extracts the active mappings from the Central Mapping List and loops through each active mapping.
This Flow passes the current mapping details to the Child Flows (Content Replication and Clean Up Flow) as seen in the image below.
Content Replication
- This Flow will Copy Content from the source to the destination based on the current mapping. It will receive the mapping details from the Parent flow.
- Loop through all folders/files of the source path mentioned in the mapping and fetches the folder/files modified after the date-time mentioned in the “LastFlowRunTime” column of the central mapping list. After getting all the folder/files it will check folder/file already exists on the equivalent destination path same as the source path using the Internal ID column which we created in the destination library
- If it exists, then we overwrite it.
- If it does not exist, then the Flow will create the folder/file
Clean-up Files
- This Flow will remove files from the destination which were deleted from the source
- Loop through all folders/files in the destination path mentioned in the mapping and will fetch the folder/files. After getting all the folder/files it will check whether the folder/file already exists in the equivalent source path using the Internal ID column.
- If the folder/file is not found in the source path, it means that the folder/file was deleted from the source, so we delete it from the destination.
- This way, it will delete all the files from the destination which were originally deleted from the source.
After implementing the solution, we found that when we move a folder/file to another folder then it does not modify the modified date of the moved subfolder or file.
So content movement between folders and libraries can cause an issue, where the updates don’t get reflected in the destination.
In practice, we found that the moved folder does not get captured in the next cycle of the Power Automate Flow, as we are only synchronizing the folders/file which was modified after the previous Power Automate Flow run, based on the timestamp which we store in “LastFlowRunTime” columns of the central mapping list, and therefore will not get synced to the destination equivalent location.
We had further optimized the solution to overcome this move folder/file issue and made the changes in the solution as shown below.
SharePoint Lists structure
- Create Moved Mapping List (For Moved Folder/File: a complete replica of central mapping list)
Content Replication
- This Flow will Copy Content from the source to the destination based on the current mapping. It will receive the mapping details from the Parent Flow.
- Loop through all folders/files of the source path mentioned in the mapping and will fetch the folder/files modified after the value of “LastFlowRunTime”. After getting all the folder/files it will check whether the folder/file already exists on the equivalent destination path the same as the source path using the Internal ID column which we created in the destination library
- If it exists, then the Flow will overwrite it.
- f it does not exist, then a further check of the folder/file to see whether it exists anywhere in the destination library. If it exists somewhere in the destination library, then it seems the file has moved to another folder in the source location. If so, it will create an entry for the parent folder of the folder/file in a Moved Mapping List. If it does not exist in the library at all, then the Flow will create it as a new folder/file
Power Automate Solution Structure After adding Move functionality
- Content Replication Parent Flow (Parent Flow)
- Content Replication (Child Flow)
- Clean-up Files (Child Flow)
- Replicate Moved Content (Flow for moved folder/file attached on Moved Mapping SharePoint List on Item create the event)
Replicate Moved Content
- This Flow is a complete replica of the Content Replication flow. But it only triggers for the specific moved folder file which we created in the Moved Mapping list while executing the Content Replication Flow.
- Power Automate will trigger when any new item will be created in the Moved Mapping list and move the folder/file to the destination path mentioned earlier.
In Conclusion, Mirroring the SharePoint document library contents to multiple sites is an important task that needs to be done with care, and having a reliable SharePoint development company with expertise in Microsoft Sharepoint services is crucial for efficient and smooth mirroring.
Want to talk?
Drop us a line. We are here to answer your questions 24*7.