Help

Automatically link record based on plain text or formula result

Topic Labels: Scripting extentions
Solved
Jump to Solution
3164 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Karl_L
6 - Interface Innovator
6 - Interface Innovator

I would like to create a workaround for the issue that Linked Records are not available in Automations.

I am collecting lots of URL inputs from colleagues via the web clipper. For a number of reasons I want to link the records to another table automatically, using a script. The idea would be to trigger the script using an Automation.

In short:
I want the title of the Calculated site to be copied into the linked record field Sites
how to link record

I feel like this should be fairly simple but I’m not able to dig into JS :confused:

1 Solution

Accepted Solutions
Justin_Barrett
18 - Pluto
18 - Pluto

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. :slightly_smiling_face:

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": [{id: siteRecord.id}]});

See Solution in Thread

2 Replies 2
Justin_Barrett
18 - Pluto
18 - Pluto

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. :slightly_smiling_face:

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": [{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)