Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Mar 20, 2020 04:21 AM
Im trying to expand the report example, to make my own custom report.
However I’m completely stuck on filtering an array of records that contains a specific name.
I’ve tried a few different things (commented out below), but I don’t seem to get it to work.
I have a table called ‘report’ in that base there is a field called ‘names’ and I want to filter all away all the records that does not contain the value ‘Dan’ in my names field.
I hope someone has time to help an aspiring JS developer.
let tableReport = base.getTable('report')
let filter = 'Dan'
//loadReportRecords
let reportRecords = await tableReport.selectRecordsAsync();
//let filteredRecords = reportRecords.getRecord(reportRecords.recordIds).getCellValue("names")
//let filteredRecords = reportRecords.records.filter(record => record.getCellValue("names")===filter);
/*
let filteredRecords = reportRecords.records.filter(function(reportRecord){
return reportRecord.getCellValue('names') === 'Dan';
});
*/
Mar 20, 2020 10:44 AM
Hi @Stephen_Suen I hope one day I’ll get good at this.
It sounds to me your assumtions are right. However I still get the error saying:
TypeError: reportQuery.filter is not a function
Mar 20, 2020 11:12 AM
reportQuery
in your case is an Object - the Object has an array inside of it called records
. That’s what you are wanting to filter. To access the records you queried, you need to pull them out of the query Object with reportQuery.records
.
So you want:
let reportRecordsForPerson = reportQuery.records.filter(record => {
...
});
Mar 20, 2020 12:13 PM
Ah yes, that was my mistake — I’ve updated the snippet @Kim_Trager1
Mar 23, 2020 04:41 AM
Thank you @Jeremy_Oglesby for pointing out the obvious and make me understand…
I should have tried something like that considering my reportQuery output a bunch of objects.
Mar 23, 2020 04:42 AM
Thank you @Stephen_Suen and thank you for introducing me to the some() method…
Aug 21, 2020 09:06 AM
I had a similar problem and I changed from getCellValue to getCellValueAsString which helped me. I’m not sure I fully understand your use case, but I wanted to offer this potential suggestion,.