Custom button - Generate new Deal from Contact record

Custom button - Generate new Deal from Contact record

Hi. I'm trying to streamline the user experience by creating a button that will generate a specific Deal (we have multiple Deal page layouts) and pre-populate it with Contact record information and static text.

It works but only if I run the function independently. Whenever I try to map the function to a button, it stops working. 

My best guess is the function calling within the button looks for a String and I need to pass the Contact ID as an integer. 

Has anyone run into this issue before? Is there a more optimal solution?

For reference, here is my working code (not associated with button):
//contId == Contacts -> Contact ID

contDetails = zoho.crm.getRecordById("Contacts",contId.toLong());
//generate Opp name
dealType = "[CUSTOM NAME]";
acctName = ifnull(contDetails.get("Account_Name").get("name"),contDetails.get("Full_Name"));
//contName = ifnull(contDetails.get("Full_Name"),"");
dealName = dealType + " - " + acctName;
mp = Map();
mp.put("Deal_Name",dealName);
mp.put("Owner",ifnull(contDetails.get("Owner"),"").get("id"));
mp.put("Contact_Name",contId);
mp.put("Account_Name",ifnull(contDetails.get("Account_Name"),"").get("id"));
mp.put("Title",ifnull(contDetails.get("Title"),""));
mp.put("Email",ifnull(contDetails.get("Email"),""));
mp.put("Phone",ifnull(contDetails.get("Phone"),""));
mp.put("Mobile",ifnull(contDetails.get("Mobile"),""));
mp.put("Lead_Source",ifnull(contDetails.get("Lead_Source"),""));
mp.put("Email_Opt_Out",ifnull(contDetails.get("Email_Opt_Out"),""));
mp.put("Website",ifnull(contDetails.get("Website"),""));
mp.put("Mailing_Street",ifnull(contDetails.get("Mailing_Street"),""));
mp.put("Mailing_City",ifnull(contDetails.get("Mailing_City"),""));
mp.put("Mailing_State",ifnull(contDetails.get("Mailing_State"),""));
mp.put("Mailing_Zip",ifnull(contDetails.get("Mailing_Zip"),""));
mp.put("Mailing_Country",ifnull(contDetails.get("Mailing_Country"),""));
mp.put("Description",ifnull(contDetails.get("Description"),""));
mp.put("Stage","Prospect");
//create default Closing date for end of next month
mp.put("Closing_Date",today.eomonth(1));
//pass Product-Specific layout as part of the .put
mp.put("Layout",4622861000000522001);
create = zoho.crm.createRecord("Deals",mp);
info create;
TaskDetails = zoho.crm.getRelatedRecords("Tasks","Contacts",contId.toLong());
for each  task in TaskDetails
{
taskmap = Map();
taskmap.put("What_Id",create.get("id"));
taskmap.put("$se_module","Deals");
updatetask = zoho.crm.updateRecord("Tasks",task.get("id"),taskmap);
info updatetask;
}
EventDetails = zoho.crm.getRelatedRecords("Events","Contacts",contId.toLong());
for each  events in EventDetails
{
eventmap = Map();
eventmap.put("What_Id",create.get("id"));
eventmap.put("$se_module","Deals");
updateevent = zoho.crm.updateRecord("Events",events.get("id"),eventmap);
info updateevent;
}
CallDetails = zoho.crm.getRelatedRecords("Calls","Contacts",contId.toLong());
for each  call in CallDetails
{
callmap = Map();
callmap.put("What_Id",create.get("id"));
callmap.put("$se_module","Deals");
updatecall = zoho.crm.updateRecord("Calls",call.get("id"),callmap);
info updatecall;
}



      • Sticky Posts

      • How to Add Users to your Organization in ZohoMail?

        A better clarity so you can create other users to start using Zoho Mail. You can directly Add Users from the Control Panel to your Organization. You can invite users with the existing email address. If the person (user) already uses ZohoCRM, then you can import users from Zoho CRM. You can also import them using a .csv file. (if you are planning to add them in Bulk)  In this topic, We will be discussing on how to Add and Invite users only.  The Import options are self explanatory. ____________________________________________________________________________________________________________