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)