How to Send a Zoho Sign Document from Zoho CRM & Auto-Update Signed Status

Sending a Zoho Sign document from Zoho CRM and updating the signed status when the end user completes the signature

Overview :

When a document is sent for Signature collection to the Contact / Lead (End User) from Zoho CRM, it is sent either using the "Send for Zoho Sign" default button (that is added by the Zoho Sign extension) or Using custom functions associated with an Automation or Button, where the field values that are filled by the recipient in the sign document, cannot be pushed back to Zoho CRM using any in-built automation and the Status of the Documents are not tracked by the extension as the Signature Document was created by a Custom Function. In order to address this, we have come up with a workaround.

Info
You can deploy the below solution using Zoho Flow (if you are a Zoho One Users or Zoho Flow Paid Standalone User) as the solution is reliant Flow to fetch the details from Zoho Sign on Signature completion.

Use case:

Let us consider a scenario where you are sending out a Zoho Sign Document to a Contact record from Zoho CRM; you have a signature field for the End User to sign and another field in the document "Company Name" to be filled by the End User.
 
Sample Script:
To send the sign document to the contact record's email.
 
  1. templateid = "476594000000050259";
  2. actionid = "476594000000050280";
  3. contactdetails = zoho.crm.getRecordById("Contacts",ContID);
  4. ContactEmail = contactdetails.get("Email");
  5. CompanyName = contactdetails.get("Account_Name").get("name");
  6. AccountID = contactdetails.get("Account_Name").get("id");
  7. FirstName = contactdetails.get("First_Name");
  8. LastName = contactdetails.get("Last_Name");
  9. actionMap = Map();
  10. fieldTextData = Map();
  11. fieldTextData.put("Company","" + CompanyName + "");
  12. fieldTextData.put("First Name","" + FirstName + "");
  13. fieldTextData.put("Last Name","" + LastName + "");
  14. actionMap.put("field_data",{"field_text_data":fieldTextData});
  15. eachActionMap1 = Map();
  16. eachActionMap1.put("recipient_name","" + FirstName + "");
  17. eachActionMap1.put("recipient_email","" + ContactEmail + "");
  18. eachActionMap1.put("action_type","SIGN");
  19. eachActionMap1.put("action_id",actionid);
  20. eachActionMap1.put("role","Reviewer");
  21. eachActionMap1.put("verify_recipient","false");
  22. fieldList = List();
  23. fieldList.add(eachActionMap1);
  24. actionMap.put("actions",fieldList);
  25. submitMap = Map();
  26. submitMap.put("templates",actionMap);
  27. parameters = Map();
  28. parameters.put("is_quicksend","true");
  29. parameters.put("data",submitMap);
  30. sendtemplate = zoho.sign.createUsingTemplate(templateid,parameters);
  31. info sendtemplate;
 
Where,
  1. templateid is the id of the template you created in the Zoho sign.
  2. actionid can be fetched using the following sample,
    1. actiondetails = zoho.sign.getTemplates();
    2. actionid = actiondetails.get("templates").getJSON("actions");
  3. Map arguments for ContID with the respective contact id.


Now, let us look at the steps to fetch the status of the document and the respective values filled by the recipient in the document to push back to Zoho CRM. 

Step 1 :

We need to modify the above function by appending a small part of the script that is used to create a Zoho Sign Document record in CRM.

Notes
Notes :

"Zoho Sign Document" is a custom module that gets created by the Zoho Sign Extension for Zoho CRM. Whenever a Zoho Sign Document is sent for signature using the "Send for Zoho Sign" button, a record gets created in the "Zoho Sign document" module. This record contains information about the document ID (Zoho Sign document ID), Parent records in CRM to which the document was sent, Status of the Document, etc.
 

Script :

  1. SignDocumentID = sendtemplate.get("requests").get("request_id");
  2. DocumentName = sendtemplate.get("requests").get("request_name");
  3. mp = Map();
  4. mp.put("zohosign__Contact",ContID);
  5. mp.put("zohosign__Account",AccountID);
  6. mp.put("zohosign__ZohoSign_Document_ID",SignDocumentID);
  7. mp.put("Name",DocumentName);
  8. Create = zoho.crm.createRecord("zohosign__ZohoSign_Documents",mp);
  9. info Create;
 
