assigning leads to owner based on time of day
We would like to have all leads outside of business hours assigned to person 1. The rest should be assigned to person 2.
- Monday to Friday (day 2 to day 6):
- From 8:30 am to 7:30 pm: leads are assigned to user 4972398000074706001.
- From 7:30 pm to 8:30 am: leads are assigned to user 4972398000081238001.
- Saturday and Sunday (day 1 and day 7): all leads are assigned to user 4972398000081238001
I have the following function, but it doesn't seem to work correctly. Leads are all being assigned to 4972398000081238001.
Can anyone see where I've gone wrong? I am stumped.
- leadDetails = zoho.crm.getRecordById("Leads",input.leadId);
createdtime = ifnull(leadDetails.get("Created_Time"),"");
info createdtime;
if(createdtime != "")
{
createddatetime = createdtime.toTime();
// convert to DateTime object
createdhour = createddatetime.getHour();
createdday = createddatetime.getDayOfWeek();
// 1 = Sunday, 2 = Monday, ..., 7 = Saturday
info createdhour;
info createdday;
if(createdday >= 2 && createdday <= 6)
{
// Monday to Friday
if(createdhour >= 8 && createdhour < 19.5)
{
// 8:30 am to 7:30 pm
owner = 4972398000074706001;
}
else
{
// 7:30 pm to 8:30 am
owner = 4972398000081238001;
}
}
else
{
// Saturday and Sunday
owner = 4972398000081238001;
}
mp = Map();
mp.put("Owner",owner);
update = zoho.crm.updateRecord("Leads",input.leadId.toLong(),mp);
info mp;
info update;
}
else
{
info "Created time is empty.";
}