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 script:
Code for Version 2.0 API:
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_1";
}
updatefirstRef = zoho.crm.update("Leads", "xxxxxxxxxxx".toLong(), { "Owner" : UpOwner.toLong() });
info updatefirstRef;
mp = map();
mp.put("Owner", UpOwner.toLong());
updateResp = zoho.crm.update("Leads", leadId.toLong(), mp);
info mp;
info updateResp;
Code for Version 1.0 API:
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: