Automatically update the recent Event date in the Accounts module
Business scenario:
The importance of spending quality time with your clients and prospects cannot be understated. Be it sharing samples or explaining your products and services, meetings go a long way establishing customer trust. Depending on your line of business, the frequency of client meetings might vary.
Meetings can be tracked under the Events section of the Activities module. With multiple events filling up your calendar, it’s important that the event related information be available contextually. One of our customers had an interesting requirement. They wanted to have a custom field in the Accounts module named “Last Visit Date”, and have the latest event date updated in the same. This would help them get an easy view of the most recent meeting with their clients. Workflows cannot be used to meet this requirement. However, the Function I'm sharing this week helps you update the custom field with the recent event date automatically.
Pre-requisites
- Create a date/time custom field in the Accounts module with the name "Last Visit Date".
Getting started with the function:
- Go to Setup > Developer Space > Functions > + Create New Function.
- Select Automation as Function type and click Next.
- Provide a name for the function. Add a description(optional).
- Copy the code given below.
- Click Edit Arguments.
- Enter the name as eventId and select the type as Int.
- Click Save&Execute Script.
- Click Save.
The Code:
eventDetails = zoho.crm.getRecordById("Events",eventId.toLong());
seid = ifnull(eventDetails.get("What_Id"),"").get("id");
semodule = ifnull(eventDetails.get("$se_module"),"");
fromdate = ifnull(eventDetails.get("Start_DateTime"),"").toDate();
if ( semodule == "Accounts")
{
mp = Map();
mp.put("Last_Visit_Date",fromdate);
updateResp = zoho.crm.update("Accounts", seid.toLong(), mp);
info mp;
info updateResp;
}
Adding to the workflow
- Go to Setup > Automation > Workflow Rules.
- Click '+ Create Rule'.
- Select the Module for which this custom function has to be added and give it a name and a description(optional).
- Select "On a record action" in the "When do you want to execute this rule?".
- Select "Create".
- Select the Condition as "All Records".
- Select the checkbox "Repeat this workflow whenever a record is edited." and Click Next.
- Choose "Function" from Instant Actions.
- Select the option "Function" (Created by users from your organization).
- Select the required function and click Configure.
- Click Save and Associate.
- Save the workflow.

Note:
- The Function is applicable only when you create Campaigns in CRM. More on that here.
- The above code works only for API V2.0 and not the previous version.
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!