Streamline Document Sharing for Deals in Zoho CRM using Custom Functions

Streamline Document Sharing for Deals in Zoho CRM using Custom Functions

Requirement Overview

A Zoho CRM user wants to automate and simplify the process of sharing deal-related documents (such as proposals, invoices, or contracts) with customers directly using Custom Function instead of sending them manually by selecting each attachment.

Use Case

A company using Zoho CRM sells electronic products to customers, and during the sales process, the sales team uploads several documents to the Deal record:

  1. Proposal
  2. Pricing Doc
  3. Case Studies
  4. Purchase Order
  5. Contracts

These documents are stored under the Attachments section of the Deal in Zoho CRM.

Once a deal is marked as “Closed Won”, The company needs to send all the deal-related documents to the associated contact.


Challenges in sending documents manually: The sales representative has to click on the ‘Send Mail’ button every time a deal is marked as ‘Closed Won’ and attach each related document one by one and compose an email, which results in time consumption.


Why It is Important:

  1. Time Saving
  2. Zero Errors
  3. Scalability 
  4. Mitigated Risk
  5. Impoved Customer Experience by sharing files instantly

Info

Permission & Availability

Info
-> Users with the Manage Extensibility permission can create connections and write custom functions.
-> Users with the Manage Automation permission can configure Workflow Rules.
-> Users with the Manage Sandbox permission can manage the sandbox and test this use-case.

Configuration

Since sales representative wants all the documents to be sent when deal is marked as "Closed Won". We can use the "Workflow Rule" automation feature to trigger whenever a deal stage is updated to "closed won" and execute the custom function to get all attachments of the deal and send them as an email to the associated contact.
  1. Workflow Rule Configuration:

Navigate to Setup (⚙️) in Zoho CRM >> Automation >> Workflow Rules >> Create Rule

Select "Deal" module and provide a Name to rule along with a Description.

-> When: Select Record Action >> Edit >> Specific Stage Field gets modified to value "Closed Won" >> "Repeat" enabled 
-> Condition: All Deals
-> Instant Actions: Select Function >> Write own function


  1. Create a Connection:

Navigate to Setup (⚙️) in Zoho CRM >> Developer Hub >> Connections >> My Connection >> Create Connection

Select "Zoho OAuth" as service and provide Name to "Connection". Then, select the below scopes:
  1. ZohoCRM.modules.ALL
  2. ZohoCRM.settings.ALL
  3. ZohoCRM.modules.attachments.all

The Code

  1. void automation.toSendDealDocuments(Int dealRecordID,String associatedContactEmail)
  2. {
  3. //Get contact name associated to deal - to use it in email message
  4. dealData = zoho.crm.getRecordById("Deals",dealRecordID);
  5. // info dealData;
  6. dealContact = ifNull(dealData.get("Contact_Name"),"");
  7. dealContactName = ifNull(dealContact.get("name"),"");
  8. //Can also add via argument directly to get name - same as contact email
  9. // info dealContactName;
  10. // info associatedContactEmail;
  11. //Get all attachment from deal
  12. relatedrcords = zoho.crm.getRelatedRecords("Attachments","Deals",dealRecordID);
  13. info relatedrcords;
  14. if(relatedrcords.size() > 0)
  15. {
  16. attachementIdList = List();
  17. for each  ele in relatedrcords
  18. {
  19. attachementId = ele.get("id");
  20. //getting all attachment id
  21. attachementIdList.add(attachementId);
  22. }
  23. info attachementIdList.size();
  24. fileList = List();
  25. //getting each attachment from deal using attachment id and adding into list
  26. for each index i in attachementIdList
  27. {
  28. downloadFile = invokeurl
  29. [
  30. url :"https://www.zohoapis.com/crm/v2/Deals/" + dealRecordID + "/Attachments/" + attachementIdList.get(i)
  31. type :GET
  32. connection:"send_email_with_attachment"
  33. ];
  34. //  info downloadFile;
  35. fileList.add(downloadFile);
  36. }
  37. //Sending email to contact with all deal-related documents
  38. toAddress = associatedContactEmail;
  39. sendmail
  40. [
  41. from :zoho.adminuserid
  42. to :toAddress
  43. subject :"Deal Documents"
  44. message :"Hi " + dealContactName + ", Please find all attachments related to the deal."
  45. Attachments :file:fileList
  46. ]
  47. }
  48. else
  49. {
  50. info "No attachments found for this deal.";
  51. }
  52. }
  1. Field Argument Mapping in Deluge Setup


  1. Code Explanation

