Cross-module record conversion can be mind-numbing if done manually, especially when you’re dealing with a list of records. Don’t you wish that you can convert records from any one module to another in Zoho CRM in a single click of a button like the “Convert” button in Leads? Well, we’ll show you how you can build one that even works for custom modules!
Some of you may think “I don’t need to know this cause I’ll never need to do record conversions”. Before you hit the back button, it might interest you to know that some parts of this article can be useful to you, like how to convert related lists, activities, move attachment, notes and more. While I still have you here, let’s dive in!
Cool Ideas to use the Code
Here are some cool ideas on ways you can use the code in Zoho CRM:
//Change below to the relevant old & new modules
oldModule = "Households";
newModule = "Businesses";
oldRecord = zoho.crm.getRecordById(oldModule,recordId);
//Get all Necessary Fields - add/modify as needed
recordName = oldRecord.get("Name");
email = oldRecord.get("Primary_Email");
//Create Record
rMap = Map();
rMap.put("Name",recordName);
rMap.put("Primary_Email",email);
newRecord = zoho.crm.createRecord(newModule, rMap);
newRecordId = newRecord.get("id");
info newRecordId;
allContacts = zoho.crm.getRelatedRecords("Contacts", oldModule, recordId);
for each c in allContacts
{
delete = zoho.crm.updateRecord("Contacts", c.get("id"), {"Household" : ""});
update = zoho.crm.updateRecord("Contacts", c.get("id"), {"Business" : newRecordId});
info delete;
info update;
}
allDeals = zoho.crm.getRelatedRecords("Deals", oldModule, recordId);
if (allDeals.size() > 0)
{
for each d in allDeals
{
delete = zoho.crm.updateRecord("Deals", d.get("id"), {"Household_Name" : ""});
update = zoho.crm.updateRecord("Deals", d.get("id"), {"Business_Name" : newRecordId});
info delete;
info update;
}
}
allNotes = zoho.crm.getRelatedRecords("Notes", oldModule, recordId);
if(allNotes.size() > 0)
{
for each n in allNotes
{
notesMap = {"Parent_Id":newRecordId,"Note_Title":n.get("Note_Title"),"Note_Content":n.get("Note_Content"),"$se_module":newModule};
create = zoho.crm.createRecord("Notes",notesMap);
info create;
}
}
allAct = zoho.crm.getRelatedRecords("Activities", oldModule, recordId);
if (allAct.size() > 0)
{
for each a in allAct
{
idMap = Map();
idMap.put("id",newRecordId);
aMap = Map();
aMap.put("$se_module",newModule);
aMap.put("What_Id",idMap);
updateAct = zoho.crm.updateRecord(a.get("Activity_Type"), a.get("id"), aMap);
info updateAct;
}
}
allPastAct = zoho.crm.getRelatedRecords("Activities_History", oldModule, recordId);
if (allPastAct.size() > 0)
{
for each ap in allPastAct
{
idMap = Map();
idMap.put("id",newRecordId);
aMap = Map();
aMap.put("$se_module",newModule);
aMap.put("What_Id",idMap);
updatePastAct = zoho.crm.updateRecord(ap.get("Activity_Type"), ap.get("id"), aMap);
info updatePastAct;
}
}
attachment = invokeurl
[
url: "https://www.zohoapis.com/crm/v2/"+oldModule+"/"+recordId+"/Attachments"
type: GET
connection: "zohocrm" //Change this to your connection name
];
if (attachment.get("data").size() > 0)
{
for each atm in attachment.get("data")
{
download = invokeurl
[
url: "https://www.zohoapis.com/crm/v2/"+oldModule+"/"+recordId+"/Attachments/"+atm.get("id")
type: GET
connection: "zohocrm" //Change this to your connection name
];
upload = zoho.crm.attachFile(newModule,newRecordId,download);
info upload;
}
}
delete = invokeurl
[
url: "https://www.zohoapis.com/crm/v2/"+oldModule+"?ids="+recordId+"&wf_trigger=true"
type: DELETE
connection: "zohocrm" //Change this to your connection name
];
info delete;
//Change below to the relevant old & new modules
oldModule = "Contacts";
newModule = "Leads";
oldRecord = zoho.crm.getRecordById(oldModule,recordId);
//Get all Necessary Fields and Add to a Map - add/modify as needed
rMap = Map();
rMap.put("First_Name",oldRecord.get("First_Name"));
rMap.put("Last_Name",oldRecord.get("Last_Name"));
rMap.put("Email",oldRecord.get("Email"));
rMap.put("Company",ifNull(oldRecord.get("Account_Name"),{"name":""}).get("name"));
//Create Record
newRecord = zoho.crm.createRecord(newModule,rMap);
newRecordId = newRecord.get("id");
info newRecordId;
//Copy Related Notes
allNotes = zoho.crm.getRelatedRecords("Notes",oldModule,recordId);
if(allNotes.size() > 0)
{
for each n in allNotes
{
notesMap = {"Parent_Id":newRecordId,"Note_Title":n.get("Note_Title"),"Note_Content":n.get("Note_Content"),"$se_module":newModule};
create = zoho.crm.createRecord("Notes",notesMap);
info create;
}
}
//Get and Modify Related Activities
allAct = zoho.crm.getRelatedRecords("Activities",oldModule,recordId);
if(allAct.size() > 0)
{
for each a in allAct
{
idMap = Map();
idMap.put("id",newRecordId);
aMap = Map();
aMap.put("$se_module",newModule);
aMap.put("What_Id",idMap);
aMap.put("Who_Id","");
updateAct = zoho.crm.updateRecord(a.get("Activity_Type"),a.get("id"),aMap);
info "UpdateACT : " + updateAct;
}
}
//Get and Modify Related Closed Activities
allPastAct = zoho.crm.getRelatedRecords("Activities_History",oldModule,recordId);
if(allPastAct.size() > 0)
{
for each ap in allPastAct
{
idMap = Map();
idMap.put("id",newRecordId);
aMap = Map();
aMap.put("$se_module",newModule);
aMap.put("What_Id",idMap);
aMap.put("Who_Id","");
updatePastAct = zoho.crm.updateRecord(ap.get("Activity_Type"),ap.get("id"),aMap);
info "UPDATE PAST ACT : " + updatePastAct;
}
}
//Download & Upload Attachments
attachment = invokeurl
[
url :"https://www.zohoapis.com/crm/v2/" + oldModule + "/" + recordId + "/Attachments"
type :GET
connection:"insert_your_crm_connection_here"
];
if(attachment.get("data").size() > 0)
{
for each atm in attachment.get("data")
{
download = invokeurl
[
url :"https://www.zohoapis.com/crm/v2/" + oldModule + "/" + recordId + "/Attachments/" + atm.get("id")
type :GET
connection:"insert_your_crm_connection_here"
];
upload = zoho.crm.attachFile(newModule,newRecordId,download);
info upload;
}
}
//Delete Related Deals
allDeals = zoho.crm.getRelatedRecords("Deals",oldModule,recordId);
if(allDeals.size() > 0)
{
for each d in allDeals
{
delete = invokeurl
[
url :"https://www.zohoapis.com/crm/v2/Deals?ids=" + d.get("id") + "&wf_trigger=true"
type :DELETE
connection:"insert_your_crm_connection_here"
];
info delete;
}
}
//Deleted Related Account
accountid = ifNull(oldRecord.get("Account_Name"),{"id":"none"}).get("id");
if(accountid != "none")
{
delete = invokeurl
[
url :"https://www.zohoapis.com/crm/v2/Accounts?ids=" + accountid + "&wf_trigger=true"
type :DELETE
connection:"insert_your_crm_connection_here"
];
info delete;
}
//Delete the Old Record
delete = invokeurl
[
url :"https://www.zohoapis.com/crm/v2/" + oldModule + "?ids=" + recordId + "&wf_trigger=true"
type :DELETE
connection:"insert_your_crm_connection_here"
];
info delete;
//Construct success msg
newURL = "https://crm.zoho.com/crm/org707073965/tab/Leads/" + newRecordId;
return "This Contact has been converted back into a Lead here: " + newURL;
Book a free 30-minutes consultation with a Zoho expert or send us an email