In this post I am going to be answering a question from the forums about doing a mass update using the value of another field.
I’ll make up a scenario to make the question more concrete. The issue here is that we’ve got thousands of leads in the CRM that were imported from a spreadsheet. The spreadsheet had the phone number in a different field (let’s call it Fax) so our Leads have phone numbers in the Fax field but not in the Phone field. Now I want to copy the value from Fax to the Phone field. It would be cool if I could use the Mass Update feature but it doesn’t work. If I try entering something like “Fax” or “Business_Phone_Number”, it won’t let me proceed.
To overcome this limitation, we’ll create a “Custom Button.” When you click on the button, it will execute a deluge script custom function.
The first challenge we have is getting the IDs of the leads we selected. Let’s have a look at how lead_ids is structured. If we select a few leads and click the button, we will see that the lead IDs are separated by three pipes
The lead IDs are separated by three pipes (|). Let’s turn this into a list:
Then we will get the fax by entering, fax = lead_record.get(‘Fax’);
lead_id_list = lead_ids.toList("|||");
for each lead_id in lead_id_list {
lead_record = zoho.crm.getRecordById("Leads", lead_id.toLong());
fax = lead_record.get("Fax");
}
Then we’re going to update the Phone field for those leads to be the same as the Fax number.
lead_id_list = lead_ids.toList("|||");
for each lead_id in lead_id_list {
lead_record = zoho.crm.getRecordById("Leads", lead_id.toLong());
fax = lead_record.get("Fax");
update_map = {
"Phone": fax
};
update_resp = zoho.crm.updateRecord("Leads", lead_id.toLong(), update_map);
}
return lead_ids;
In order to try this out, I need to set the fax with a new update.
After that, I click on my button which I called “Handle Multiple”.
It’s going to give me this message because I returned the list of IDs again. You can choose a more meaningful message.
Now, if I look at Phone field for those two leads, it has been updated using what was in the fax. Job done 🙂