Function-19: Add leads to campaign records at the click of a button.

Function-19: Add leads to campaign records at the click of a button.


Welcome back everyone!

Last week, we learnt how to update the lead records with the Notes and Activity count. This week, let's look at a custom function that adds the leads to campaign records at the click of a button.

Business scenario:

The Campaigns module in Zoho CRM helps you plan and run promotional campaigns effectively. The campaign record centralizes all the related leads, contacts and deals associated with the campaign. It helps you stay on top of cost, revenue, and the revenue pipeline of all the deals associated with the campaign. Measuring ROI of sales and marketing campaigns becomes much more simpler with effective use of Campaigns.

Sounds easy, right? However, the tricky part is ensuring that your users update the related records in time. This ensures that the revenue accrued and the revenue pipeline reflect properly in the campaign record. This lets you take corrective actions if the campaigns don't perform as expected. Let's say you are running a year-end discount sale targeting customers from specific cities. As the specifications vary based on the city and product, you create multiple campaigns to measure its effectiveness. At the entry level, your users are tasked with two CRM activities - creating the lead records and linking the lead record with their relevant campaign. Business processes should only serve to enhance sales productivity and not derail it :) The custom function shared this week addresses this requirement effectively. It links the lead and campaign records at the click of a button and eliminates the need to link manually every time a lead is created.

The button is placed in the list view page of Leads module. This lets you link multiple leads to a campaign record easily.

Pre-requisites:

  • Create and link the button with the custom function as detailed in the "Getting started with the custom function" section below.
  • To use this custom function for multiple campaigns, clone this custom function and link it with new buttons. Ensure you update the campaign id's accordingly.
  • To link multiple lead records to a campaign, just select the leads from the list view of Leads module and click on the respective campaign button.


Getting started with the custom function:

  1. Go to Setup > Customization > Modules and Fields > Select the 'Leads' module > Links and Buttons > +Create new button .
  2. Provide a name for the button. For example: “[The campaign name]”. Add a description(optional).
  3. Choose List View page from the drop-down list.
  4. Select Writing custom function from the subsequent drop-down.
  5. Provide a name for the custom function. Add a description(optional).
  6. Click “ Free flow scripting ”.
  7. Copy the code given below.
  8. Click “ Edit arguments ”.
  9. Enter the name as “ leadId ” and select the value as “ Lead Id ”.
  10. Create a new argument with the name as " Authtoken " and select the value as " Auth token ".
  11. Save the changes.
  12. Click Save to create the button.
The script:

Code for Version 2.0 API:
 
leadIdsList = input.leadId.toList("|||"); 
campid = "zzzzzzzzzzzzz"; 
for each leadIdStr in leadIdsList 
mp=map();
mp.put("CAMPAIGNID",campid.toLong());
resp = zoho.crm.updateRelatedRecord("Campaigns",campid.toLong(),"Leads",leadIdStr.toLong(),mp);
info resp;
}
return "success"; 

Code for Version 1.0 API:

leadIdsList = input.leadId.toList("|||");
for each leadIdStr in leadIdsList
{
countVal=0;
campid = "zzzzzzzzzzzzz";
paramsmap=map();
paramsmap.put("authtoken","xxxxxxxxxxxxxx");
paramsmap.put("scope","crmapi");
paramsmap.put("relatedModule","Leads");
paramsmap.put("id",campid);
xmlData="<Leads>";
countVal=(countVal + 1);
xmlData=(xmlData + "<row no=\"" + (countVal)) + "\">";
xmlData=xmlData + "<FL val=\"LEADID\">" + leadIdStr + "</FL>";
xmlData=xmlData + "</row>";
xmlData=xmlData + "</Leads>";
paramsmap.put("xmlData",xmlData);
info url;
}
return "success";

Note: 
  • The Campaigns module in Zoho CRM is different from Zoho Campaigns. Zoho Campaigns is a separate email marketing application from Zoho.
  • Change the 'zzzzzzzzzzzzz' to the ID of the campaign. Associating a campaign with a lead requires the campaign ID and not the campaign name.
  • The ID can be found in the URL of the Campaign record. Take a look at the screenshot below for more details.

  • Change the 'xxxxxxxxxxxxxx' to the Authtoken for your CRM.

Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful.

Do check out other custom functions shared in this series here.

See you all next week with another interesting custom function. Ciao!

Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this announcement for more. We've updated the post to include the Version 2.0 compatible Function.