String not readable for 'includes' when filtering a

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

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 = => ({
    '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!

1 Reply 1

Hi @Connor_Cash - includes works on an array:

like this:

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

// 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