It looks like you’re using a built-in formula field in Airtable to determine the site name. Your overlay says the name is calculated according to IFTTT, which is a third-party integration service, and which can’t change the contents of a formula field. Just for the sake of clarity, please don’t refer to Airtable formulas as IFTTT. The idea of using IF-THEN logic in formulas and programming has been around a lot longer than the IFTTT service.
Back to your question. If you’re using the web clipper to create those records, you could probably trigger the automation with the “when record created” trigger option. For the script action, set it up to pass the value of the {Calculated site}
field into the script as an input variable named “siteName”, and the triggering record ID as an input variable named “recordID”. With that in place, the following script should work. It will link to a record matching the name from the formula. If it doesn’t find a matching record, it will create one and link to it.
let submissionsTable = base.getTable("Submissions");
let siteTable = base.getTable("Sites");
let sitesQuery = await siteTable.selectRecordsAsync();
let config = input.config();
// Find the matching record
let matched = sitesQuery.records.filter(site => {return site.name === config.siteName});
let siteRecord;
// If a matching record exists, use it; otherwise make a new record
if (matched.length)
siteRecord = matched 0];
else
siteRecord = await siteTable.createRecordAsync({"Name": config.siteName});
await submissionsTable.updateRecordAsync(config.recordID, {"Sites": g{id: siteRecord.id}]});
It looks like you’re using a built-in formula field in Airtable to determine the site name. Your overlay says the name is calculated according to IFTTT, which is a third-party integration service, and which can’t change the contents of a formula field. Just for the sake of clarity, please don’t refer to Airtable formulas as IFTTT. The idea of using IF-THEN logic in formulas and programming has been around a lot longer than the IFTTT service.
Back to your question. If you’re using the web clipper to create those records, you could probably trigger the automation with the “when record created” trigger option. For the script action, set it up to pass the value of the {Calculated site}
field into the script as an input variable named “siteName”, and the triggering record ID as an input variable named “recordID”. With that in place, the following script should work. It will link to a record matching the name from the formula. If it doesn’t find a matching record, it will create one and link to it.
let submissionsTable = base.getTable("Submissions");
let siteTable = base.getTable("Sites");
let sitesQuery = await siteTable.selectRecordsAsync();
let config = input.config();
// Find the matching record
let matched = sitesQuery.records.filter(site => {return site.name === config.siteName});
let siteRecord;
// If a matching record exists, use it; otherwise make a new record
if (matched.length)
siteRecord = matched 0];
else
siteRecord = await siteTable.createRecordAsync({"Name": config.siteName});
await submissionsTable.updateRecordAsync(config.recordID, {"Sites": g{id: siteRecord.id}]});
Amazing, thank you @Justin_Barrett! Worked like a charm.
(I clarified that I refer to the if-then logic, and not the IFTTT service, in the screenshot)