where,
  1. Replace "zohosign__Contact", "zohosign__Account",  "zohosign__ZohoSign_Document_ID" and "Name" in the code with the API names of the Account, Contact,  Zoho Sign Document ID and Zoho Sign Documents Name fields in the Zoho Sign Documents module.
  2. Replace "zohosign__ZohoSign_Documents" with the module API name of Zoho Sign Documents module.
  3. ContId and AccountId are the respective contact and account records ids.

Sample Script with above changes as follows
:

To create the record in the necessary modules to track the request.

  1. //Fetch actionid details
  2. /*actiondetails = zoho.sign.getTemplates();
  3. actionid =  actiondetails.get("templates").getJSON("actions").getJSON("action_id");
  4. info actionid;*/
  5. templateid = "476594000000050259";
  6. actionid = "476594000000050280";
  7.  
  8. //fetch the contact and account details
  9. contactdetails = zoho.crm.getRecordById("Contacts",ContID);
  10. ContactEmail = contactdetails.get("Email");
  11. CompanyName = contactdetails.get("Account_Name").get("name");
  12. AccountID = contactdetails.get("Account_Name").get("id");
  13. FirstName = contactdetails.get("First_Name");
  14. LastName = contactdetails.get("Last_Name");
  15.  
  16. //Making a parameter map to create a Zoho Sign document with prefilled fields using a Zoho Sign Template.
  17. actionMap = Map();
  18. fieldTextData = Map();
  19. fieldTextData.put("Company","" + CompanyName + "");
  20. fieldTextData.put("First Name","" + FirstName + "");
  21. fieldTextData.put("Last Name","" + LastName + "");
  22. actionMap.put("field_data",{"field_text_data":fieldTextData});
  23. eachActionMap1 = Map();
  24. eachActionMap1.put("recipient_name","" + FirstName + "");
  25. eachActionMap1.put("recipient_email","" + ContactEmail + "");
  26. eachActionMap1.put("action_type","SIGN");
  27. eachActionMap1.put("action_id",actionid);
  28. eachActionMap1.put("role","Reviewer");
  29. eachActionMap1.put("verify_recipient","false");
  30. fieldList = List();
  31. fieldList.add(eachActionMap1);
  32. actionMap.put("actions",fieldList);
  33. submitMap = Map();
  34. submitMap.put("templates",actionMap);
  35. parameters = Map();
  36. parameters.put("is_quicksend","true");
  37. parameters.put("data",submitMap);
  38.  
  39. // create template
  40. sendtemplate = zoho.sign.createUsingTemplate(templateid,parameters);
  41. info sendtemplate;
  42. //Create ZohoSing Document IN CRM
  43. SignDocumentID = sendtemplate.get("requests").get("request_id");
  44. DocumentName = sendtemplate.get("requests").get("request_name");
  45. mp = Map();
  46. mp.put("zohosign__Contact",ContID);
  47. mp.put("zohosign__Account",AccountID);
  48. mp.put("zohosign__ZohoSign_Document_ID",SignDocumentID);
  49. mp.put("Name",DocumentName);
  50. Create = zoho.crm.createRecord("zohosign__ZohoSign_Documents",mp);
  51. info Create;
 
Notes
Notes :
This additional code in your existing function will ensure that a Zoho Sign Document record is created in Zoho CRM, once the document is sent for signature and it also fetches the Document ID of the Sign document and updates it into this CRM record. Later, we can use this document ID and fetch the values of fields from the respective Sign document in Zoho Sign.

Step 2 :

You will have to create a Flow in Zoho Flow which should be triggered on the change of the status (Signed/ Completed) of the document and update it in Zoho CRM. The reason for using Zoho Flow is, this automation cannot be setup in Zoho Sign or Zoho CRM, as there is no valid trigger point for this action.

You can refer to the entire setup of Zoho Flow in screen cast below.


Step 3 :

