Prerequisite: You must create a permanent record in the specific module, leads in this case and assign that record to the first user in round-robin.
Here’s how you add this custom function to your CRM account:
- Go to Setup>Automations>Actions >Custom Functions > Configure Custom Function > Write your own.
- Enter the name of the Custom function. For example: “Round-robin assignment”.
- Select the module as Quotes. Add a description(optional).
- Click “Free flow scripting”.
- Copy the code given below.
- Click “Edit arguments”.
- Enter the name as “leadId” and select the value as “Lead Id”.
- Click Save.
As you have created a permanent record, this function does the assignment on a round-robin basis without errors. Note that the function won’t work if you don’t create a permanent record .
The code (based on Leads Module):
leadIdStr = input.leadId.toString();
firstRefRecordDetails = zoho.crm.getRecordById("Leads", xxxxxxxxxxxxx);
firstOwner = ifnull(firstRefRecordDetails.get("SMOWNERID"),"");
if (firstOwner = "User_ID_1")
{
UpOwner = "User_ID_2";
}
if (firstOwner = "User_ID_2")
{
UpOwner = "User_ID_1";
}
updatefirstRef = zoho.crm.updateRecord("Leads", "xxxxxxxxxxx", { "SMOWNERID" : UpOwner });
mp = map();
mp.put("SMOWNERID", UpOwner);
updateResp = zoho.crm.updateRecord("Leads", leadIdStr, mp);
info mp;
info updateResp;
Note:
- Replace 'xxxxxxxxxx' with the permanent record id mentioned in the pre-requisite.
- The above code is an example for assigning the records in the Leads module. You can use this code for any other module by changing the module name and parameters.
- Assigning to a user requires the User ID and not the user name. The user ID is found in the Setup page of your CRM. Take a look at the screenshot below for more details.