-> Script will fetch the current executed record using record id (via passed argument - dealRecordID
-> From the fetched record data, it will get the field (Contact_Name) value and store the name in variable.
-> Then, it will fetch all the uploaded attachments from respective deal record and store into variable. Later, checking if there is any attachment or not. If yes, then creating a list (attachementIdList) and using loop, getting attachment IDs and store them in mentioned list.
-> Now, using a Loop again and fetching all attachment using attached IDs to store into a file. Which then, later passed on to Send Mail Task. 

Working Demo - Screencast


  1. End Result - Recieved Email from Zoho CRM:


AlertTo ensure a smooth implementation, we recommend configuring and testing the setup in the sandbox environment before deploying it to production.

TIPS: Avoid Common Errors

-> Ensure to use the correct API Names for both Module & Fields in the script.


-> To ensure you get the intended output, we would suggest you to use info() logs to each variable to check the output for seamless functionality under the Console section within Zoho CRM Function IDE.


-> Since we have used the Connections within a function script, ensure to have the required scopes added in connection to perform the intended API action. Also, ensure to use the connection link name (i.e., crm_connection ) while passing on to Deluge Invoke URL or Integration Task. 

-> As a common practice, we have used US DC API end point. If you are using CRM account in a different DC (i.e., IN, EU, CA, AU, etc.), then we would recommend you to use the API end point URL according to your DC.

For example:
US DC - "https://www.zohoapis.com/crm/v2/Deals/" + dealRecordID + "/Attachments/" + attachementIdList.get(i)
IN DC - "https://www.zohoapis.in/crm/v2/Deals/" + dealRecordID + "/Attachments/" + attachementIdList.get(i)
EU DC - "https://www.zohoapis.eu/crm/v2/Deals/" + dealRecordID + "/Attachments/" + attachementIdList.get(i)

-> Since the Automation Feature (e.g., Workflow Rules) is involved in this use-case, if the intended functionality does not work, then users can check the associated function failure reason under "Setup >> Developer Hub >> Functions >> Failures". Additionally, Users can also see the complete Log of all function execution for any specific created function to track the executions (i.e. under My Functions >> 3 Dots >> Logs). This also help in a scenario where a function is executed via Workflow rule in CRM record(shows in timeline), however it didn't perform the intended actions/updates in record. In such scenario, users can check the output (info logs) & error of execution via function logs within Zoho CRM.

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.



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.

      Create. Review. Publish.

      Write, edit, collaborate on, and publish documents to different content management platforms.

      Get Started Now


        Access your files securely from anywhere

          Zoho CRM Training Programs

          Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

          Zoho CRM Training
            Redefine the way you work
            with Zoho Workplace

              Zoho DataPrep Personalized Demo

              If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

              Zoho CRM Training

                Create, share, and deliver

                beautiful slides from anywhere.

                Get Started Now


                  Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                  BOOK A SESSION







                              Quick LinksWorkflow AutomationData Collection
                              Web FormsEnterpriseOnline Data Collection Tool
                              Embeddable FormsBankingBegin Data Collection
                              Interactive FormsWorkplaceData Collection App
                              CRM FormsCustomer ServiceAccessible Forms
                              Digital FormsMarketingForms for Small Business
                              HTML FormsEducationForms for Enterprise
                              Contact FormsE-commerceForms for any business
                              Lead Generation FormsHealthcareForms for Startups
                              Wordpress FormsCustomer onboardingForms for Small Business
                              No Code FormsConstructionRSVP tool for holidays
                              Free FormsTravelFeatures for Order Forms
                              Prefill FormsNon-Profit

                              Intake FormsLegal
                              Mobile App
                              Form DesignerHR
                              Mobile Forms
                              Card FormsFoodOffline Forms
                              Assign FormsPhotographyMobile Forms Features
                              Translate FormsReal EstateKiosk in Mobile Forms
                              Electronic Forms
                              Drag & drop form builder

                              Notification Emails for FormsAlternativesSecurity & Compliance
                              Holiday FormsGoogle Forms alternative GDPR
                              Form to PDFJotform alternativeHIPAA Forms
                              Email FormsFormstack alternativeEncrypted Forms

                              Wufoo alternativeSecure Forms

                              WCAG

                                      Create. Review. Publish.

                                      Write, edit, collaborate on, and publish documents to different content management platforms.

                                      Get Started Now







                                                        You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                            Manage your brands on social media


                                                              • Desk Community Learning Series


                                                              • Digest


                                                              • Functions


                                                              • Meetups


                                                              • Kbase


                                                              • Resources


                                                              • Glossary


                                                              • Desk Marketplace


                                                              • MVP Corner


                                                              • Word of the Day


                                                              • Ask the Experts


                                                                Zoho Sheet Resources

                                                                 

                                                                    Zoho Forms Resources


                                                                      Secure your business
                                                                      communication with Zoho Mail


                                                                      Mail on the move with
                                                                      Zoho Mail mobile application

                                                                        Stay on top of your schedule
                                                                        at all times


                                                                        Carry your calendar with you
                                                                        Anytime, anywhere




                                                                              Zoho Sign Resources

                                                                                Sign, Paperless!

                                                                                Sign and send business documents on the go!

                                                                                Get Started Now




                                                                                        Zoho TeamInbox Resources





                                                                                                  Zoho DataPrep Demo

                                                                                                  Get a personalized demo or POC

                                                                                                  REGISTER NOW


                                                                                                    Design. Discuss. Deliver.

                                                                                                    Create visually engaging stories with Zoho Show.

                                                                                                    Get Started Now








                                                                                                                        • Related Articles

                                                                                                                        • 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 ...
                                                                                                                        • Contacts and Products Association from Zoho CRM to Zoho Desk

                                                                                                                          Summary: By default, the Zoho CRM–Zoho Desk integration only syncs Contacts, Accounts, and Products as standalone modules. However, the associations between Products and Contacts/Accounts are not preserved during the sync. This article explains a ...
                                                                                                                        • Update "Modified by" field in Zoho CRM records using custom function

                                                                                                                          Overview In Zoho CRM, the “Modified By” field automatically captures the name of the user who last made changes to a record’s fields. However, updating this field manually or either via UI or by passing a user ID in a custom function is not possible. ...
                                                                                                                        • Importing Record Images in Bulk in Zoho CRM

                                                                                                                          Overview In Zoho CRM, visual representation of records such as product thumbnails or contact photos greatly improves user experience, helps with identification, and supports marketing workflows. However, uploading these images manually for each ...
                                                                                                                        • Client Script: Effective way to handle Data Validation before Lead Conversion in Zoho CRM

                                                                                                                          Requirement Overview A Zoho CRM organization wants to have validation within Lead module for all Contact's mandatory fields before Lead Conversion. i.e. The Business need an easier & best way to validate lead data before Lead Conversion using default ...
                                                                                                                          Wherever you are is as good as
                                                                                                                          your workplace

                                                                                                                            Resources

                                                                                                                            Videos

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



                                                                                                                            eBooks

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



                                                                                                                            Webinars

                                                                                                                            Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                            CRM Tips

                                                                                                                            Make the most of Zoho CRM with these useful tips.



                                                                                                                              Zoho Show Resources