Sync Files from Zoho CRM to Zoho WorkDrive Using Automation

Sync Files from Zoho CRM to Zoho WorkDrive Using Automation

Summary: This article explains how to automatically sync files uploaded to a Zoho CRM record into a corresponding folder in Zoho WorkDrive. By combining Workflows, Custom Functions, and custom fields, you can automate folder creation and file syncing without manual intervention.

Objective

To:

  1. Automatically create a WorkDrive folder for each new CRM record.

  2. Sync files from a File Upload field in CRM to the corresponding WorkDrive folder using a checkbox trigger.


Scenario:

A real estate agency uses Zoho CRM to manage incoming property leads. For each potential client (record), they collect important documents such as:

  • Identity proof (e.g., Passport, Driver’s License)

  • Property preferences or legal forms

  • Signed agreements

Manually creating a WorkDrive folder and uploading these documents one by one leads to disorganised file structures and wasted time.

Solution with Automation:

  1. Folder Creation on Lead Creation:
    When a new lead is added in Zoho CRM, a folder is automatically created in a predefined WorkDrive location using the lead’s name (e.g., John_Doe_Lead_#1294). The folder ID is stored in a hidden custom field in CRM for future reference.

  2. Sync Files on Upload:
    When the agent uploads documents to the file upload field in the CRM lead record, they simply check a box labeled “Sync to WorkDrive.” This triggers a workflow that uploads all attached files to the corresponding WorkDrive folder, keeping things perfectly organized.

  3. Centralised Access for Legal and Sales Teams:
    Since all documents are now stored in a structured WorkDrive hierarchy, internal teams can easily access client-specific files for legal review, contract generation, or future reference without digging through CRM attachments.


Step 1: Create a Folder in WorkDrive When a CRM Record is Created

What You'll Need:

  • A custom field in CRM to store the WorkDrive Folder ID (e.g., WorkDrive_Folder_ID)

  • A workflow in Zoho CRM to run on record creation

  • A custom function to create a folder in WorkDrive

Workflow Setup:

  • Module: Leads / Deals / [Your Module]

  • Trigger: On record creation

  • Action: Custom Function (Create WorkDrive Folder)






Sample Deluge Function: Create Folder in WorkDrive

  1. LEAD_ID= "3361723000090030015";
  2. PARENT_FOLDER_ID= "4ea6978af62a11a1840ed823f7f25e1f6c0a7";
  3. leadInfo = zoho.crm.getRecordById("Leads", LEAD_ID);
  4. fullName =leadInfo.get("Full_Name");
  5. info fullName;

  6. header = Map();
  7. header.put("Accept","application/vnd.api+json");
  8. data=Map();
  9. data_param1=Map();
  10. att_param1=Map();
  11. att_param1.put("name",fullName);
  12. att_param1.put("parent_id",PARENT_FOLDER_ID);
  13. data_param1.put("attributes",att_param1);
  14. data_param1.put("type","files");
  15. data.put("data",data_param1);

  16. createFolder = invokeurl
  17. [
  18. url :"https://www.zohoapis.com/workdrive/api/v1/files"
  19. type : POST
  20. parameters : data.toString()
  21. headers : header
  22. connection : "workdrive"
  23. ];
  24. info createFolder;

  25. folderId = createFolder.get("data").get("id");

  26. mp= Map();
  27. mp.put("Workdrive_Folder_ID", folderId);
  28. updateLead = zoho.crm.updateRecord("Leads",LEAD_ID,mp);
  29. info updateLead;


Step 2: Sync Files to WorkDrive on Checkbox Trigger

CRM Setup:

  • Add a Checkbox field (e.g., Sync_to_WorkDrive)

  • Workflow: Runs On Edit when Sync_to_WorkDrive == true





Sample Deluge Function: Upload Files to WorkDrive Folder

  1. leadInfo = zoho.crm.getRecordById("Leads", LEAD_ID);
  2. workdriveFolderId =leadInfo.get("Workdrive_Folder_ID");
  3. filesInTheFileUploadField = leadInfo.get("file");
  4. info filesInTheFileUploadField ;

  5. downloadedFiles = list();
  6. for each  file in filesInTheFileUploadField
  7. {
  8. fileId = file.get("attachment_Id");
  9. downloadFile = invokeurl
  10. [
  11. url :" https://www.zohoapis.com/crm/v8/Leads/"+LEAD_ID+"/Attachments/" + fileId
  12. type :GET
  13. connection:"stagehistory"
  14. ];
  15. info downloadFile;
  16. downloadedFiles.add({"file": downloadFile, "fileName": file.get("file_Name")});
  17. }

  18. for each fileObj in downloadedFiles
  19. {
  20. header = Map();
  21. header.put("Accept","application/vnd.api+json");

  22. info fileObj ;

  23. list_of_text=List();
  24. list_of_text.add({"paramName":"filename","content":fileObj.get("fileName"),"stringPart":"true"});
  25. list_of_text.add({"paramName":"parent_id","content":workdriveFolderId,"stringPart":"true"});
  26. list_of_text.add({"paramName":"override-name-exist","content":"true","stringPart":"true"});
  27. list_of_text.add({"paramName":"content","content":fileObj.get("file"),"stringPart":"false"});

  28. uploadFile = invokeurl
  29. [
  30. url :"https://www.zohoapis.com/workdrive/api/v1/upload"
  31. type : POST
  32. files : list_of_text
  33. headers : header
  34. connection : "workdrive"
  35. ];
  36. info uploadFile;
  37. }


Related Links  

NotesNotes: Refer to the following Guide - Article to learn the best practices for Optimizing the code and various ways to deploy Custom Function across Zoho CRM.

Custom Solution Created by Francis (Vishnu) | Zoho Partner Support

If you need any further clarifications, please don’t hesitate to contact - partner-support@zohocorp.com.

Additionally, we kindly ask all "Europe and UK partners" to reach out to partner-support@eu.zohocorp.com.