Flow - Moving Specific Files From a SharePoint Library to Another

Flow - Moving Specific Files From a SharePoint Library to Another

Occasionally, users will want to organize their files in different libraries according to the type of file or category it belongs to. Completing this task manually can become somewhat tedious and time-consuming. In this page, you will learn how to create a flow that will perform this activity automatically. Essentially, the flow you create will identify the different categories under which you have labeled the files inside a "main library".  It will then move each of the new or recently modified files to the folder assigned to their specific category.


Procedure

1. Create the libraries.
    a. First, ​you will need to create at least 2 different types of library in SharePoint:
        i. Personal - With access permission only for you or the owners of the library.
        ii. Shared​ -  With access to those in the tier you mean to share specific files with (a team, group or specific
            individual members).

Note: You will have to make sure you create only one library and create a template of the official version to make sure all of the interacting libraries have the same columns and settings. In order for a file to move from one library to another the libraries involved must be identical.

    b. To create a library in your site, simple go to 'Site Contents'  and click on '+New'. Give it a name and a
        description.

    c. Now that we have created the first library, we will want to edit it according to our needs.

Note that the library ​displays 4 default columns: 'Type of Document', 'Title', 'Modification date' and 'User who last modified the file'. We will only add one more column called 'Label':

Note: This column will determine the 'tier' of the document added to the library and based on its value, it will be sent to a specific library. 

        i. Click on 'Add column'. The drop-down menu will be displayed.
        ii. Select 'Number' and fill out the required information (warning: do not modify the 'Type' field. This will allow
            the label of the file to be read as a numeric value instead of  being identified as a text or an object in step '2.3-
            Setting Conditions')
        iii. Click on 'More options' at the bottom of that section and assign '1' as the 'Minimum allowed value' and '3' as
             the maximum allowed value. 
        iv. Make it a required field and click 'Save'.
    d. We now want to turn this library into the template so that all of our libraries are identical. ​
        i. Go to the 'Library settings' by selecting the gear on the top right of the page.
        ii. Under 'Permissions and Management' select 'save document library as a template' and follow the prompts to
             create the template.
    e. Following this action, we will go back to 'Site Contents'​ and click on the '+New' button once more, except on
        this occasion we will select 'App'.​
        i. We will navigate this catalog until we find the template we just created.
        ii. Create 3 new libraries from this template and name them 'Tier 1', Tier 2' and 'Tier 3'

    f. We should now have 4 identical document libraries in our site:
        i. Main Library
        ii. Tier 1
        iii. Tier 2
        iv. Tier 3

Note: Remember, when a file is created or modified in the Main Library, its label will be read by the flow and if it states a number from 1-3 it will send it to a specific library from Tiers 1-3. 

2. Create the Flow.
    a. Adding a Trigger
        i. Access the Microsoft Flow website and sign in. From the menu on the left side of your home page, select 'My
           Flows' and create a new flow from blank. 
          TIP: If you would like more information on how to create flows and about its components, click here.
        ii. It will prompt you to select a trigger.
            1. Select SharePoint to see the list of triggers related to this app.

            2. Select the option 'When a files is created or modified (properties only)'.

Note: Though the name of this trigger may seem self-explanatory, it means that the flow will trigger when the properties of a file are created or modified, not the file content itself. In other words, you can edit your file and make changes to it but it will not trigger the flow. An example of what would trigger the flow could be the change of any information visible under the 'Main Library' columns (i.e., Type of document, Title, Modified, Modified by, Label).

        iii. Now that you have added the trigger, it will prompt you to select where (from SharePoint) the trigger is
              going to be activated. 
            1. At this point, Flow should give you some tips on how to fill out this information.
            2. Leave the Folder field blank.
Note: Now that you have created the means for your flow to start working, we want to tell it what to do after it is triggered. Let's organize our thoughts:
            1. We want it to see what files and how many of them are in my 'Main Library' and to determine
                 their properties, where it will find the label of our files.
            2. For each file in the library, we also want the flow to evaluate the value in the 'Label' columns.
            3. After, we would also like it to determine if the label matches a specific 'tier' library and to be moved to that
                library if it does.
            4. If does not match any of the libraries we just want the file to stay in the 'Main Library'.
    b. Adding Actions
        i. For the flow to determine what files and how many there are in the 'Main Library', you will need to:
            1. Click on the  '+ New Step' button, underneath our trigger and select the SharePoint icon as before.
            2. Select the 'Get files (properties only)' action.
Note: This will determine how many files are in your library and what their properties are. It will also bring the properties' values in order for the flow to be able to interact and evaluate them.
           
3. Fill out the Required information as prompted.
        ii. To allow the flow to evaluate the properties for each file individually:
            1. Click on the  '+ New Step' button and select the  'Built-in' tab from the ribbon. 

            2. Select the 'Apply to each' option from the 'Actions' section.

            3. When filling out the information on this action, you will notice an option below the blank field that says
                'Add dynamic content'. Selecting this options will let you select items that previous actions have integrated
                 to the flow. 

            4. When clicking on that option, we will get some options like those in the image above. As you can see, the
                previous action we added to the flow brought in the value of the amount of items listed in our library
                through the 'Get files (properties only)' action. When you select the 'Value' option, it will tell the flow
                for how many files it will perform the actions to follow.​​​
        iii. After creating this control in your flow, there should be a new 'Add an Action button at the bottom of it.
            1. Add a 'Get file properties' action. Putting this under the 'Apply to each', will get the properties for each of
                the files it identifies in your library.
            2. In case you also want to get the file's metadata, you might want to add a 'Get file metadata' action.
    c. Setting Conditions
        i. Now, we will add a series of conditions that will let the flow evaluate the label of the files it brought to
           determine what folders they should go to.
            1. Under the same menu you found the 'Apply to each' control, you should find another control named
                'Condition'. Add it.
            2. For the 'Choose a value' field, select 'File Label' from the dynamic input menu.

            3. For the 'Condition Type' field, select 'is equal to'.
            4. For the 'Choose a value' field, type in '1'.
Note​: This will have the flow evaluate the 'File Label' value from the file it is currently evaluating from the list of files it brought from the 'Main Library'.
        ii. If the condition is met (if the 'File Label' value IS equal to '1', then we will want that file moved to the 'Tier 1'
            library. Here's how to do it:​
            1. In the green 'If yes' box, add an action and select the 'Move file' option.
            2. Follow the prompts to fill out the action requirement. Make sure you insert the dynamic input 'Identifier' in
                the 'File to Move' field.
            3. For the 'Destination Folder' field, select the 'Tier 1' library you created in 'Step 1 - Create the Libraries'.
        iii. If the condition is NOT met, then we will want the file to keep being evaluated to see if its 'File Label' value
              is equal to '2' or '3'. 
            1. Repeat steps c.i. and c.ii. Under step c.i.4., type in '2' as the value to be evaluated. For step c.iii., now just
                select the 'Tier 2' library.
            2. Repeat the previous step and type in '3' for the third condition to be evaluated and 'Tier 3' for
                the 'Destination Folder' field. 
            3. Finally, if the final condition is not met, simply add a 'Move file' action and for the 'Destination Folder',
                select 'Main Library'. The field 'If another file is already there' should be set to 'Fail this action'.

Conclusion
Flow is very helpful in letting you know what type of information it requires in order for it to work properly. SharePoint will easily allow you to work with this app in a very user-friendly way. With the flow that we created, you should be able to move files from one library to another through an automated process. This process may take a few minutes to run completely in a successful way. Make sure you test it a few times under different conditions to understand the logic of the app and to make sure you have everything right.

If you require additional information to understand how it works or if you would like to discover other processes you can complete through Flow, visit the Integrating Microsoft Flow with SharePoint wiki page!