Function-27: Create Activities for records based on specific criteria.

Function-27: Create Activities for records based on specific criteria.



Welcome back everyone!

Last week, we learnt how to update information between two modules via lookup fields. This week, let's look at a custom function that creates activities automatically based on specific criteria.

Business scenario:

The Workflow Rules feature takes care of most of the automation requirements in Zoho CRM. Some of you might be wondering why is there a need to rely on custom functions, when workflows, blueprints or schedules helps meet most of your requirements. While this is largely true, there are a few requirements which could not be met out-of-the-box using workflows.

Let's take the Activity module for example. It comprises of Tasks, Events and Calls. However, only Tasks can be created upon meeting workflow conditions, whereas Calls and Events cannot be. Sure, you can make the task description as "Make a call to the customer at 5PM in 2 days.". But won't you prefer it to be a lot simpler and productive to automatically create and schedule a Call record in the Activities module? This week's custom function helps you do just that. It allows you to create or schedule Calls and Events for a record through workflows. Include the custom function in the workflow to create Calls and Events that could be triggered either instantly on creation or while editing the records.

Getting started with the custom function:

Scenario : Create follow-up activities for a prospect based on deal stage.

  1. Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own.
  2. Provide a name for the custom function. For example: “Deal Follow-up call”. Add a description(optional).
  3. Select the module as Deal. Add a description (optional).
  4. Click “Free flow scripting”.
  5. Copy the code given below.
  6. Click “Edit arguments”.
  7. Enter the name as “deaId” and select the value as “Deal Id”.
  8. Save the changes.

The script:

Code for Version 2.0 API:

For tasks :
dealDetails = zoho.crm.getRecordById("Deals",input.dealId.toLong());
taskSubject = "Créer BAL pour " + ifnull(dealDetails.get("Account_Name"),"").get("name");
mp=map();
mp.put("Subject",taskSubject);
mp.put("Due_Date",today.toDate());
mp.put("Owner",ifnull(dealDetails.get("Owner"),"").get("id"));
mp.put("What_Id",input.dealId);
mp.put("$se_module","Deals");
mp.put("Stage","Non commencé");
createResp = zoho.crm.create("Tasks",mp);
info mp;
info createResp;

For events :
DealDetails = zoho.crm.getRecordById("Deals", input.dealId);
//info DealDetails;
startdate = ifnull(DealDetails.get("Contract_Start_Date"),"").toString("yyyy-MM-dd");
enddate = ifnull(DealDetails.get("Contract_End_Date"),"").toString("yyyy-MM-dd");
eventmap =map();
eventmap.put("Event_Title",ifnull(DealDetails.get("Deal_Name"),""));
eventmap.put("Who_Id",ifnull(DealDetails.get("Contact_Name"),"").get("id"));
eventmap.put("Owner",ifnull(DealDetails.get("Owner"),"").get("id"));
eventmap.put("What_Id",input.dealId);
eventmap.put("$se_module","Deals");
eventmap.put("Start_DateTime",startdate+"T09:00:00+05:30");
eventmap.put("End_DateTime",enddate+"T10:00:00+05:30");
create1 = zoho.crm.create("Events", eventmap);
info eventmap;
info create1;

For calls :
dealDetails = zoho.crm.getRecordById("Deals", input.dealId);
info ifnull(dealDetails.get("Modified_Time"),"");
modifiedtime = ifnull(dealDetails.get("Modified_Time"),"").toTime("yyyy-MM-dd'T'HH:mm:ss").addDay(1);
mp = map();
mp.put("Subject", "Cold Call");
mp.put("Owner", ifnull(dealDetails.get("Owner"),"").get("id"));
mp.put("Call_Type", "Outbound");
mp.put("se_module", "Deals");
mp.put("What_Id", input.dealId);
mp.put("Call_Start_Time", modifiedtime.toString("yyyy-MM-dd'T'HH:mm:ss+05:30"));
mp.put("which_call", "ScheduleCall");
create = zoho.crm.create("Calls", mp);
info mp;
info create;

Code for Version 1.0 API:

For Tasks:

dealDetails = zoho.crm.getRecordById("Potentials",input.dealId);
mp=map();
mp.put("Subject","No VM Call");
mp.put("Due Date",zoho.currentdate);
mp.put("SMOWNERID",ifnull(dealDetails.get("SMOWNERID"),""));
mp.put("State",ifnull(dealDetails.get("State"),""));
mp.put("Mobile",ifnull(dealDetails.get("Mobile"),""));
mp.put("SEID",input.dealId);
mp.put("SEMODULE","Potentials");
createResp = zoho.crm.create("Tasks",mp);
info createResp;

For Events:

dealDetails = zoho.crm.getRecordById("Potentials", input.dealId);
name = ifnull(dealDetails.get("First Name"),"") + " " + ifnull(dealDetails.get("Last Name"),"") ;
start = ifnull(dealDetails.get("Event Start date"),"").toTime().toString("yyyy-MM-dd 09:00:00");
end = ifnull(dealDetails.get("Event End date"),"").toTime().toString("yyyy-MM-dd 10:00:00");
eventMap = map();
eventMap.put("Subject", name);
eventMap.put("SMOWNERID", ifnull(dealDetails.get("SMOWNERID"),""));
eventMap.put("Start DateTime", start);
eventMap.put("End DateTime", end);
eventMap.put("SEID", input.dealId);
eventMap.put("SEMODULE", "Potentials");
createEvent = zoho.crm.create("Events", eventMap);
info createEvent;

For Calls:

dealDetails = zoho.crm.getRecordById("Potentials", input.dealId);
name = ifnull(dealDetails.get("First Name"),"") + " " + ifnull(dealDetails.get("Last Name"),"") + " - Call ";
created = ifnull(dealDetails.get("Created Time"),"");
time = (created.toDate().addDay(3)).toString("yyyy-MM-dd 10:00:00");
mp = map();
mp.put("Subject", name);
mp.put("Call Type", "Outbound");
mp.put("SEMODULE", "Potentials");
mp.put("SMOWNERID", ifnull(dealDetails.get("SMOWNERID"),""));
mp.put("SEID", input.dealId);
mp.put("Call Start Time", time);
mp.put("whichCall", "ScheduleCall");
create = zoho.crm.create("Calls", mp);
info create;

Adding to a workflow:

  1. Go to Setup > Automation > Workflow Rules.
  2. Click '+ Create Rule'.
  3. Select the Module for which this custom function has to be added and give it a name and a description(optional).
  4. Select "On a record action".
  5. Select "Create or Edit" and click on Next.
  6. Select the Condition as "All Records" and click Next.
  7. Choose "Custom Function" from Instant Actions.
  8. Select the option "Custom Function" (Created by users from your organization).
  9. Select the custom function you just added and click on Configure.
  10. Click on "Save and Associate".
  11. Save the workflow.

Note:

  • You can use the code on any module. Change the name of the module from 'Deals' to whichever module you prefer and update the code accordingly.
  • To schedule the action to be performed after a specific period of time from which the condition is met, select "Scheduled Actions" instead of "Instant Actions".

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.

    Access your files securely from anywhere











                            Zoho Developer Community





                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts



                                                            • 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
                                                            • User Tips: Auto-Create Opportunity/Deal upon Quote Save (PART 1)

                                                              Problem: We use quotes which convert to sales orders but Users / Sales Reps do not create opportunities / deals and go straight to creating a quote. This leads to poor reporting. Implementing this solution improves reporting and makes it easier for users.
                                                            • 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,


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • 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


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ




                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方