Creating SharePoint Subfolders

Creating SharePoint Sub-Folders

We now know that the out-of-the-box SharePoint integration creates a folder for each record in CRM. Once the corresponding SharePoint folder is created, you can add documents to that folder as well as create subfolders within it. But what if the folder for every record requires another subfolder? Is manually creating a subfolder for every SharePoint folder viable?

Fortunately, SharePoint allows automatic creation of these subfolders. This can be easily achieved by a SharePoint plug-in. If you don’t have the technical resource to write code for such plugins, you can always use workflows to achieve the same automation. Let’s see how this can be done!

Note! You will need SharePoint Designer 2013 for this.

1. Create two new columns in the SharePoint Account library:

  • ParentFolder: Text field to populate the parent folder name
  • SubFolders: Choose field for status values

Creating SharePoint Subfolders

2. Next, create two workflows to create subfolders. For example, you can name these as:

  • NewAccount_SetStatus
  • NewAccountFolder_Created

3. Open SharePoint Designer and connect to your SharePoint site where CRM integration creates folders.

4. Select Workflows. We will need to create two list workflows for the account library:

create subfolders img 2

create subfolders img 3

The first list workflow is NewAccount_SetStatus.This fires upon creation and is initiated by a user in CRM when the Documents link is clicked for the first time and they accept the prompt to create a new folder.

create subfolders img 4

Step 1 checks to see if the newly created item is a folder. If not, the workflow stops:

create subfolders img 5

If it is a folder, it checks to see it is one of the two folders:

  • Sales
  • Technical

If it is, it stops the workflow (You would not want the workflow to create another set below each sub-folder).

create subfolders img 6

Lastly, the workflow sets a column status field ‘SubFolders’ to ‘Pending’:

create subfolders img 7

This fires the second workflow, which reacts to Changes.

The second list workflow is called NewAccountFolder_Created.

create subfolders img 8

Step 1 of this workflow checks the ‘SubFolders’ value.

If Pending, this means the newly created folder is a CRM folder, therefore it needs to create the two sub-folders. The two folders are created and the parent’s SubFolders value is set to Created. This indicates that the parent folder has had its children created and will not recreate them if the parent folder is changed:

create subfolders img 9

For the Create Item, use the folder name to dictate the path, hard coding the ‘/Sales’.

You can repeat with another Create for the second sub-folder, and so on.