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.


  • Create a date/time custom field in the Accounts module with the name "Last Visit Date".

Getting started with the function:

  1. Go to Setup > Developer Space > Functions > + Create New Function.
  2. Select Automation as Function type and click Next.
  3. Provide a name for the function. Add a description(optional).
  4. Copy the code given below.
  5. Click Edit Arguments.
  6. Enter the name as eventId and select the type as Int.
  7. Click Save&Execute Script.
  8. 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();
updateResp = zoho.crm.update("Accounts", seid.toLong(), mp);
info mp;
info updateResp;


Adding to the 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" in the "When do you want to execute this rule?".
  5. Select "Create".
  6. Select the Condition as "All Records".
  7. Select the checkbox "Repeat this workflow whenever a record is edited." and Click Next.
  8. Choose "Function" from Instant Actions.
  9. Select the option "Function" (Created by users from your organization).
  10. Select the required function and click Configure.
  11. Click Save and Associate.
  12. Save the workflow.


  • 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!

Return to Tips