Skip to main content

Hi All - new here and a bit of a novice developer but trying to automate a simple creation of new records in one table when a new record is created in another table. I’ve been trying to mimic a bit of the parent /template script example but my filter function wont read my input variable that is part of the automation.


let listTable = base.getTable('List of Metrics');
let importQuery = await listTable.selectRecordsAsync();
let importRecords = importQuery.records;
let metricsTable = base.getTable('Metrics');
let inputConfig = input.config();
let companySector = inputConfig.companySector;

let imports = importRecords.map(c => ({
'Sector': c.getCellValue('Sector'),
'Stage': c.getCellValue('Stage'),
'Name': c.getCellValue('Name'),
})).filter(x => x.Sector.includes(companySector))

I’m trying to filter the imports by sector, but an error I’m getting is that since companySector is a string it is not compatible and reads as null.


Feel like I’m missing something simple, thanks!

Hi @Connor_Cash - includes works on an array:


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes


like this:


const pets = ['cat', 'dog', 'bat'];

console.log(pets.includes('cat'));
// expected output: true

So I’m guessing that, in your case, x.Sector is not an array, but a string (but I can’t tell from the script - would need to see the base to be sure). If it is a string, you should just be able to test for equality, e.g.


x.Sector == companySector


Reply