What we are going to do
We are going to create a workflow that will trigger a function that creates a set of subfolders inside a Team folder in Zoho WorkDrive. You can use the function to create folders or subfolders in your personal folder as well. This is continuation of the previous tutorial called "Function: Create a WorkDrive Team Folder and Attach it to the CRM Record".
- We are going to create normal folders. If you want to create a Team Folder, check out this tutorial: https://www.blungo.com/blogs/post/function-create-a-workdrive-team-folder-and-attach-it-to-the-crm-record.
- This tutorial is Part 2 of the WorkDrive folder creation series. The code will work as long as you already have a WorkDrive Team Folder attached to the Deal. You can modify the code as needed if you are not going to use a Team Folder. The code below includes some examples of different ways to get the folder ID.
- You have to have full access to Zoho CRM and WorkDrive.
Creating a connection
- In the CRM, go to the Setup.
- Under "developer space", click on "connections".
- Click on "create connection".
- The service is "Zoho OAuth".
- Name the connection. We are going to use "crm_workdrive".
- Add the scopes. Use the magnifier to easily find the scopes.
- List of scopes: ZohoCRM.modules.ALL, zohosearch.securesearch.READ, WorkDrive.team.ALL, WorkDrive.workspace.ALL, WorkDrive.files.ALL, WorkDrive.organization.READ, WorkDrive.members.READ, WorkDrive.members.CREATE, WorkDrive.members.UPDATE, WorkDrive.members.DELETE, WorkDrive.teamfolders.CREATE, WorkDrive.teamfolders.READ, WorkDrive.teamfolders.UPDATE, WorkDrive.teamfolders.DELETE, WorkDrive.teamfolders.sharing.CREATE, WorkDrive.teamfolders.sharing.READ, WorkDrive.teamfolders.sharing.UPDATE, WorkDrive.teamfolders.sharing.DELETE, WorkDrive.teamfolders.admin.READ, WorkDrive.groups.CREATE, WorkDrive.groups.READ, WorkDrive.groups.UPDATE, WorkDrive.groups.DELETE, WorkDrive.DataTemplates.CREATE, WorkDrive.DataTemplates.DELETE, WorkDrive.DataTemplates.UPDATE, WorkDrive.links.ALL, WorkDrive.users.READ
- Click on "create and connect".
- Click on "connect" and allow any permissions you are requested.
Setting up the function
- In the Zoho CRM settings, go to "Functions" under "Developer Space".
- Create a new function: Add a name and select "Automation" as the category.
- Copy the function located below and paste it in the text editor in Zoho CRM.
- Edit the arguments: add "deal_id" as a string.
- Generate your folder structure:
- Rename the folders,
- Add more folders,
- Create subfolders if needed.
- Test the function with a Deal that has a WorkDrive Team Folder attached.
- Save the function.
Creating a workflow
- In the setup page, click on workflow rules under automations
- Create a new rule, select the Deals module, and name it (we are selecting the Deals instead of the contact because we need to trigger this automation when a Deal stage changes)
- Configure your workflow trigger and conditions:
- When > on a record action > Edit > "Subfolders Needed" is modified to the value of "Yes"
- Condition: all Deals
- As the instant action, select "function"
- Click on "new function" and then select "functions"
- Find the function you just created, and click on "configure"
- Map the argument "deal_id" as the deal ID, using the # key
- Click on "save and associate" and save the workflow
- Test the workflow