Moving Documents to a Restricted Subfolder with SharePoint Designer Workflow for Sharepoint 2010, 2013 and Office365

This post covers the steps to move files to a restricted folder in the same library based on a metadata value in the Status column. To do this, we will use SharePoint Designer 2013, with a SharePoint 2010 Workflow. We need to use the 2010 workflow for the Impersonation Step. After creating and testing the workflow, republish workflow using System Admin account. This workflow works with SharePoint 2010, SharePoint 2013, and Office365.

A few things you should be aware of:

  1. In this example, I used a column called Status to trigger the move. When the end user changes the status value to Final, the workflow will execute and the file will move to the subfolder.
  2. If another document with the same file name already exists in the subfolder, the workflow will fail. I added a step to run before the move that will update the file name and append the date. This way files will have a better chance of having unique names.
  3. If a person adds a file and changes the status to Final on the initial upload, the workflow skips over the renaming and moves the file into the sub-folder with the original name.
  4. The workflow cannot append the existing Created date to the existing file name due to underlying system formatting. I use a calculated text field to provide a date string.

Because of these issues the workflow a little more complicated in that we have to have some conditions and something to validate against. Here is the logic I used.

Step 1 – Create and Configure the Library

1. In the Document library, create a Choice column called Status. Add the values Draft and Final. Set the default status to Draft.

2. Create a text column called NameChanged. This will be populated by the workflow. You should hide this column from the end user. The easiest way is to turn on Content Types in the library settings. Click the "Document" content type and change the NameChanged column to Hidden.

3. The workflow cannot use the existing Created date due to the formatting, so we have to create a string.

Create a calculated column called "CreatedDate" with the formula of TEXT([Created],"mmddyy"). Data type returned is Single line of text. The workflow will use this string and append it to the current name of the file.

4. Create and configure the subfolder named "Final". Break the permissions on the library then break the permissions on the subfolder. Click the subfolder's … (1) and click Share (2), then Shared With (3). On the pop up, click ADVANCED (4) to access the page to break inheritance. Remove the members, visitors and other groups not needed.

Step 2 - Create the workflow

The Workflow when complete will look like this

1. Open the site in SharePoint Designer 2013. Click Workflows in the left navigation. In the Ribbon, click the List Workflows drop down and select the library. On the Create List Workflow popup, give your workflow a name and select SharePoint 2010 Workflow.

2. Click above Step 1 and select Impersonation Step in the ribbon.

This will allow the workflow to run under elevated credentials. Using this type of step allows the workflow to run event if the user editing the file does not have permission to the sub-folder, the workflow will still move the file. Click on Step 1 box and delete it.

NOTE: You should republish the workflow with the System Admin account.

The first section will move and rename the file that has been uploaded with the status of Final.

3. Click into the Impersonation Step and click the "Condition" icon in the Ribbon and select "if any value equals".

The text in the canvas will read "If value equals value". Click the first value and click the fx button to launch the field chooser and select the Status for the current item.

Next, click the second value and choose "Final" from the dropdown choices.

Add another Condition "if any value equals". Click the first Value and select "NameChanged" for Current Item using the fx button . Click the "Equals" text and select "not equals". Click the second values and type Yes in the box.

4. Build the string to move the file to the folder and rename it. Under the Condition, click the Action icon and select "Update List Item". The text Update item in this list will show. Click the link "this list" and select the "Add" button (1) from the Update List Item window. On the select Value Assignment popup, choose "Path and Name" (2) from the Set this field section. Click the … button(3) next to "To this Value" control to launch the string builder. In the text panel, type the folder name "Final/" (4) then click the Add or Change Lookup button (5)

On the Lookup for String select Name. Be careful here, there are 3 Name values. You only want the "Name". The value is added to the string builder. Click the "Add or Change Lookup" button again and in the Lookup for String box, select the "CreatedDate" field. This will rename the file with the current name with the text date appended. Click OK to save and close each popup.

5. Add an Action to update the "NameChanged" column to Yes. Select Action Icon and "Set Field in Current Item". Click the "Field" link and choose "NameChanged" from the dropdown for the Current Item. Click "Value" and type "Yes" in the text box.

6. Next, we will add a section that supports the scenario of an existing document's status changing to Final from Draft. Add an "Else If Branch" using the icon in the ribbon. In the branch add a Condition "if value equals value". Select the "Status" column as the first value and "Final" from the dropdown.

Add another condition "If value equals value". Select the "NameChanged" column as the first value and type Yes as the second value.

Since the file has already been renamed, we do not want to append the date string when the file is moved. Add an Action to "Update List Item". Following the steps in step 4, build the string that is only the folder/ followed by the "Name (used in forms)".

NOTE: if you use the "Name" value the workflow will fail.

7. Add another Else If Branch to support when a file is uploaded with Draft status. Add a condition "If value equals value". Select "Status" as the first value and "Draft" from the value dropdown. Add another condition "if value equals value", select NameChanged as first value. Click the "equals" text and change it to "not equals" in the value type Yes.

8. Add an Action "Update Field in Current Item". The line of text added to the canvas will read "Set field to value". Click the "Field" link and select Name (for use in forms). Next click the … button and open the string builder.

Click the Add or Change Look up button and select Name for the Current item. Then click Add or Change Lookup button again and select CreatedDate for the current item.

9. The last section of the workflow supports the scenario where an end user edits an existing draft document. Add two Conditions "if value equal value" the first will check if the "Status" is Draft (follow instructions in Step 7). The second condition is if the NameChanged equals Yes.​

10. Add an Action "Stop Workflow". In the Log the message type "Document Not Final".

11. Click the Workflow Settings and set the Start Options to Start when item is created and when the item is changed.

12. Test your workflow. If it fails, verify that you are choosing the correct "Name" values and that you do not have a "/ " before the folder name in the string builder.