What we are going to do
We are going to create a workflow that will trigger a function that creates a Team folder in Zoho WorkDrive, and the folder will be attached to the attachments section in the CRM record. We are going to create a connection, then work on the function, and finally create the workflow.
Important notes
- We are going to create a Team Folder. If you want to create a normal folder, check out the next tutorial.
- You have to have full access to Zoho CRM and WorkDrive.
- We are going to use the Deals module, but this works with any module, as long as the attachments section is enabled.
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.
- Get the parent folder ID from Zoho WorkDrive (on the URL).
- Replace "yourparentfolderid" with the id from the URL.
- Make changes to the createTeamFolder function's parameters if needed:
- Add a description or leave it empty ("").
- Select if it's a public folder ("true") or private folder ("false").
- Make sure the connection name matches the connection you created in the previous step.
- Test the function with any deal.
- Save the function.
DealInfo = zoho.crm.getRecordById("Deals",deal_id);
DealName = DealInfo.get("Deal_Name");
ParentFolderID = "yourparentfolderid";
// limiting the amount of characters because the Workdrive folder name has a limit
if(DealName.len() >= 40)
{
DealName = DealName.subString(0,40);
}
FolderName = DealName + " - Main Folder";
// folder name - parent folder id - description - public - connection
Create_Team_Folder = zoho.workdrive.createTeamFolder(FolderName,ParentFolderID,"Description test",true,"crm_workdrive");
info Create_Team_Folder;
Team_Folder_ID = Create_Team_Folder.get("data").get("id");
info Team_Folder_ID;
// adding users to the team drive folder ----------------------------------------------
// l = {"email1@yourdomain.com","email2@yourdomain.com"};
// for each email in l
// {
// header = Map();
// header.put("Accept","application/vnd.api+json");
// data = Map();
// data_param1 = Map();
// att_param1 = Map();
// att_param1.put("resource_id",Team_Folder_ID);
// att_param1.put("shared_type","workspace");
// att_param1.put("email_id",email);
// att_param1.put("role_id","1");
// data_param1.put("attributes",att_param1);
// data_param1.put("type","members");
// data.put("data",data_param1);
// response = invokeurl
// [
// url :"https://www.zohoapis.com/workdrive/api/v1/members"
// type :POST
// parameters:data.toString()
// headers:header
// connection:"crm_workdrive"
// ];
// info response;
// }
// // link folder as ATTACHMENT IN CRM ------------------------------------------------
dataList = List();
data = Map();
data.put("$link_url","https://workdrive.zoho.com/home/" + ParentFolderID + "/teams/" + ParentFolderID + "/ws/" + Team_Folder_ID + "/folders/files");
data.put("File_Name",FolderName);
data.put("$type","teamdrive");
dataList.add(data);
payload = "attachments=" + zoho.encryption.urlEncode({"data":dataList});
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v3/Deals/" + deal_id + "/Attachments"
type :POST
parameters:payload
connection:"crm_workdrive"
content-type:"application/x-www-form-urlencoded"
];
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 > Stage is modified to the value of Won
- 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