Button to Convert all info from contacts to deals (including attachments)

Button to Convert all info from contacts to deals (including attachments)

I am trying to create a button in contacts to convert everything to deals. This way everything can be converted back and forth as needed. The function is below but it seems to not quite work:

continfo = zoho.crm.getRecordById("Contacts",contId.toString());
mp = Map();
mp.put("Last_Name",continfo.get("Last_Name"));
mp.put("First_Name",ifnull(continfo.get("First_Name"),""));
mp.put("Lead_Source",ifnull(continfo.get("Lead_Source"),""));
mp.put("Description",ifnull(continfo.get("Description"),""));
mp.put("Email",ifnull(continfo.get("Email"),""));
mp.put("Mobile",ifnull(continfo.get("Mobile"),""));
mp.put("Phone",ifnull(continfo.get("Phone"),""));
mp.put("Zip_Code",ifnull(continfo.get("Mailing_Zip"),""));
mp.put("State",ifnull(continfo.get("Mailing_State"),""));
mp.put("City",ifnull(continfo.get("Mailing_City"),""));
mp.put("Address",ifnull(continfo.get("Mailing_Street"),""));
mp.put("Deal_Name",ifnull(continfo.get("Contact_Name"),""));
create = zoho.crm.createRecord("Deals",mp);
info mp;
info create;
// Notes
RelatedNotes = zoho.crm.getRelatedRecords("Notes","Contacts",contId.toLong());
for each  note in RelatedNotes
{
 notemap = Map();
 notemap.put("Parent_Id",create.get("id"));
 notemap.put("Note_Content",note.get("Note_Content"));
 notemap.put("Note_Title",note.get("Note_Title"));
 notemap.put("se_module","Deals");
 notecreate = zoho.crm.createRecord("Notes",notemap);
}
// Tasks
reltasks = zoho.crm.getRelatedRecords("Tasks","Contacts",contId.toLong());
for each  task in reltasks
{
 taskmap = Map();
 taskmap.put("What_Id",create.get("id"));
 taskmap.put("$se_module","Deals");
 taskmap.put("Who_Id","");
 updatetask = zoho.crm.updateRecord("Tasks",task.get("id"),taskmap);
 info updatetask;
}
// Events
relevents = zoho.crm.getRelatedRecords("Events","Contacts",contId.toLong());
for each  events in relevents
{
 eventmap = Map();
 eventmap.put("What_Id",create.get("id"));
 eventmap.put("$se_module","Deals");
 eventmap.put("Who_Id","");
 updateevent = zoho.crm.updateRecord("Events",events.get("id"),eventmap);
 info updateevent;
}
// Calls
relcalls = zoho.crm.getRelatedRecords("Calls","Contacts",contId.toLong());
for each  call in relcalls
{
 callmap = Map();
 callmap.put("What_Id",create.get("id"));
 callmap.put("$se_module","Deals");
 callmap.put("Who_Id","");
 updatecall = zoho.crm.updateRecord("Calls",call.get("id"),callmap);
 info updatecall;
}
//Attachments
relatedrcords = zoho.crm.getRelatedRecords("Attachments","Contacts",contId.toLong());
attachid = List();
for each  ele in relatedrcords
{
 attachementId = ele.get("id");
 attachid.add(attachementId);
}
for each  ele in attachid
{
 downloadFile = invokeurl
 [
  url :"https://www.zohoapis.com/crm/v2/Contacts/" + contId + "/Attachments/" + ele
  type :GET
  connection:"test"
 ];
 resp = zoho.crm.attachFile("Deals",create.get("id"),downloadFile);
 info resp;
}
return "Success";