Hello Team,
I have created a Function which should get the
created time and modified time from the lead ID and get the time gap and update the
TimeGap custom field that only accepts string data. The Script is running but the
created time and modified time is not being picked it is taking as null please help.
// Get the lead record
lead = zoho.crm.getRecordById("Leads",leadId);
// Retrieve the created and modified times
createdTime = lead.get("Created Time");
modifiedTime = lead.get("Modified Time");
// Handle potential missing data
if(createdTime != null && modifiedTime != null)
{
// Calculate the time gap in HH:mm:ss format
timegap = createdTime.timeBetween(modifiedTime);
// Extract hours, minutes, and seconds
hoursString = substring(timegap,0,2);
minutes = substring(timegap,3,2);
// Convert hours to long integer
hours = toLong(hoursString);
// Using toLong for conversion
// Calculate days and adjust hours
days = hours / 24;
hours = hours % 24;
// Format the time gap as a string (e.g., "2 days 5 hours 30 minutes")
timegapString = "";
if(days > 0)
{
timegapString = timegapString + days + " day";
if(days > 1)
{
timegapString = timegapString + "s";
}
timegapString = timegapString + " ";
}
if(hours > 0)
{
timegapString = timegapString + hours + " hour";
if(hours > 1)
{
timegapString = timegapString + "s";
}
timegapString = timegapString + " ";
}
timegapString = timegapString + minutes + " minute";
// Update the "Timegap" field with the formatted time gap string
lead.put("Timegap",timegapString);
zoho.crm.updateRecord("Leads",leadId,lead);
}