Send contract via zoho sign from zoho crm

PHOTO EMBED

Fri Aug 01 2025 06:28:36 GMT+0000 (Coordinated Universal Time)

Saved by @usman13

void automation.Send_Contract_Via_Zoho_Sign(String deal_id)
{
//////////Get the zoho crm data///
//////////
deals_Data = zoho.crm.getRecordById("Deals",deal_id);
landlords_details = deals_Data.get("Landlords");
Floor = deals_Data.get("Floor");
Passport_Number = deals_Data.get("Passport_Number");
Unit_Number = deals_Data.get("Unit_Number");
// ===  Pick Template Dynamically Based on Signer Count ===
template_id = null;
landlord_count = landlords_details.size();
if(landlord_count == 1)
{
	template_id = 489483000000043453;
}
else if(landlord_count == 2)
{
	template_id = 489483000000043243;
}
else if(landlord_count == 3)
{
	template_id = 489483000000043483;
}
else if(landlord_count == 4)
{
	template_id = 489483000000043521;
}
else
{
	info "Unsupported number of landlords: " + landlord_count;
}
// === Get Template Details from Zoho Sign ===
//info template_id;
templateResp = zoho.sign.getTemplateById(template_id,"zoho_sign");
//info templateResp;
signerActionList = List();
if(templateResp.containKey("templates"))
{
	templateData = templateResp.get("templates");
	signerActionList = templateData.get("actions");
}
actionsList = List();
index = 0;
// ===  Map Landlords to Signer Actions ===
for each  data in landlords_details
{
	Email = data.get("Email_1");
	Buyer_Name = data.get("Buyer_Name");
	if(Email != null && Email != "" && index < signerActionList.size())
	{
		templateAction = signerActionList.get(index);
		action_id = templateAction.get("action_id");
		signer = Map();
		signer.put("action_id",action_id);
		signer.put("recipient_name",Buyer_Name);
		signer.put("recipient_email",Email);
		signer.put("action_type","SIGN");
		actionsList.add(signer);
		index = index + 1;
	}
}
// === Add Manager Signer If Present in Template ===
for each  actionMap in signerActionList
{
	if(actionMap.get("role") == "Manager")
	{
		managerSigner = Map();
		managerSigner.put("action_id",actionMap.get("action_id"));
		managerSigner.put("recipient_name","Awais");
		managerSigner.put("recipient_email","m.awais@leosuk.com");
		managerSigner.put("action_type","SIGN");
		actionsList.add(managerSigner);
		break;
	}
}
////////////////Add the fields data for zoho sign
//////////////////
field_text_data = Map();
field_text_data.put("Unit Number",Unit_Number);
field_text_data.put("Passport Number",Passport_Number);
field_text_data.put("Owner",Buyer_Name);
field_text_data.put("Floor",Floor);
field_data = Map();
field_data.put("field_text_data",field_text_data);
////////////
///////////////////////////
//////////////////
// === Prepare Payload and Send ===
templateActions = Map();
templateActions.put("actions",actionsList);
templateActions.put("field_data",field_data);
submitMap = Map();
submitMap.put("templates",templateActions);
parameters = Map();
parameters.put("is_quicksend","true");
parameters.put("data",submitMap);
//info "Final Payload: " + parameters;
response = zoho.sign.createUsingTemplate(template_id,parameters,"zoho_sign");
info response;
//===  Update CRM Deal Record with Zoho Sign Info ===
reqId = response.get("requests").get("request_id");
docId = response.get("requests").get("document_ids").get(0);
Document_id = response.get("requests").get("document_fields").get(0).get("document_id");
mpdocx = Map();
mpdocx.put("request_id",reqId);
mpdocx.put("Zoho_Sign_Document_ID",Document_id.toString());
mpdocx.put("Stage","Contract Sent");
update = zoho.crm.updateRecord("Deals",deal_id,mpdocx);
info update;
}
content_copyCOPY