If you've closely observed a lead record, you may have noticed two system-defined fields: Modified Time and Last Activity Time. These fields are often used to filter leads in views, reports, workflows, and more. The Modified Time field records the timestamp of any changes made to a field in a lead record. In contrast, the Last Activity Time records the timestamp of the most recent activity related to that lead, such as a task, call, meeting, or email, along with any changes made to its fields.
As a result, both fields may display the same date and time, even without any actual user interaction. Additionally, it can disrupt workflows and other automations set up for the Leads module, making it difficult for businesses to track genuine user interactions or any lack thereof. Luckily, there's a way to streamline this process.
All you need to do is write a function that updates a custom date/time field in a lead record with a timestamp whenever a specific action is performed in its related module, such as closing a task. By replicating this function for other activities, like completing a call or checking out of a meeting, you can maintain a truly accurate Last Real Activity Time. Read on to learn more.
Permissions and availability
- Users with the Modules Customization permission can add custom fields.
- Users with the Manage Automation permission can create and update workflow rules.
- Users with the Manage Extensibility permission can create custom functions.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Add a Date/Time field in the Leads module. This field will hold the real last activity time of a lead record. Learn more
- Create a workflow rule for the Tasks module that triggers when creating or editing a task. Learn more
- Write a custom Deluge function and link it with the workflow rule. Learn more
- Test the workflow rule in a sandbox before deploying it to your production environment. Learn more
Add a custom field
The first step is adding the custom date/time field to the Leads module.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Leads module to open the layout editor.
- Drag and drop the Date/Time field from the New Fields tray to the layout.
- Name the date/time field (e.g., "Last Real Activity Time") and define its properties as required.
- Once you have finished, click Save and Close.
Create a workflow rule
Next, you need to write and connect a custom function with a workflow rule.
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select Tasks from the module dropdown list.
- Provide a name for the rule. For example: "Record task activity timestamp".
- Add a description (optional), then click Next.
- In the Execute this workflow rule based on section, choose Record Action, then select Create or Edit from the dropdown and click Next.
- In the Which tasks would you like to apply the rule to? section, select All Tasks, then click Next.
- Under Instant Actions, select Function and Write your own.
- Provide a name for the function, as well as a description, if necessary.
- In the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Choose Tasks - Task Id, name it taskid, then click Save.
- Click Save & Execute script.
- Click Save on the workflow rule page.
The code
resp = zoho.crm.getRecordById("Tasks",taskid);
sem = ifnull(resp.get("$se_module"),"");
if(sem == "Leads")
{
upd = zoho.crm.updateRecord("Leads",resp.get("What_Id").get("id"),{"xxxxx":zoho.currenttime.tostring("yyyy-MM-dd'T'HH:mm:ss","GMT+05:30")});
}Notes
- Replace "xxxxx" with the API name of the custom date/time field you added to the Leads module (see the Create a connection section above).
- Make sure to use the accurate API name of the custom date/time field in the code snippet. Learn more
- The code above is an example of how to automatically record the timestamp of a task-related activity in an associated Lead record. You can use this code to record the timestamp of task-related activities in any other module, such as Contacts or Deals, by modifying the module name and parameters.
Bonus
Here are the code snippets for the Calls and Meetings modules that record the timestamps of their activities in the associated Lead record.
resp = zoho.crm.getRecordById("Calls", callid);
sem = ifnull(resp.get("$se_module"),"");
if(sem == "Leads")
{
upd = zoho.crm.updateRecord("Leads",resp.get("What_Id").get("id"),{"xxxxx":zoho.currenttime.tostring("yyyy-MM-dd'T'HH:mm:ss","GMT+05:30")});
}resp = zoho.crm.getRecordById("Events", recid);
sem = ifnull(resp.get("$se_module"),"");
if(sem == "Leads")
{
upd = zoho.crm.updateRecord("Leads",resp.get("What_Id").get("id"),{"xxxxx":zoho.currenttime.tostring("yyyy-MM-dd'T'HH:mm:ss","GMT+05:30")});
}Tips
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
- You can implement a similar solution by recording the actual last activity time of related deals into their account or contact record, allowing you to filter them based on their deal-related activity.
Test the solution
- Navigate to the Tasks module.
- Open a task record associated with a lead.
- On the Task Details page, click Close Task, then click Mark as Completed.
The workflow rule will be triggered. - Click the lead's name from the task to view its details.
- Check whether the lead's Last Real Activity Time field was updated with the timestamp of task closure.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleTasks
- Trigger PointWorkflow Rule
- EditionEnterprise and above
- ComplexityMedium
- Implementation Time30 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST