Skip to main content

I’m trying to write a script for an automation that creates a list of all the companies which bought a certain material. (input.config() has two variables: materialUsed and recordID)


However, I want the output pushed onto the Contact field which is in the record (which itself is a link to the “Companies” table).


In short, when I add a new record, I want the Contact field to autopopulate with the links to all the relevant companies.


The output.set displays an array of the correct companies, but I can’t seem to figure out how to push each of the results using the updateRecordAsync().


Thank you.


// query for all the records in a table
let table = base.getTable("Companies");
let searchPO = base.getTable("SearchPO");
let materialsBought = table.getField("Materials Bought")
var material = input.config();
let result = await table.selectRecordsAsync();
// print ID & "Company" from each record:

let records;
records = result.records.filter(record => record.getCellValue('Materials Bought').includes(material.materialUsedr0]));
var companyList = y]
for (let record of records) {
companyList.push(record.getCellValueAsString("Company Name"))
await searchPO.updateRecordAsync(material.recordID, {
"Contact": n{id:record.id}],
})
}
output.set("CompanyList", companyList)

Not much of an expert Airtabler here, but I’ll give it a try.


I think you need to take the update out of the companyList building loop.

You want to update "Contact": companyList once the list is complete.

As it is, Contact seems to be overwritten with each company, rather than extended.


Reply