Help

Trying to update linked field in automation scripti

Topic Labels: Scripting extentions
1158 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Ezra_Butler
4 - Data Explorer
4 - Data Explorer

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.materialUsed[0]));
var companyList = []
for (let record of records) {
companyList.push(record.getCellValueAsString("Company Name"))
await searchPO.updateRecordAsync(material.recordID, {
    "Contact": [{id:record.id}],
})
}
output.set("CompanyList", companyList)
1 Reply 1
Grunty
7 - App Architect
7 - App Architect

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.