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.




                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation
                                        • Sticky Posts

                                        • Zoho CRM Functions 53: Automatically name your Deals during lead conversion.

                                          Welcome back everyone! Last week's function was about automatically updating the recent Event date in the Accounts module. This week, it's going to be about automatically giving a custom Deal name whenever a lead is converted. Business scenario Deals are the most important records in CRM. After successful prospecting, the sales cycle is followed by deal creation, follow-up, and its subsequent closure. Being a critical function of your sales cycle, it's good to follow certain best practices. One such
                                        • Custom Function : Automatically send the Quote to the related contact

                                          Scenario: Automatically send the Quote to the related contact.  We create Quotes for customers regularly and when we want to send the quote to the customer, we have to send it manually. We can automate this, using Custom Functions. Based on a criteria, you can trigger a workflow rule and the custom function associated to the rule and automatically send the quote to customer through an email. Please note that the quote will be sent as an inline email content and not as a PDF attachment. Please follow
                                        • Function #50: Schedule Calls to records

                                          Welcome back everyone! Last week's function was about changing ownership of multiple records concurrently. This week, it's going to be about scheduling calls for records in various modules. Business scenario Calls are an integral part of most sales routines.. Sales, Management, Support, all the branches of the business structure would work in cohesion only through calls. You could say they are akin to engine oil, which is required by the engine to make all of it's components function perfectly. CRM
                                        • Function #37: Create a Purchase Order from a Quote

                                          Welcome back everyone! Last week, we learnt how to calculate the total number of activities for a lead and further take note of the activity count for particular dates. For instance, from the period of Demo to Negotiation. This week, let's look at a function that lets you create a Purchase Order instantly from a Quote. Business scenario: In any form of business, one of the most important things to do is to document the transactions. Naturally, negotiation, signing an agreement, placing an order,
                                        • Function-2: Round-Robin assignment of records

                                          Welcome back folks! Last week, we saw how to update sales commission in quotes using a custom function. This week, let's see an interesting use case asked by many of you - auto-assignment records by round-robin method. Business scenario: Right now, the solution allows you to auto-assign leads from web form and imported lists. Let us look at a need where you want to auto-assign leads from in-bound calls in a round-robin method, across modules. Prerequisite: You must create a permanent record in the


                                        Manage your brands on social media



                                              Zoho TeamInbox Resources

                                                Zoho DataPrep Resources



                                                  Zoho CRM Plus Resources

                                                    Zoho Books Resources


                                                      Zoho Subscriptions Resources

                                                        Zoho Projects Resources


                                                          Zoho Sprints Resources


                                                            Qntrl Resources


                                                              Zoho Creator Resources


                                                                Zoho WorkDrive Resources



                                                                  Zoho Campaigns Resources

                                                                    Zoho CRM Resources

                                                                    • CRM Community Learning Series

                                                                      CRM Community Learning Series


                                                                    • Tips

                                                                      Tips

                                                                    • Functions

                                                                      Functions

                                                                    • Meetups

                                                                      Meetups

                                                                    • Kbase

                                                                      Kbase

                                                                    • Resources

                                                                      Resources

                                                                    • Digest

                                                                      Digest

                                                                    • CRM Marketplace

                                                                      CRM Marketplace

                                                                    • MVP Corner

                                                                      MVP Corner

                                                                    





                                                                    




                                                                        Design. Discuss. Deliver.

                                                                        Create visually engaging stories with Zoho Show.

                                                                        Get Started Now