Rodger's Helpful Deluge Scripts #3 - Automatically attach files to CRM records when a file is added to Workdrive

Rodger's Helpful Deluge Scripts #3 - Automatically attach files to CRM records when a file is added to Workdrive

Hi Everyone,

I'm hoping this one will be really helpful for a lot of people. One thing that's missing from Zoho is a tighter integration between Workdrive and CRM. Whilst an update is in the works as far as I'm aware, file management can still be a needlessly complicated problem. And while there are apps out there that help with this, they often don't work with custom modules, or in the way you want.

Wouldn't it be great if you could just drag and drop your files into a workdrive folder and they all get renamed and appear on your CRM record without any effort from you? In this post, I will show you how to automatically create folders in workdrive AND LINK THEM TO THE CRM RECORD so that when a new file is added to the folder, it's automatically attached to the CRM record.

This is the basic process:
  1. CRM record is created
  2. Workdrive folder is created
  3. A Data Bind is created between the CRM Record and the Workdrive Folder
  4. When a new file is added to the Workdrive Folder, a function is triggered that attaches the file to the CRm Record.
When the file is attached to the CRM Record, we can take this opportunity to do whatever we want to aid in file management. In one of our organisations we accomplish the following in one of our business processes:

If the new file is a csv, the data is parsed and added to a subform on the recocrd
If the new file is a PDF, it is renamed with a specific format
If the new file contains a specific string of text, we know it's a thumbnail image, so it's uploaded to the record image
...

You get the idea of what we can do, so let's get into it.

Step 1: Create a CRM Function to receive the Data
First we need to create a function in CRM to receive a webhook, essentially a packed of data sent from Workdrive to CRM.

Head over to your functions in CRM and create a new Standalone function. Give it a name and description if you want.



We're going to create an argument called crmAPIRequest (spelled exactly like that, this is case sensitive) and se tthe argument type as string



Now save that and save the function, we don't need anything in there yet. In your function menu, click on the elipses (the 3 dots) and select REST API

 

Turn on "API Key" and the system will generate a url for you. Copy and save that URL as we will need it for Step 2. This finishes Step 1.

Step 2: Create an app in Workdrive
Firstly, we need to create an "App" in Workdrive. This will monitor your folder for specific events and send a webhook when that event is triggered, i.e new file created.

In Workdrive, head to the Admin Console --> Apps --> + New Custom App



Give your app a name that's descriptive and informative and paste your client ID. (There's insructions in the opo-up window about how to get your client ID)

When you have created your Custom App, go into it and head over to "Webhooks" and click "+ Create New Webhook"




Give your webhook a name and description if you please. The endpoint URL will be the url of your function that you created in step 1. This tells the app where to send the packed of data.

Next we select the event that will trigger the webhook. In this case, we want it to trigger when a file is uploaded.



Finally we want to specify the folder to monitor. This will be the parent folder that all your new folders will sit under. When you're done, click "Create Webhook"

Step 3: Setup the Data bind

A data bind links 2 records together with their unique ids. To do this we need a field on your CRM Record to store the Wokdrive Folder ID. Make this a single line field. If you don't know how to do this, then this  guide is not for you.

So that stores the Workdrive folder ID, but what stores the CRM record ID? The answer is a Data Template. In you Workdrive Admin Console, head over to Data Templates and create a data template. Add a single line text field to your data template. This will store the CRM Record ID



Step 4: Create folders in Workdrive with Deluge function.

Now that we have set this up, we need to create folders and associate store the respective IDs. This will be done on record creation.

