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