Many businesses notice a steady stream of leads during the weekdays, but this tends to slow down towards the end of the week and on weekends. To prevent salespeople from being overwhelmed, these businesses may choose to assign leads generated on weekdays to one group of salespeople and leads generated on weekends to others in a round-robin fashion.
Since this requirement is unique to only a few businesses, we offer low-code tools that you can connect to workflow rules. Our custom function allocates leads created from Monday to Friday to one group, while those created on Saturdays and Sundays are assigned to others.
Permissions and availability
- 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
- Create a permanent record in the Leads module and assign that record to the first user (i.e., User_ID_1) in the code snippet for assignment in a round-robin fashion.
- Create a workflow rule for the Leads module that assigns leads to the right salespeople upon being created. Learn more
- Write a custom Deluge function and link it up with the workflow rule. Learn more
- Test the workflow rule in a sandbox environment before deploying it to your production environment. Learn more
Create a workflow rule
Follow the steps below to create a workflow rule in your Zoho CRM account:
- Go to Setup > Workflow Rules > +Create Rule.
- Set the module as Leads from the dropdown list.
- Provide a name for the rule. For example: "Assign leads to salespeople".
- Add a description (optional) and then click Next.
- In the Execute this workflow rule based on section, choose Record Action, select Create, and then click Next.
- In the Which leads would you like to apply the rule to? section, select All Leads and click Next.
Note: You can also apply the rule to leads received from a specific source, such as a landing page or a campaign. - Under Instant Actions, select Function and then Write your own.
- Give the function a Name and description (optional).
- On the Deluge Script Editor, do the following:
- Copy and paste the code given below.
- Click Edit Arguments.
- Choose Lead Id and name as leadId.
- Choose Lead Created Time and name it createdDate.
- Click Save & Execute Script.
- Click Save on the workflow rule page.
The code
createddate = input.createdDate.toDate().getDayOfWeek().toString();
firstlist = {"2","3","4","5","6"};
// Assign leads created from Monday to Friday
if( firstlist.contains(createddate))
{
firstRefRecordDetails = zoho.crm.getRecordById("Leads", xxxxxxxxxxxxx);
firstOwner = ifnull(firstRefRecordDetails.get("Owner"),"").get("id");
if (firstOwner = "User_ID_1")
{
UpOwner = "User_ID_2";
}
if (firstOwner = "User_ID_2")
{
UpOwner = "User_ID_3";
}
if (firstOwner = "User_ID_3")
{
UpOwner = "User_ID_4";
}
if (firstOwner = "User_ID_4")
{
UpOwner = "User_ID_5";
}
if (firstOwner = "User_ID_5")
{
UpOwner = "User_ID_6";
}
updatefirstRef = zoho.crm.updateRecord("Leads", xxxxxxxxxxxxx, { "Owner" : UpOwner });
updateResp = zoho.crm. updateRecord("Leads", leadId, { "Owner" : UpOwner });
info updateResp;
}
//Assign leads created on Saturday
if( createddate == "7")
{
mp = map();
mp.put("Owner", "User_ID_7");
updateResp = zoho.crm. updateRecord("Leads", leadId, mp);
info mp;
info updateResp;
}
//Assign leads created on Sunday
if ( createddate == "1")
{
firstRefRecordDetails = zoho.crm.getRecordById("Leads", xxxxxxxxxxxxx);
firstOwner = ifnull(firstRefRecordDetails.get("Owner"),"").get("id");
if (firstOwner = "User_ID_1")
{
UpOwner = "User_ID_8";
}
if (firstOwner = "User_ID_8")
{
UpOwner = "User_ID_1";
}
updatefirstRef = zoho.crm. updateRecord("Leads", xxxxxxxxxxxxx, { "Owner" : UpOwner });
updateResp = zoho.crm. updateRecord("Leads", leadId, { "Owner" : UpOwner });
info updateResp;
}
Notes
- Replace 'xxxxxxxxxx' with the record ID of the permanent lead record created in the requirements.
- Assigning to a user requires the User ID and not the user name. You can find the user ID on the Setup page of your CRM.
- Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more
Idea
- If you need to assign leads received on Sundays to two new users, create an additional permanent lead record and assign it to User_ID_8 in the code snippet below. Then, replace 'yyyyyyyyyy' with the record ID of that permanent lead record.
//Assign leads created on Sunday
if ( createddate == "1")
{
firstRefRecordDetails = zoho.crm.getRecordById("Leads", yyyyyyyyyy);
firstOwner = ifnull(firstRefRecordDetails.get("Owner"),"").get("id");
if (firstOwner = "User_ID_8")
{
UpOwner = "User_ID_9";
}
if (firstOwner = "User_ID_9")
{
UpOwner = "User_ID_8";
}
updatefirstRef = zoho.crm. updateRecord("Leads", yyyyyyyyyy, { "Owner" : UpOwner });
updateResp = zoho.crm. updateRecord("Leads", leadId, { "Owner" : UpOwner });
info updateResp;
}
Tip
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Go to the webform on your website and complete it as a lead to create a new lead record in your CRM.
The workflow rule will get triggered upon lead creation. - Check if the lead record is assigned to the second user as specified in the round-robin order of the custom function based on the day of the week.
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
- ModuleLeads
- 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