How can I randomly assign a collaborator?

We use our AirTable for content management for our blog. I’m looking to randomly assign a collaborator when an article updates in a “For Review” view. Any thoughts on how I might be able to do this?

You could do this with an Automation. Set up a trigger for when a record enters your For Review view. Then add a Run A Script action with a script like this:

const collaborators = base.activeCollaborators
const chosenOne = collaborators[Math.floor(Math.random() * collaborators.length)];

(That script is basically saying “give me a a random number from 0 to the total number of collaborators in the base” and then “give me the name of the collaborator who matches that number”)

Then add and Update Record action. For Record ID use the ID of the record which triggered the automation. Click “Choose field”, select the collaborator field, and use the output from the script step (my example calls the “output variable” chosenOne).


This is awesome @Kamille_Parks. If I’m understanding you correctly, when I run this script, I should be able to keep it focused exclusively on a certain field too?

For example, I have 10 authors and 3 editors, but both use the collaborator fields to assign the work. I want to make sure it’s only the editors are getting pinged on the random assignment. Does that sound right?

Also, do I need to modify that script or is it plug and play?

There are a couple ways to do that. You can either manually assign the list of editors like this:

const collaborators = [
    {name: Editor 1},
    {name: Editor 2},
    {name: Editor 3}

Or, if you have a table where all the collaborators are listed you could set up a filter. That can be done either by selecting a random record from a View of editors, or filtering those records where the value of a SingleSelect field == “editor”. This option is more flexible.

So, rather than collaborator we go with a single select field @Kamille_Parks. Sorry if I’m a little dense on this one, I haven’t yet gotten into scripting and am a bit of a weenie.

Ideally, I stick with the collaborator so I can still have the editors pinged on Slack and Email when it’s ready for their eyes.

No, the second option I was describing is for if you have a table in your base where each collaborator is a record. Each record would have a collaborator field as well as a single select field describing if they are an editor, author, etc. If that isn’t your setup, go with the first option I described.

Cool cool, and which parts of the script would I need to edit to customize it to my table?

(by the way, I really appreciate you taking the time here. I’m really thick on the script side, but am keen to learn)

No part of the script needs to be customized other than you typing in the actual names of the editors.

So {name: Editor 1} would become {name: "Thomas Walker"}, assuming you are in fact an editor. Match names exactly as they appear in the collaborator field (case sensitive).

For the avoidance of doubt, your full script would look like this:

const collaborators = [
    {name: "Thomas Walker"},
    {name: "Jane Doe"},
    {name: "John Doe"}
const chosenOne = collaborators[Math.floor(Math.random() * collaborators.length)];

Hey @Kamille_Parks, sorry to be a pain, but I’m getting the error “output.set is not a main function” when I enter the code. Any thoughts?

That means you’re tying to do this in a Scripting Block. Back in my first reply I explained we are doing this in an Automation which includes a “Run a script” action. This is not the same thing as the Script Block. I know the terminology is confusing.

Ahhhhh! Ok, thank you

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.