I’m trying to make a dynamic pivot table.
I’ve made my groupings and I’m now playing around with how I can get this into a table format.
I’m currently trying to create rows to push into my tables array.
I’m trying to do for loop with with a map method inside, however I can’t figure out why my categories returns [undefined, undefined, undefined]?
const table = base.getTable('report');
let tableArray = [];
let queryResult = await table.selectRecordsAsync();
output.inspect(queryResult);
//Row names
let nameArray = []
for (let record of queryResult.records){
//nameArray.push(record.name)
nameArray.push(record.getCellValue('Select Name')[0].name)
};
const uniqueNames = [...new Set(nameArray)];
output.inspect(uniqueNames);
//Coloumn names
let itemsArray = []
for (let record of queryResult.records){
itemsArray.push(record.getCellValue('Working on'))
}
const uniqueItems = [...new Set(itemsArray)]
output.inspect(uniqueItems);
//Make Rows
for(let i=0; i<uniqueNames.length; i++ ){
let categories = uniqueItems.map(record => {`${record}: 'SUM'`});
output.inspect(categories);
}
//Outcome
output.table([
{'Name/Item': 'John', Car: '', Bus: '£34', Scooter: '', '':''},
{'Name/Item': 'Dan', Car: '£32', Scooter: '£70', '':''},
{'Name/Item': 'Theo', Bus: '£90', Car: '£50', '':''},
]);
Output:
-
{recordIds: Array(7), records: Array(7)}
-
:arrow_forward: (3) [“Dan”, “John”, “Theo”]
-
:arrow_forward: (3) [“Car”, “Bus”, “Scooter”]
-
:arrow_forward: (3) [undefined, undefined, undefined]
-
:arrow_forward: (3) [undefined, undefined, undefined]
-
:arrow_forward: (3) [undefined, undefined, undefined]