Wednesday, June 3, 2020

Microsoft Flows: Move Library documents

This article is to go through about Get Files (Properties Only), Move File and Move Folder Sharepoint actions in Microsoft Flows through below implementation.

We want to archive all the files / folders in one library to Central Archive (Separate Site Collection).

Source Library: A Document library with versioning enabled and also has some Meta data columns.

Destination Library: 
  • In Destination Library, we need to make sure the versioning is enabled (as we have it in Source) with higher or same limits as in Source Library. 
  • It should also include all the meta data columns as in Source Library as Move Actions would fail if schema doesn't match from Source
  • Few extra columns like Archived on and SourceLoc to capture archival info.

Below are the steps to achieve the functionality
  1. Use Get Files (Properties Only) action to fetch all the files and Folders in the given source library
    Note: We need to make Include Nested Items Property to "No" as we don't want the documents inside folders and when we move folders, it would go along with inside content.

  2. Apply to Each action to lop through each File / Folder fetched from above action
  3. Condition action to check if the current file is a File or Folder. We have IsFolder property to identify it.
  4. Based on above condition, 
    • If its folder, use Move Folder action to move complete folder along with content inside it to destination library
    • If Its File, use Move File action to move the corresponding file to destination.

      Note: Both above actions work same as the Move to commands we use in sharepoint
  5. Once the Move action is completed, in order to update the Archival meta data in destination, use Update File Properties  action.

    Here as we either moved File / Folder in above action, we use below if logic to fetch the correct ItemID to update.  
    If(empty(body('Move_file'))
            ,body('Move_folder')?['ItemId']
            ,body('Move_file')?['ItemId']
      )

Complete flow would appear as below,


When we run this flow, it moves all files from Main Library in Demo Site to Documents Library in ArchivalCenter.

No comments:

Post a Comment