Create Activities for records 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 function:

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

  1. Go to Setup > Automations > Actions > Functions > Configure Function > Write your own.
  2. Provide a name for the function. For example: "Auto Update Tasks from related lists".
  3. Select the moduleto be associated as Tasks. Add a description(optional).
  4. Copy the code given below.
  5. Click "Edit arguments".
  6. Enter the name as "dealId" and select the value as "Deal Id".
  7. Click Save & Execute Script.
  8. Save the changes.

The code:

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;

Note:

  • This function code works only when you have the latest version of Zoho CRM's APIs.
  • 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 us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips