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!
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
2. Next, create two workflows to create subfolders. For example, you can name these as:
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:
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.
Step 1 checks to see if the newly created item is a folder. If not, the workflow stops:
If it is a folder, it checks to see it is one of the two folders:
If it is, it stops the workflow (You would not want the workflow to create another set below each sub-folder).
Lastly, the workflow sets a column status field ‘SubFolders’ to ‘Pending’:
This fires the second workflow, which reacts to Changes.
The second list workflow is called NewAccountFolder_Created.
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:
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.