Adding multiple rows in a many-to-many table after an input

Hello everyone!

I am trying to build an ATS (Applicant Tracking System) using AirTable. I basically have a Candidates table, a Companies table and a Candidate_Company table that links a candidate to a company including other infos such as the recruitment step of the candidate in the company.

Whenever a new candidate is created, I’d like to automatically add rows in the Candidate_Company with the newly created candidate id and the id of all the companies. Same when I add a new company so it automatically add rows in the Candidate_Company with the newly created company id and the id of all the candidates.

From what I’ve understand so far, Automations alone won’t be able to do that, it looks like I’ll have to combine Automations and Scripts, am I right?

Do you have any article or tutorial that could give me some hints on how to proceed?

Thank you! :slight_smile:

I did manage to do it with Automation + script.

Here is the script (sorry for the french table names and missing indentation) :

let inputConfig = input.config();
let posteId = inputConfig[“posteId”];

let postesTable = base.getTable(“Postes”);
let candidatsTable = base.getTable(“Candidats”);
let candidatsPostesTable = base.getTable(“Candidats_Postes”);

let result = await postesTable.selectRecordsAsync();
let postes = result.records;
let poste = postes[0];
for (let posteTemp of postes) {
if (posteTemp.id == posteId) {
poste = posteTemp;
}
}

result = await candidatsTable.selectRecordsAsync();
let candidats = result.records
let candidatsPostes = candidats.map(candidat => ({
fields: {
‘Poste’: [poste],
‘Candidat’: [candidat]
}
}));

while (candidatsPostes.length > 0) {
await candidatsPostesTable.createRecordsAsync(candidatsPostes.slice(0, 50));
candidatsPostes = candidatsPostes.slice(50);
}

2 Likes

Thanks for the script. Your candidates have no choice but to apply to all companies :).

You’re welcome!

In fact, they have :blush:

The point is for us, on the recruitment side, to never forget about a potential match between a candidate and a company :wink:

Once we have examined all criteria, only a few candidate - company tuples are left and then we ask the candidates.

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