Setup a Workflow for Zoho Sign Documents module in Zoho CRM. The workflow will be triggered when the Zoho Sign Document record is updated to "Signed". The purpose is to fetch the values updated in the sign document and update the same in the contact record.

  1. Kindly navigate to setup >  Automation > Worlflow Rules > Click on Create rule.
  2. Please select the module name as Zoho Sign Documents and specify the name of the Workflow Rule
  3. Now, select the trigger as "Record Action" as "Edit" and in the next field select "specific field is modified". It will probe you to select the field name and there select the Document Status field.

  4. Set the Workflow condition as "Document Status is Signed"

  5. In the Instant action > click on Functions > Configure function > write your function name > specify the function name and display name. Now, paste the below code.
 
  1. //Fetch the SignDocument record details
  2. signdocumentdetails = zoho.crm.getRecordById("zohosign__ZohoSign_Documents",ID);
  3. DocID = signdocumentdetails.get("zohosign__ZohoSign_Document_ID");
  4. ContactID = signdocumentdetails.get("zohosign__Contact").get("id");
  5. documentdetails = zoho.sign.getDocumentById(DocID);
  6.  
  7. //Fetch the field to be updated in crm
  8. CRMFieldInfo = documentdetails.get("requests").get("actions").get(0).get("fields");
  9. //info CRMFieldInfo;
  10. //update the contact record
  11. for each  rec in CRMFieldInfo
  12. {
  13. if(rec.get("field_name") == "Company")
  14. {
  15. Company = rec.get("field_value");
  16. info Company;
  17. mp = Map();
  18. mp.put("Title",Company);
  19. update = zoho.crm.updateRecord("Contacts",ContactID,mp);
  20. info update;
  21. }
  22. }
 

Notes
Notes :
Map "ID" with the respective ZohoSign Document id. Company is the field that I had inserted inside the sign document to fill in by the recipient


 

Conclusion:

By implementing the above steps using Flow, it is ensured that a document can be sent to a recipient for signing, and that the values entered by the recipient during the signing process are automatically captured and updated back in Zoho CRM, enabling a smooth and efficient data synchronization.

In the above code using flow, we have updated the following. :
  1. A Zoho Sign document is sent directly from Zoho CRM to a specific Contact record.
  2. The End User receives an email notification and opens the document for signing. During the signing process, they are prompted to fill in an additional field named “Company.”
  3. After the document is submitted, the corresponding record in the Zoho Sign Documents module is automatically updated with the status Signed via flow.
  4. Based on the above action, the workflow created for the contacts module will update the fetched company value to a field called "Title" in Contacts module.

Please refer to the below screen cast which covers the outcome of the above steps.
 

 
 

Tips:  

  1. Ensure to use the correct API Names for both Module & Fields in the script.
  2. While writing the script, we would suggest you to add info() logs to each variable to check the output for seamless functionality under the Console section within Zoho CRM Function IDE.
  3. Ensure to use the Optimised Code in Custom Function to avoid facing limitations related to statement execution or execution time limits. Refer to Deluge Limitations for more information.
  4. When you need to use 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.
  5. When you use get() method in Deluge function, try using ifNull() conditional statement to avoid any errors that say "get value is null" and execution stops immediately. When you associate a function with any automation (e.g, Workflow Rules) and if such error occurred, it would stop function execution for respective record. Help LINK to know more about ifNull statement.
  6. Incase, if the associated function is not executed in the respective record via the Automation Feature (e.g., Workflow Rules), then check the failure reason under "Setup >> Developer Hub >> Functions >> Failures".
 
Notes
Notes :
Visit the Help Link to understand Common Deluge Error Messages that may occur during Custom Function execution.
  

Learn How to Optimize the Code

Limit Logging in Production
  1. When a user adds too many info() logs, it may slow down execution. While testing, add info() logs to each variable, and once tested, comment the non-required info() logs. i.e., use conditional logging only for debugging purposes.

Use Try-Catch Blocks

  1. Use try-catch blocks to handle exceptions smartly without wrapping every line in a try. Log the required error messages that help trace the exact issue with the line of code. Refer to the following Help Link to know the syntax & sample code.

Notes
Notes :
To ensure a smooth implementation, we recommend configuring and testing the setup in the sandbox environment before deploying it to product
ion.



Quote
Custom Solution Created by Sakthi Priya | Zoho Partner Support.

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

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