Jun 21, 2023 06:36 PM - edited Jun 21, 2023 06:58 PM
Hello,
I'm trying to:
Right now I'm getting 0, so I suspect my filter is off.
Here's the code I've been able to cobble together:
// change these names to pick a view:
let inputConfig = input.config();
const table = base.getTable('Deals');
const view = table.getView('Pipeline Stages 2-4');
const checkedRecords = await view.selectRecordsAsync({fields: [
'Amount',
'fldL0YbZsYuNJJwTP'
]})
.then(queryResult => {
return queryResult.records.filter(record => {
record.getCellValue('fldL0YbZsYuNJJwTP') === inputConfig.Individual;
})
});
let runningTotal = 0;
for (let record of checkedRecords) {
// change the field names here to adapt this script to your base
runningTotal += record.getCellValue('Amount');
}
return runningTotal
And here's a screenshot of the automation step:
Any feedback or support is appreciated, thank you so much!
Jun 21, 2023 07:13 PM
inputConfig.Individual is returning a record ID string. Is the value of fldL0YbZsYuNJJwTP also expected to be a record ID string?
Try inserting
output.set('checkedRecords', checkedRecords)
right before your for loop to see what checkedRecords contains. I'm guessing it's empty.
Jun 22, 2023 02:24 PM
Hi Stephen, appreciate the support!
The output is showing an empty set:
Jun 22, 2023 02:37 PM
So does your field fldL0YbZsYuNJJwTP contain record IDs or some other value? It sounds like the filter here
queryResult.records.filter(record => { record.getCellValue('fldL0YbZsYuNJJwTP') === inputConfig.Individual; })
is removing everything because the value of fldL0YbZsYuNJJwTP is not a record ID or you don't have a record where this field contains the exact record ID that you're filtering on. What does this field look like in your table?
Jun 22, 2023 03:00 PM
It contains the string in an array, per the documentation:
Jun 22, 2023 03:54 PM - edited Jun 22, 2023 06:27 PM
Try this
return queryResult.records.filter(record =>
record.getCellValue('fldL0YbZsYuNJJwTP').includes(inputConfig.Individual)
)