Use the following code snipped to create your folder

  1. // Create folder
  2. header = Map();
  3. header.put("Accept","application/vnd.api+json");
  4. data = Map();
  5. data_param1 = Map();
  6. att_param1 = Map();
  7. att_param1.put("name",<Folder Name>);
  8. att_param1.put("parent_id",<Parent Folder ID>);
  9. data_param1.put("attributes",att_param1);
  10. data_param1.put("type","files");
  11. data.put("data",data_param1);
  12. createFolder = invokeurl
  13. [
  14. url :"https://www.zohoapis.com.au/workdrive/api/v1/files"
  15. type :POST
  16. parameters:toString(data)
  17. headers:header
  18. connection: <Your Workdrive Connection>
  19. ];
  20. info createFolder;
  21. // m_record.put("Folder_Id",createFolder.get("data").get("id")); - Put the created folder ID into the map for your CRM record
  22. // Associate Data Template
  23. header = Map();
  24. header.put("Accept","application/vnd.api+json");
  25. data = Map();
  26. data_param1 = Map();
  27. att_param1 = Map();
  28. att_param1.put("resource_id",createFolder.get("data").get("id"));
  29. att_param1.put("data_template_id","s1a2u5f693092015d4edc876d9043efcf9bcd-73963000001705001"); // 
  30. innerattr_param = List();
  31. innerattr_param_map1 = Map();
  32. innerattr_param_map1.put("custom_field_id",<Custom Field ID>);
  33. innerattr_param_map1.put("value",<CRM Record ID>));
  34. innerattr_param.add(innerattr_param_map1);
  35. att_param1.put("custom_data",innerattr_param);
  36. data_param1.put("attributes",att_param1);
  37. data_param1.put("type","custommetadata");
  38. data.put("data",data_param1);
  39. associateDataTemplate = invokeurl
  40. [
  41. url :"https://www.zohoapis.com.au/workdrive/api/v1/custommetadata"
  42. type :POST
  43. parameters:data.toString()
  44. headers:header
  45. connection: <Your Workdrive Connection>
  46. ];
  47. info associateDataTemplate;

Note: Use the following documentation to get the ID of your Data Template Field needed for line 33 above Zoho WorkDrive API Documentation

Then update your CRM record with the ID of the workdrive folder you created.

Generally, we don't attach this folder to the CRM Record, all we want to see in the CRM record are the files within the folder, not the folder itself.

Step 5: Set-up CRM Function to receive Webhook and attach file to CRM Record

Now we need to go back to your CRM Function which you setup in Step 1 and we're going to add some code:

  1. crmAPIRequest = crmAPIRequest.get("body");
  2. getFolderMetadata = invokeurl
  3. [
  4. url :"https://www.zohoapis.com.au/workdrive/api/v1/files/" + crmAPIRequest.get("data").get(0).get("resource_info").get("parent_id") + "/custommetadata"
  5. type :GET
  6. headers:{"Accept":"application/vnd.api+json"}
  7. connection: <Your Workdrive Connection>
  8. ];
  9. info getFolderMetadata.get("data").get(0).get("attributes").get("custom_data").get(0).get("value");
  10. recordId = getFolderMetadata.get("data").get(0).get("attributes").get("custom_data").get(0).get("value"); // Gets the Data out of the Data Template - This is the CRM Record ID
  11. r_record = zoho.crm.getRecordById(<Module>,recordId); //Get your CRm Record
  12. fileID = crmAPIRequest.get("data").get(0).get("resource_info").get("resource_id");
  13. m_map = Map();
  14. // Attach new file to CRM Record
  15. //
  16. l_attachments = list();
  17. data = Map();
  18. data.put("$link_url","https://workdrive.zoho.com.au/file/" + fileID);
  19. data.put("File_Name",<Your File Name>);
  20. if(!data.isEmpty())
  21. {
  22. data.put("$resource_id",recordId);
  23. data.put("$type","teamdrive");
  24. l_attachments.add(data);
  25. payload = "attachments=" + zoho.encryption.urlEncode({"data":l_attachments});
  26. attachFile = invokeurl
  27. [
  28. url :"https://www.zohoapis.com.au/crm/v2/<Module>/" + recordId + "/Attachments"
  29. type :POST
  30. parameters:payload
  31. connection: <Your CRM Connection>
  32. content-type:"application/x-www-form-urlencoded"
  33. ];
  34. info attachFile;
  35. // Rename File in Work Drive
  36. data = Map();
  37. data_param1 = Map();
  38. att_param1 = Map();
  39. att_param1.put("name",<Your File Name>);
  40. data_param1.put("attributes",att_param1);
  41. data_param1.put("type","files");
  42. data.put("data",data_param1);
  43. renameFile = invokeurl
  44. [
  45. url :"https://www.zohoapis.com.au/workdrive/api/v1/files/" + fileID
  46. type :PATCH
  47. parameters:data.toString()
  48. headers:{"Accept":"application/vnd.api+json"}
  49. connection: <Your Workdrive Connection>
  50. ];
  51. info renameFile;
  52. }
  53. if(!m_map.isempty())
  54. {
  55. info zoho.crm.updateRecord(<Module>,recordId,m_proof);
  56. }
  57. return "";

