Jun 28, 2023 03:34 AM
Hello all,
I have a database with a list of records representing people that are uploaded every month with new people coming in and people going out.
Each record (people) is assigned to a group of 5 people to share ideas and experience. I did the first repartition where People (ie records) are assigned to specific group but I am stumbling on the automation of the process.
The idea is that now, every time someone is coming in, I can automaticaly update its record with the group he or she is assigned to (meaning assigned to the first group with less than 5 people in it).
I tried numerous formulas and automations without success...did anyone have any suggestion on how I could do so ?
Thanks for your help !
Paul
Jun 28, 2023 06:36 AM
Hmm, do you have an Airtable Pro plan? Does it matter whether you assign the person to the group that has only had 4 users the longest?
Jun 28, 2023 06:40 AM
Hello,
Thank you for your reply ! Yes I do have a pro plan.
No it does not really matter for the duration, the automation could pick any group that has less than 5
Jun 29, 2023 04:17 AM
Roger that. I would suggest:
1. Create a count field in the "Groups" table that displays the number of people linked to the group
2. In the automation that triggers when a new "Person" record gets created, add a "Find Record" action that'll look for all gorups that have <5 people in it
3. Add a "Run script" action with the following code:
const {foundRecords} = input.config()
console.log(foundRecords)
if(foundRecords.length > 0){
output.set("record", foundRecords[0])
}
else{
throw "No groups with less than 5 members"
}
4. Add the input variables on the left so it looks like the following screenshot:
5. Add an "Update record" action that'll update the triggering record's (i.e. the "Person" record) linked field to the "Group" table with the ID from the script step
The script basically pulls the first group from the "Find Record" action if it found any groups that have less than 5 members, and if the "Find Record" action didn't find anything it'll throw an error
If you DM me an invite link I can set it up for you real quick, or we could also do a quick screenshare where I set it up for you too. Best of luck