Welcome back everyone!
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-requisite
- Create a date/time custom field in the Accounts module with the name "Last Visit Date".
Getting started with the function
- Go to Setup > Automation > Workflow Rules.
- Click '+ Create Rule'.
- Select the Events Module and give the function a name and a description(optional).
- Select "On a record action".
- Select "Create".
- Select "All events" for the Condition.
- Choose "Function" from Instant Actions.
- Click "+New Function".
- Select "Write your own".
- Give a name for the function and copy the code given below.
- Click on edit Arguments and choose 'Event Id' and name it as 'eventId'.
- Click on "Save and Associate".
- Save the workflow.
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;
}
-----------------------------------------------------------------------------------------------------------------------
Note
- The code given above works only for V2 version of Zoho APIs. Please note that the code WILL NOT work for Version 1.0 APIs.
Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Do check out other functions shared in this series here.
See you all next week with another interesting function. Ciao!