Jan 05, 2022 09:25 AM
Hello
I am trying to find a way to assign the collaborator field in order - Like a TRUE round-robin
We are currently running an automation where status is “Status A” and the Collaborator field is empty
THEN - run this script (below) and update the record.
const collaborators = [
{name: "Person 1"},
{name: "Person 2"},
{name: "Person 3"},
{name: "Person 4"},
{name: "Person 5"}
]
const chosenOne = collaborators[Math.floor(Math.random() * collaborators.length)];
output.set("chosenOne", chosenOne.name)
This automation runs randomly - I need an automation that will assign 1,2,3,4,5 in order and then repeat that order.
Jan 05, 2022 02:03 PM
hi @Meghan_Weeder,
I actually recently worked in a similar use case for a client. He needed to make sure that each of his employees received the same number of tasks (and each new task would be allocated to an employee as soon as it was created). The approach I took is having a rollup field in the employee table that would count the number of tasks that had been assigned to each employee. Then from the script I would check all the employees and check which employee had the lowest number of tasks assigned to him. Then I would assign the task to that employee.
In your case, if the order of the collaborators is also important, you could add a field called “Ranking” or something similar in your collaborators table. Then when the script runs, it would first check for the collaborator with the lowest number of tasks and, in case of a draw, select the member with the lowest/higher ranking.
Hope this helps!
Alessio
Website: alessiomonino.com
Email: alessio.monino@gmail.com
Jan 05, 2022 03:38 PM
Is your collaborator field a linked record field? If not, turning it into a linked record field would enable you to assign the round-robin without using a script at all.
In your collaborators field, have the following fields
When the automation runs,
Note that when picking out the record ids for the Update Record actions, you will have to “make new list” of the values from the “Find records” action.
Note that this will assign collaborators in a circular fashion–it will not identify the collaborator with the fewest tasks. That requires a different logic, and is best done in a script (although there are ways of managing it without a script).
If you want to use a script, I also recommend that you do not hard code your list of collaborators in the script. A good script can to adapt to any number of collaborators being added or removed without having to edit the script.