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




                                      Zoho Desk Resources

                                      • Desk Community Learning Series


                                      • Digest


                                      • Functions


                                      • Meetups


                                      • Kbase


                                      • Resources


                                      • Glossary


                                      • Desk Marketplace


                                      • MVP Corner


                                      • Word of the Day



                                          Zoho Marketing Automation
                                                  • Sticky Posts

                                                  • Enhanced duplicate check for Leads in CRM

                                                    Hello Everyone, We are excited to announce that you can now check for duplicate entries in leads by comparing them with similar records in the Contacts Module. Previously, when you added a lead, only the converted leads were checked for duplicates. This
                                                  • Nimble enhancements to WhatsApp for Business integration in Zoho CRM: Enjoy context and clarity in business messaging

                                                    Dear Customers, We hope you're well! WhatsApp for business is a renowned business messaging platform that takes your business closer to your customers; it gives your business the power of personalized outreach. Using the WhatsApp for Business integration
                                                  • Accessibility in Zoho CRM: Not just a feature—a way to empower

                                                    For instructions on setting up these controls, please check this help document: Configuring accessibility controls. Hello everyone, Today (December 3, 2024), on the International Day of Persons with Disabilities, we begin our journey towards a CRM that
                                                  • Act on your customers' voices in Zoho CRM

                                                    Dear Customers, We hope you're well! We are super excited to present a pivotal addition to VoC in Zoho CRM—the ability to act! Customer feedback is directly proportional to customer experience, and in this customer-driven market, that feedback has a powerful
                                                  • Focus Group Webinar - Streamline Record Creation with Wizards

                                                    Hi there, With all the time your users spend on record creation, do you feel like they have the most seamless experience while doing it? For different types of records or those with a LOT of fields, do your users spend time navigating to enter data repeatedly?


                                                  Manage your brands on social media



                                                        Zoho TeamInbox Resources

                                                          Zoho DataPrep 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

                                                                                                  • Last sync date/time as a widget

                                                                                                    Is there any way to get the last date/time that the data shown (reports and dashboard) was last updated.  For example, If I have our data being synced every 3 hours and the last was done 2 hrs ago, I would like to show date/time of update OR updated #{hrs}
                                                                                                  • ChatGPT

                                                                                                    Hola, sabéis si además de tener la licencia de chat GPT Plus hay que comprar créditos para usar chat GPT en zoho social? Gracias
                                                                                                  • Lookup Field in Zoho Forms <> Zoho CRM Integration

                                                                                                    Hello, We use Zoho CRM to manage our products, create quotes, etc. I want to use Zoho Form to configure a simple form that allows customers to request quotes on our website. I completed the form and used a subform for the "Add items to your quote" part
                                                                                                  • An update to improve email delivery | Email Authentication & Relay

                                                                                                    Dear Zoho Recruit Community, We hope this message finds you well. This post is to inform you about an important update regarding the authentication of all email domains in your Zoho Recruit account. Effective 31st December, 2024, emails sent using email
                                                                                                  • Create custom rollup summary fields in Zoho CRM

                                                                                                    Hello everyone, In Zoho CRM, rollup summary fields have been essential tools for summarizing data across related records and enabling users to gain quick insights without having to jump across modules. Previously, only predefined summary functions were
                                                                                                  • 100 record view limitation

                                                                                                    I have just migrated from another CRM and am starting in ZOHOcrm with over 5000 contacts. It seems that my searches and sorts are limited to 100 live records....or am I missing something. This seems to be very limiting...in a lot of scenarios (mass email,
                                                                                                  • Setting Up Direct Mail Campaigns

                                                                                                    If I need to set up a 5 step direct mail campaign is that possible? Basically every week I upload names from a CSV to Zoho and then would need to mail them every 45 days for about 6 months. I would want to be able to take names off the list when they say their house is sold or that they don't want to be contacted. I don't necessarily need to have it integrated with click2mail or anything but would at least need to be able to export the file in a CSV/excel for each mailing.  Does anyone know if that's
                                                                                                  • RFQ MODEL

                                                                                                    A Request for quotation model is used for Purchase Inquiries to multiple vendors. The Item is Created and then selected to send it to various vendors , once the Prices are received , a comparative chart is made for the user. this will help Zoho books
                                                                                                  • Recruit - How to Force a Job Opening out of a Blueprint

                                                                                                    In past versions of Zoho Recruit, there was the ability to create a custom button on a record's page that would evoke a URL that would force a record out of a blueprint. What is that URL or is there a better way to force a record out of a blueprint?
                                                                                                  • Introducing Zia LLM: Zoho’s in-house Generative AI solution for CRM's AI capabilities

                                                                                                    Hello everyone, We're excited to announce the launch of our in-house Large Language Model (LLM) by Zia to power our AI offerings. What is LLM? LLM stands for Large Language Model, a powerful AI technology that processes and generates human-like text based
                                                                                                  • ERROR

                                                                                                    I deleted a contact card, I want to add it again but it says that the contact already exists. I searched the records and it is not there, and I even deleted it in the trash. The email is this one:xxxxx. Please help!!
                                                                                                  • How to Automatically Populate the Deal ID in the Parent Lead After Creating a New Deal with Blueprint?

                                                                                                    Hello Everyone! 🎉 I wanted to share a solution to a problem that some of you might have encountered. In Zoho CRM, when creating a Deal from a Lead using a Blueprint, data can only flow in one direction—from the Lead (parent) to the Deal (child). But
                                                                                                  • Chroniques de l'année 2024 Zoho France : avec vous, pour vous !

                                                                                                    Nous vous adressons nos vœux les plus chaleureux pour une année 2025 exceptionnelle et pleine de réussites ! Fidèle à son habitude, Zoho France vous réserve chaque année de nombreuses mises à jour, des événements marquants, des activités diversifiées
                                                                                                  • Why can't I see the delivered Zoho Campaign automation email on Zoho CRM lead record?

                                                                                                    I recently did update the field mapping on our Leads sync services between Zoho CRM and Zoho Campaigns. The end goal is to create tailored email drip campaigns with the use of segments and automation. I understand you can build cadences, email templates,
                                                                                                  • Custom Function to Format Phone / Mobile numbers in Australian Standard format

                                                                                                    So I got sick of phone numbers being formatted incorrectly and Zoho not doing anything to standardise phone numbers to meet E.164 formats. So I went and coded my own function to fix this. And figured I'd share with the community This is specifically for
                                                                                                  • Kaizen #173: A Comparison of Zoho CRM REST APIs and GraphQL APIs

                                                                                                    Hello everyone! Welcome back to another week of Kaizen! Zoho CRM offers two API architectures for its users: REST API and GraphQL API. Each of these API architectures has its own strengths and ideal use cases. In this post, we will discuss the difference
                                                                                                  • Marketer's Space: Leveraging CRM Data for Dynamic Content and Personalized Campaigns

                                                                                                    Hello Marketers! Welcome back to another post in Marketer’s Space! We’re excited to continue our series on the many advantages of integrating Zoho CRM with Zoho Marketing Automation (ZMA). This series is designed to help you unlock the full potential
                                                                                                  • How to preview a locked note? Or just lock one?

                                                                                                    Once a note is locked there is no preview, just a blur (good). But, if there are a lot of notes, wouldn't it be good to have the title show up and blur the rest? Or am I just being dumb - do they all unlock and lock at the same time?
                                                                                                  • Linkedin Plugin

                                                                                                    H, Is there a plugin to allow the connection to LinkedIn and simplify editing? I've looked at a few, but they all seem to be outdated and not working... What do you use or can you recommend?
                                                                                                  • Query About Updating Records in Batches via API

                                                                                                    We are working on integrating the Creator application with an external app, and we need to update thousands of records daily. I understand that the "Update Records" API is available; however, it appears to be designed for updating multiple records with
                                                                                                  • Unable to use Sign "You have entereed some invalid characters"

                                                                                                    Unable to use Sign "You have entered some invalid characters" I do not see any invalid characters. The text in "Leave a Note" is plain text which I entered directly into the field. See attached screenshot
                                                                                                  • Remove the link between app admin roles and org admin privileges

                                                                                                    Greetings Zoho One Team, Currently, assigning someone as an admin in certain Zoho apps, such as Cliq, Connect, Mail, Vault, or Forms (and maybe other apps as well) automatically grants them org admin privileges, even though they are not listed as org
                                                                                                  • !! URGENT My sent mail goes to spam

                                                                                                    I tested a few times and every time I send mail out it goes the recipients spam box.  Why is it marking my mail as spam? please help me ! thanks
                                                                                                  • Difference between Admin, Team leader/Manager, Clinets/user profile and roles in Zoho Project

                                                                                                    I've been wondering to find out the difference between the key feature of Admin,Manager, and client/user in Zoho Project. I am student and trying to learn about the Zoho Project. I could not find the roles and profiles difference between this 3 users
                                                                                                  • Missing Modules such as RFQ, Purchase request and Store room

                                                                                                    Hi, I wonder why zoho doesn't add Purchase requests module e.g. ( a lower level staff wants to request for provision of something) which can be approved or rejected by his/her manager. In case of approval, same request can be converted into RFQ. Secondly
                                                                                                  • Important updates to Zoho CRM's email deliverability

                                                                                                    Last modified on: Jul 24, 2024 These enhancements are released for all users across all data centers. Modified on: Oct 30, 2023 Organisations that are in the Enterprise and above editions of Zoho CRM, and have not authenticated their email-sending domains
                                                                                                  • Paid Support Plans with Automated Billing

                                                                                                    We (like many others, I'm sure) are designing or have paid support plans. Our design involves a given number of support hours in each plan. Here are my questions: 1) Are there any plans to add time-based plans in the Zoho Desk Support Plans feature? The
                                                                                                  • Zoho expense linked with Campaign instead of customers

                                                                                                    Hi, Is there a development planned for linked an expense or a report to a zoho campaign? Indeed, suppose I created a campain in which I add different clients (for example a trip to a foreign country where I meet 3 different clients), I would like this campaign to be linked to the expenses I have. Say I have a plane ticket, taxis and 1 hotel night, I would like those expenses to be linked to the 3 clients. With Zoho expense, it is not possible at the time (or maybe it is but I do not know how!). thanks
                                                                                                  • Function #4: Schedule Customer Statements

                                                                                                    Regularly sending statements to customers is an imperative part of many business processes as it helps foster strong customer relationships and provides timely guidance on payments. While you can generate the statement of accounts and have it sent over
                                                                                                  • Export multiple Invoice PDF

                                                                                                    As part of end of year accounting a client needs to export all of their Invoices in PDF from Zoho CRM. Do they need to click into every single Invoice and click the Export to PDF button. Is there a means of either doing a mass Export to PDF of all Invoices
                                                                                                  • How to create Sepa Direct Debit XML file: solution and code

                                                                                                    Even though Books provides a payment integration for Stripe and Gocardless (in Europe) there are customers that want to use the Sepa services of their own bank. Mainly because Stripe and Gocardless are quite expensive. In that case they would need a Sepa
                                                                                                  • Introducing 'Dynamic display' in the latest version of the Bigin Android mobile app.

                                                                                                    Hello everyone! In the latest version of the Bigin Mobile Android app (1.6.0), we have introduced support for Dynamic Display, which transforms the List View into a powerful and customizable visual interface. Dynamic Display: This feature allows users
                                                                                                  • CRM - Copy data from Single Line to Lookup Field

                                                                                                    Hello, I need help to create a workflow with a custom function in order to copy value from a single value field to a Lookup Field. Module : Shipment Single value field API name : Customer_ID Lookup field API name : Account_ID WOuld be great to have some
                                                                                                  • How to Parse XML Data Returned by API?

                                                                                                    I have several APIs integrated with my CRM and they work great. I am having some trouble though parsing data out of a large string/array in Funtions? I need to be able to pull the DeviceId and the WebSiteDeviceName from each PanelDevice. I would appreciate
                                                                                                  • Unable to add organization consultants and contractors in Zoho People

                                                                                                    Hello Team: I am unable to add my few consultants and contractors in Zoho People. How to add these people as Users?
                                                                                                  • Why can't I see the email from Zoho Campaigns Automation under Zoho CRM Leads module?

                                                                                                    I recently did update the field mapping on our Leads sync services between Zoho CRM and Zoho Campaigns. The end goal is to create tailored email drip campaigns with the use of segments and automation. I understand you can build cadences, email templates,
                                                                                                  • Linkedin - Recruiter System Connect

                                                                                                    Hi there! Does anyone here know how to connect Zoho Recruit to Linkedin Recruiter via Recruiter System Connect?
                                                                                                  • Lead Owner not importing all users only main user

                                                                                                    I have set up 3 users, 1 CEO, 2 Managers, all users have been verified. I'm using the Free ZOHO version. When I go to import Leads my Excel file has these 3 users listed as the Lead Owner. However when the import completes only 1 user is displayed as
                                                                                                  • Getting Data into zoho calendar from a creator app

                                                                                                    So how do you get a date that's created in an app, for example when a site visit is due, into the zoho calendar for the field engineers.
                                                                                                  • Create deal from estimate

                                                                                                    Hello, I have integrated CRM and books. I created an estimate on CRM but I would like to allocate that estimate to a deal with the contact. How can I do this please?
                                                                                                  • Next Page