How do I set up a callback function in CRM to add Zoho Sign document details?

How do I set up a callback function in CRM to add Zoho Sign document details?

Scenario: I have set up an automation in ZohoCRM to send documents to Zoho Sign. Each time I want to view the documents, I need to view them at Zoho Sign. It is difficult to view the document status this way. Can I set up a callback function in CRM to add Zoho Sign document details?

  1. When documents are sent for signature from CRM using Zoho Sign's extension, the documents will be updated in CRM. However, in other instances such as automation and workflow, this will not be done.
  2. You need to create a custom callback function, which can be done by following these steps. 
Paste the following code:

  1. crmAPIRequestMap = crmAPIRequest.toMap();
  2. request_body = crmAPIRequestMap.get("body");
  3. info request_body;
  4. requestMap = request_body.toMap();
  5. response = Map();
  6. response.put("status_code",200);
  7. response.put("Content-Type","application/json");
  8. hasRequests = requestMap.containKey("requests");
  9. if(requestMap.containKey("requests") && requestMap.containKey("notifications"))
  10. {
  11. notificationMap = requestMap.get("notifications").toMap();
  12. requestStr = requestMap.get("requests");
  13. requestObj = requestStr.toMap();
  14. response.put("body",{"what we got":requestObj,"notification":notificationMap});
  15. if(requestObj.containKey("request_status") && notificationMap.containKey("operation_type"))
  16. {
  17. operationType = notificationMap.get("operation_type");
  18. //if(requestObj.get("request_status").equals("completed"))
  19. if(operationType.equals("RequestCompleted") || operationType.equals("RequestSigningSuccess") || operationType.equals("RequestRecalled") || operationType.equals("RequestRejected") || operationType.equals("RequestExpired"))
  20. {
  21. requestStatus = "Out for Signature";
  22. if(operationType.equals("RequestCompleted"))
  23. {
  24. requestStatus = "Signed";
  25. }
  26. else if(operationType.equals("RequestRecalled"))
  27. {
  28. requestStatus = "Recalled";
  29. }
  30. else if(operationType.equals("RequestRejected"))
  31. {
  32. requestStatus = "Declined";
  33. }
  34. else if(operationType.equals("RequestExpired"))
  35. {
  36. requestStatus = "Expired";
  37. }
  38. requestId = requestObj.get("request_id");
  39. //Check if already exists
  40. zsignrecord = zoho.crm.searchRecords("zohosign__ZohoSign_Documents","(zohosign__ZohoSign_Document_ID:equals:" + requestId + ")");
  41. if(zsignrecord.size() > 0 && zsignrecord.get(0).containKey("zohosign__DeleteEdit_Preview_or_Position_Signature_Fields"))
  42. {
  43. info "Record already present";
  44. response.put("body",{"message":"Record already present, updating"});
  45. if(zsignrecord.get(0).get("zohosign__DeleteEdit_Preview_or_Position_Signature_Fields") == false)
  46. {
  47. //Needs to be updated
  48. zsrecordId = zsignrecord.get(0).get("id");
  49. recordInfo = {"zohosign__Document_Status":requestStatus};
  50. resp = zoho.crm.createRecord("zohosign__ZohoSign_Documents",zsrecordId,recordInfo);
  51. if(resp.containKey("id"))
  52. {
  53. response.put("body",{"message":"Updated record"});
  54. }
  55. }
  56. else
  57. {
  58. return {"crmAPIResponse":response};
  59. }
  60. }
  61. else
  62. {
  63. response.put("body",{"request_id":requestId});
  64. associatedModule = "Contacts";
  65. associatedModuleKey = "zohosign__Contact";
  66. actions = requestObj.get("actions");
  67. email = actions.get(0).get("recipient_email");
  68. records = zoho.crm.searchRecords("Contacts","(Email:equals:" + email + ")");
  69. if(records.size() <= 0)
  70. {
  71. records = zoho.crm.searchRecords("Leads","(Email:equals:" + email + ")");
  72. if(records.size() > 0)
  73. {
  74. associatedModule = "Leads";
  75. associatedModuleKey = "zohosign__Lead";
  76. }
  77. }
  78. if(records.size() > 0)
  79. {
  80. info "Record found";
  81. leadid = records.get(0).get("id");
  82. recordInfo = {"Name":requestObj.get("request_name"),associatedModuleKey:leadid,"zohosign__Document_Status":requestStatus,"zohosign__ZohoSign_Document_ID":requestId,"zohosign__Date_Completed":today,"zohosign__Module_Name":associatedModule,"zohosign__Module_Record_ID":leadid};
  83. //Create ZohoSign Record in CRM
  84. resp = zoho.crm.createRecord("zohosign__ZohoSign_Documents",recordInfo);
  85. if(resp.containKey("id"))
  86. {
  87. zsDocId = resp.get("id");
  88. respDoc = zoho.sign.downloadDocument(requestId);
  89. zoho.crm.attachFile("zohosign__ZohoSign_Documents",zsDocId,respDoc);
  90. response.put("body",{"attached to record":zsDocId});
  91. //Create zoho sign recipients record for all recipients
  92. for each  action in actions
  93. {
  94. recpStatus = "Waiting for Signature";
  95. if(action.get("action_status").equals("SIGNED"))
  96. {
  97. recpStatus = "Signed";
  98. }
  99. else if(action.get("action_status").equals("DECLINED"))
  100. {
  101. recpStatus = "Cancelled";
  102. }
  103. recpRecordInfo = {"Name":action.get("recipient_name"),"zohosign__Email":action.get("recipient_email"),"zohosign__ZohoSign_Document":zsDocId,"zohosign__Recipient_Order":action.get("signing_order"),"zohosign__Recipient_Type":action.get("action_type"),"zohosign__Recipient_Status":recpStatus};
  104. zoho.crm.createRecord("zohosign__ZohoSign_Recipients",recpRecordInfo);
  105. }
  106. }
  107. else
  108. {
  109. response.put("body",{"error":resp});
  110. }
  111. }
  112. }
  113. }
  114. else
  115. {
  116. response.put("body",{"not completed":requestObj});
  117. }
  118. }
  119. else
  120. {
  121. response.put("body",{"no request status":requestObj});
  122. }
  123. }
  124. else
  125. {
  126. info "Error";
  127. response.put("body",{"error":"No requests key"});
  128. }
  129. return {"crmAPIResponse":response}

    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









                                            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

                                                  Zoho Desk Resources

                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                    Zoho Marketing Automation

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

                                                                                                              • How to set up a callback function in CRM to add Zoho Sign document details that is triggered by the Zoho Sign webhook?

                                                                                                                Scenario: Within a Custom module in ZohoCRM, I have set up an automation to send documents to Zoho Sign. Each time I want to view the documents, I need to view them at Zoho Sign. Can I set up a callback function in CRM to add Zoho Sign document ...
                                                                                                              • Zoho Sign credits

                                                                                                                What are Zoho Sign credits and what are they used for? Zoho Sign credits are a prepaid add-on that requires an additional purchase on top of the subscription cost of the Zoho Sign general licensing plans. Zoho Sign credits are consumed when users in ...
                                                                                                              • Integrating Zoho Sign with Zoho People

                                                                                                                Available in all Data Centers. From onboarding documents to exit letters, the HR department handles tons of employee and company information. Most of these documents will require signatures from the employees, after which they need to be returned and ...
                                                                                                              • Zoho Sign integration with Pipedrive

                                                                                                                Available only in Enterprise edition Zoho Sign now integrates with Pipedrive, customer relationship management software that helps small and medium businesses to manage their sales pipeline. This integration can help sales team to directly send ...
                                                                                                              • Creating Templates in Zoho People

                                                                                                                Available in all data centers. Administrators and template owners can create and send templates directly from Zoho People, or you can create and import templates from your Zoho Sign account. Creating templates in your Zoho People account From your ...
                                                                                                                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