There are situations where you need to send a ZohoSign Document via a Deluge custom function upon criteria met, instead of using the manual “Send for ZohoSign” button from a record. It is important to note that when a ZohoSign Document is sent from CRM using the default button, 3 records in 3 separate modules are automatically created in the backend – ZohoSign Documents, ZohoSign Document Events, ZohoSign Recipients. The same does not happen however, when it is sent via Deluge. For document trackability in CRM, we think that it’s sufficient for the function to only account for the record creation in the ZohoSign Documents module.
Before you can use this script with Zoho CRM, you must specify the following in the script:
This script works in the following order:
//Get the name, address, email or any other necessary fields to merge in the Zoho Sign Document record = zoho.crm.getRecordById("***ZOHO CRM RECORD","***RECORD ID***"); name = record.get("***NAME FIELD***"); street = record.get("Shipping_Street"); state = record.get("Shipping_State"); city = record.get("Shipping_City"); code = record.get("Shipping_Code"); nameaddress = name + "\n" + street + ", " + state + "," + "\n" + city + ", " + code; email = record.get("***EMAIL FIELD***"); //Making a parameter map to create a Zoho Sign document with prefilled fields using a Zoho Sign Template - Note: You first need to create a template in Zoho Sign actionMap = Map(); fieldTextData = Map(); fieldTextData.put("Name and Address",nameaddress); actionMap.put("field_data",{"field_text_data":fieldTextData}); eachActionMap1 = Map(); eachActionMap1.put("recipient_name",name); eachActionMap1.put("recipient_email",email); eachActionMap1.put("action_type","SIGN"); eachActionMap1.put("action_id","111430000000143036"); eachActionMap1.put("role","Reviewer"); eachActionMap1.put("verify_recipient","false"); fieldList = List(); fieldList.add(eachActionMap1); actionMap.put("actions",fieldList); submitMap = Map(); submitMap.put("templates",actionMap); parameters = Map(); parameters.put("is_quicksend","true"); parameters.put("data",submitMap); //Send the Zoho Sign Template with the pre-filled fields to the desired recipient/ recipients response = zoho.sign.createUsingTemplate("***ZOHO SIGN TEMPLATE ID***",parameters); //Get the Template Name - used as the name for the record in the "ZohoSign Documents" module in Zoho CRM later template = zoho.sign.getTemplateById("***ZOHO SIGN TEMPLATE ID***""); templatename = template.get("templates").get("template_name"); //Get the Zoho Sign Document ID requests = response.get("requests"); docs = requests.get("document_ids"); docinfo = docs.get(0); docid = docinfo.get("document_id"); //Get the Zoho Sign Request ID reqid = requests.get("request_id"); docinfo = docs.get(0); docid = docinfo.get("document_id"); //Create Map for CRM Record - ZohoSign Documents recordmap = Map(); recordmap.put("Name",templatename); recordmap.put("zohosign__Account",accountid); recordmap.put("zohosign__Deal",dealid); recordmap.put("zohosign__Owner",deal.get("Owner").get("id")); recordmap.put("zohosign__Date_Sent",today); recordmap.put("zohosign__ZohoSign_Document_ID",docid); recordmap.put("zohosign__Module_Record_ID",dealid.toString()); recordmap.put("zohosign__Document_Deadline",today.addDay(3)); //--> This is arbitrary recordmap.put("zohosign__Document_Status","Out for Signature"); //Check Date and Frequency are additional fields created in the "ZohoSign Documents" CRM Module to control the email notification triggering and field update via workflow rule recordmap.put("Check_Date",today.addDay(1)); recordmap.put("Frequency",0); recordmap.put("Request_ID",reqid); //Create a Record in the "ZohoSign Documents" module in Zoho CRM create = zoho.crm.createRecord("zohosign__ZohoSign_Documents",recordmap);
Because the ZohoSign Document is being triggered manually via Deluge instead of the default system button, the fields in the ZohoSign Document CRM module do not get updated automatically. Hence, a workflow rule with custom function is needed to get the document status and other relevant information from ZohoSign, then update in the record in Zoho CRM. Concurrently, an email notification reminder to the record owner (which many people find useful) can also be acheived here.
Check Date
05:00 AM
(time is arbitrary, though it’s recommended to set the time before work usually starts for updated data)Once
Document Status
doesn’t contain SIGNED
ANDDocument Deadline
due in days >= 0
ANDFrequency
< 3
(this acts as a controller to stop the workflow after a specified number is reached – you may change it to any other number you desire) //Get the Document Status record = zoho.crm.getRecordById("zohosign__ZohoSign_Documents",recordid); requestid = record.get("Request_ID"); document = zoho.sign.getDocumentById(requestid); status = document.get("requests").get("actions").get(0).get("action_status"); //Validation - If document is signed, update status and sign date. Otherwise, add the Check Date and Frequency by 1 day if(status = "SIGNED") { signdate = document.get("requests").get("action_time"); signdate = signdate.toDate("yyyy-MM-dd"); update1 = zoho.crm.updateRecord("zohosign__ZohoSign_Documents",recordid,{"zohosign__Document_Status":status}); update2 = zoho.crm.updateRecord("zohosign__ZohoSign_Documents",recordid,{"zohosign__Date_Completed":signdate}); } else { frequency = record.get("Frequency") + 1; update3 = zoho.crm.updateRecord("zohosign__ZohoSign_Documents",recordid,{"Check_Date":today.addDay(1)}); update4 = zoho.crm.updateRecord("zohosign__ZohoSign_Documents",recordid,{"Frequency":frequency}); }
Click here to copy these scripts. For more Zoho-wizardry, check out our GitHub page.
When scripting, ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit....
Learn to create a customized inventory report with Zoho Analytics. This tutorial contains a link to our GitHub page for SQL code that will help with your table creations....
How nice would it be if you could, at the press of a button, send clients an email w/a Zoho Books invoice? Replete with “Pay Now” buttons that link to PayPal/Stripe/other payment gateways?...
Whether you work primarily out of CRM or the Zoho Finance Suite, you can use Analytics to build commissions dashboards. This involves some fairly simple SQL code....
If you are an inventory manager, this blog post could change your life. If you are not, it will at least teach you how to build some wicked inventory tracking for your business....
Convert fields, related activities, attachments, notes and more from one record to another across modules via custom function....