Great for leads, approvals and anything else, because you can tell anyone who gets upset that it is a random process!
departmentmgrgroup = zoho.crm.getOrgVariable("departmentmgrgroup"); managergroup = zoho.crm.getOrgVariable("managergroup"); seniormgrgroup = zoho.crm.getOrgVariable("seniormgrgroup");
I saved the Group ID to an Org Variable so I didn’t need to call it every time, and I can get it really easily. I find the Users Group endpoint clunky, especially since it is not available in Zoho Deluge
//Set Lists to hold the IDs of the Users assigned to the groups departList = List(); managerLIst = List(); seniorMap = LIst(); // Start with Department Managers, get the group, and return List of Associated Users departmentManagers = invokeurl [ url :"https://www.zohoapis.com.au/crm/v5/settings/user_groups/" + departmentmgrgroup + "/sources" type :GET connection:"humanpixelcrmusergroups" ]; //Burn the unnecessary parts of the response to allow for a clean loop departmentManagers = departmentManagers.getJSON("sources"); //Set up the loop to get each User ID and add to the List defined earlier for each dmgr in departmentManagers { source = dmgr.getJSON("source").get("id"); departMap.add(source); } Then I randomised the users in the group //Randomise the Department Manager Approver to be assigned lists = departMap; size = lists.size(); for each i in lists { if(size > 0) { random = randomNumber(0,size); lists.add(lists.get(random)); lists.remove(random); size = size - 1; } } // Remove all other Users from the list except random index 0 dmgrapprover = lists.get(0);
And there you have it. You can then assign this person as the owner of the record, and every time it will be completely random from the selected group!