So how does the above code work?

Firstly, we get the body of the Webhook, this has all the data we really want.
Next we get the file metadata, this will contain the data in teh Data Template, which of course is the CRM Record ID.
Now that we have the CRM Record ID from the file Metadata, we can fetch the CRM Record. Contained within the Webhook is also the File ID in Workdrive, so this gives us all the information we need to attach the file to your CRM Record and rename the file in Workdrive.

Within this function you can now do whatever you want with the file or anything else. Let's say you want to send an email when a specific file is  uploaded, you can do that here. Or if you want to send a notification via Cliq to someone when a file is uploaded, do that here. You can code specific filename syntaxes so that all your files are perfectly name all the time, the limits are endless.

This is far more advanced than most deluge functions posted on here, so see how you go, play around and have fun. If you have any questions, I'll try to respond as soon as possible.

    Access your files securely from anywhere







                            Zoho Developer Community





                                                  Use cases

                                                  Make the most of Zoho Desk with the use cases.

                                                   
                                                    

                                                  eBooks

                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho Desk.

                                                   
                                                    

                                                  Videos

                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho Desk.

                                                   
                                                    

                                                  Webinar

                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                   
                                                    
                                                  • Desk Community Learning Series


                                                  • Meetups


                                                  • Ask the Experts


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner






                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner







                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ






                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方




                                                                                                            • Recent Topics

                                                                                                            • Zoho Finance Suite - Customer Custom Tabs - Dynamic Link

                                                                                                              Hi Finance Suite team, When creating a Custom Tab for a Client Portal, there is no option to add dynamic parameters. This would be very helpful for adding Zoho Analytics dashboards which can be dynamically filtered through the URL to only show information
                                                                                                            • Feature Request - Insert URL Links in Folders

                                                                                                              I would love to see the ability to create simple URL links with titles in WorkDrive. or perhaps a WorkDrive extension to allow it. Example use case: A team is working on a project and there is project folder in WordDrive. The team uses LucidChart to create
                                                                                                            • FSM trying again

                                                                                                              have not linked FSM yet to the rest of out Zoho suit. It certainly looks like the apointment and service part is more manageable for our staff. The question is that our engineers multi task examples 1. deliver products to customers not fitted 2. Service
                                                                                                            • Possible to bold or indent text in the description field?

                                                                                                              As part of one item, I often have a detailed description that would be much easier to read if there was the ability to have a bulleted list or bold text and the like. Is this possible? My last invoicing software allowed markup in the field so, for example, an asterisk meant a bullet. I haven't been able to find any documentation related to this.  Any information would be appreciated. Thank you.
                                                                                                            • How can I setup Zoho MCP with Chat GPT

                                                                                                              I can set up custom connections with Chat GPT but I cat an error when I try to set it up. The error is: "This MCP server can't be used by ChatGPT to search information because it doesn't implement our specification: search action not found" Thoughts?
                                                                                                            • Formatting of Balance Sheet and Profit & Loss Reports

                                                                                                              The default format of the Balance Sheet and P&L Reports are based on the Account Types and then the individual accounts within the Chart of Accounts. These are then ordered alphabetically under these sub-headings and one is unable to re-order these or
                                                                                                            • UK MTD reports concerning turnover and cerash accounting

                                                                                                              Hi I am a sole trader, and I have just started with Zoho Books in order to comply with the new HMRC requirements. I use 'cash basis' - which I understand to mean that income is when the cash comes in (not the invoice date) and expenses are when they are
                                                                                                            • Retainer Invoice.

                                                                                                              Why ZOHO not have facilities to deduct partially advance payment from an invoice.
                                                                                                            • Collaborate Feature doesn't work

                                                                                                              Hello Team. It seems that the collaborate section is broken? I can post something but it all appears in "Discussions". In there is no way how I would mark something as Draft, Approval, post or any of the other filter categories? Also if I draft a post
                                                                                                            • IMAP Server not responding.

                                                                                                              Trying to connect a phone via IMAP and getting "imap.zoho.com not responding." Is the server down, for maintenance or otherwise? I've tried this on two different devices and got the same error on both.
                                                                                                            • Share saved filters between others

                                                                                                              Hi, I am in charge to setup all zoho system in our company. I am preparing saved filters for everybody, but the only one can see its me. How can others see it? Thanks
                                                                                                            • GST Slabs Redefined: Stay Compliant Using Zoho Books!

                                                                                                              Hello Everyone! The Government of India is rolling out new GST rates, a major reform aimed at simplifying the current tax structure starting 22 September 2025. GST will move from four slabs (5%, 12%, 18%, 28%) to two main slabs (5% and 18%), plus a special
                                                                                                            • Kanban view on Zoho CRM mobile app!

                                                                                                              What is Kanban? The name doesn't sound English, right? Yes, Kanban is a Japanese word which means 'Card you can see'. As per the meaning, Kanban in CRM is a type of list view in which the records will be displayed in cards and categorized under the given
                                                                                                            • Presenting ABM for Zoho CRM: Expand and retain your customers with precision

                                                                                                              Picture this scenario: You're a growing SaaS company ready to launch a powerful business suite, and are looking to gain traction and momentum. But as a business with a tight budget, you know acquiring new customers is slow, expensive, and often delivers
                                                                                                            • No practical examples of how survey data is analyzed

                                                                                                              There are no examples of analysis with analytics of zoho survey data. Only survey meta data is analyzed, such as number of completes, not actual analysis of responses, such as the % in each gender, cross-tabulations of survey responses. One strange characteristic of Zoho analytics is that does not seem aware of how Zoho Survey codes 'multiple response' questions. These are questions where more than one option can be selected from a list. Zoho Survey stores this data as text, separated by commas within
                                                                                                            • Zoho Creator as LMS and Membership Solution

                                                                                                              My client is interested in using Zoho One apps to deploy their membership academy offer. Zoho Creator was an option that came up in my research: Here are the components of the program/offer: 1. Membership portal - individual login credentials for each
                                                                                                            • Adding Chargebee as a Data Connector

                                                                                                              Is it possible to get Chargebee added as a Zoho Analytics data connector?
                                                                                                            • Zoho CRM - Custom Views for Portal Users

                                                                                                              I'm looking for an option to customise custom views for portal users in CRM. It would be great if "portal user" was a permission on custom views.
                                                                                                            • Webform & spam

                                                                                                              Hi, We set up 2 webform on our website, fowarding the content to Zoho CRM. Since it has been opened up, we are getting lot of spam message (for now about 20 a day). To lower the  amount of false new leads we added the captcha field and new enquieries are send to the Approval Leads list. However we still get some spam. Is there any "anti spam" mechanism built in Zoho CRM, or how is the best way to avoid these kind of spam ? Thanks
                                                                                                            • Elevate your CX delivery using CommandCenter 2.0: Simplified builder; seamless orchestration

                                                                                                              Most businesses want to create memorable customer experiences—but they often find it hard to keep them smooth, especially as they grow. To achieve a state of flow across their processes, teams often stitch together a series of automations using Workflow
                                                                                                            • Dropbox to Workdrive

                                                                                                              Namaste, Trust you all are doing well. Wanted to check how this can be done with Zoho flow. I typically receive dropbox links from my clients. Is there a way where I can provide the link to Zoho flow and it downloads the files from dropbox link to a work
                                                                                                            • Deals by Stages Funnel not showing in correct order

                                                                                                              Using the Stage-Probability Mapping for the Deals module we have created a steps our deals will pass through, RFQ, Closed/Lost, Declined/No-Go, Pricing, Submitted, Negotiations, Won. However when I view the Deal By Stages Funnel it does not show in the
                                                                                                            • Adding a developer for editing the client application with a single user license

                                                                                                              Hi, I want to know that I as a developer I developed one application and handed over to the customer who is using the application on a single user license. Now after6 months customer came back to me and needs some changes in the application. Can a customer
                                                                                                            • Turning off the new UI

                                                                                                              Tried the new 'enhanced' UI and actively dislike it. Anyone know how to revert back?
                                                                                                            • Message "...does not support more than 100 distinct values..." WHY????

                                                                                                              I get this message on one of my reports: Sorry, Zoho Reports currently does not support more than 100 distinct values in columns. 'Account Name * Sum(Amount),Count(Amount Tier)' contains more than 100 distinct values.  Possibly, you can apply filter to reduce the number of distinct values in 'Account Name' or drop the 'Account Name' field in Rows. I want to list all ACCOUNT NAMES (about 500) with SALES BY ACCOUNT.  What is blocking this?
                                                                                                            • Attention API Users: Upcoming Support for Renaming System Fields

                                                                                                              Hello all! We are excited to announce an upcoming enhancement in Zoho CRM: support for renaming system-defined fields! Current Behavior Currently, system-defined fields returned by the GET - Fields Metadata API have display_label and field_label properties
                                                                                                            • Confirmation prompt before a custom button action is triggered

                                                                                                              Have you ever created a custom button and just hoped that you/your users are prompted first to confirm the action? Well, Zoho knows this concept. For example, in blueprint, whenever we want to advance to the next state by clicking the transition, it is
                                                                                                            • Cost of good field

                                                                                                              Is there a way we can have cost of good sold as a field added to the back end of the invoicing procedure and available in reports?
                                                                                                            • How to create auto populate field based on custom module in Zoho CRM?

                                                                                                              Hello, i'm still new to Zoho CRM and work as administrator in my company. Currently, I'm configuring layout for Quotes Module. So, the idea is, I've created a read-only field in Quotes called "Spec". I want this field automatically filled with Specification
                                                                                                            • Rich Text For Notes in Zoho CRM

                                                                                                              Hello everyone, As you know, notes are essential for recording information and ensuring smooth communication across your records. With our latest update, you can now use Rich Text formatting to organize and structure your notes more efficiently. By using
                                                                                                            • Date triggering Workflow rule

                                                                                                              I have a function triggered by a workflow rule. The function takes a date and creates a task for that date and fills in a field with the name of the day for that date. It also updates the status field of the record. The workflow rule is set to run whenever
                                                                                                            • Change Last Name to not required in Leads

                                                                                                              I would like to upload 500 target companies as leads but I don't yet have contact people for them. Can you enable the option for me to turn this requirement off to need a Second Name? Moderation update (10-Jun-23): As we explore potential solutions for
                                                                                                            • Office 365 and CRM mail integration: permission required

                                                                                                              Has anyone run into this weird problem? My email server is Office 365. When I try to configure Zoho CRM to use this server, a Microsoft popup window opens requesting user and password. After entering that, I get a message in the Microsoft window saying
                                                                                                            • Tables improvement ideas / features

                                                                                                              Heya, I've been using Zoho Tables for a few months now and wanted to post some features that I think will be greatly beneficial for the tool: 1. Ability to delete a record in automation or move a record in automation. - Usecase: I move a record from one
                                                                                                            • Deluge - Can't get phone number SalesIQ

                                                                                                              Hey folks, I’m building a custom plug for SalesIQ that’s supposed to register leads into Zoho CRM. The SalesIQ chat is being implemented on WhatsApp, and in my plug I’m using this line: mobile_clean = session.get("phone").get("value"); From what I understand,
                                                                                                            • Zoho CRM button to download images from image upload field

                                                                                                              Hello, I am trying to create a button in Zoho CRM that I can place in my record details view for each record and use it to download all images in the image upload fields. I tried deluge, client scripts and even with a widget, but feel lost, could not
                                                                                                            • how to differentiate if whatsapp comes from certain landing page?

                                                                                                              I create a Zobot in SalesIQ to create a Whatsapp bot to capture the lead. I have 2 landing pages, one is SEO optimized and the other want is optimized for leads comes from Google Ads. I want to know from which landing page this lead came through WhatsApp
                                                                                                            • Zoho Desk - Community

                                                                                                              As a regular user of Zoho Cares Community I would really love to see the publish date of articles. For example, when I look at Announcements, it would be very beneficial to see which ones were posted recently, over those which have just and a recent comment.
                                                                                                            • access to quartz for my customers

                                                                                                              Hi how can I have access to the application quartz you use for us to send you screen rocording, this feature would be immensely useful for our customers support https://quartz.zoho.com/
                                                                                                            • Issue with Inline Images in Email Reply via Zoho Desk API

                                                                                                              Hi, I am attempting to send inline images in an email reply using the Zoho Desk API, but the images are not being displayed inline for the recipient. I have followed this documentation: https://desk.zoho.com/DeskAPIDocument#Uploads https://desk.zoho.com/DeskAPIDocument#Threads#Threads_SendEmailReply
                                                                                                            • Next Page