Values from dropdown array

Hi there,

i can’t find a solution how to list values of an array of linked table and summ values for same categories.

var ContractID ="2022001";
const result_items = await doo.table.getData('documentsItems', {filter: [ 
   {field: "DI_contractID.CON_contractNo", operator: "in", value: ContractID}
], filterOperator: "and"});

var itemCategory = result_items.data[0].fields.DI_itemCategory;
var itemArray = result_items.data;
const arrayLength = result_items.data.length;
var Total = 0;

for (var i=0; i<result_items.data.length; i++){
    // THERE I NEED TO DO IF ARRAY VALUE IS EQUAL TO CATEGORY 1, 2, ..., x - SUMM ALL VALUES FROM FIELD "TOTAL" AND MULTIPLE WITH SOME COEFFICIENT 
}

In table Documents items I have dropdown with some categories and for each category I need values from each record of same category and save it as summ to table Documents

Problem is that I need to split these categories because each one I need to multiple with different coefficient.

I could create an extra field for each category - but it’s not good solution because categories can be add by time and I really do not want to have need to edit code again…

Thanks.

Hi Thomas,
It is slightly difficult for me to answer without any knowledge of your data.
Depends on how many rows we talk about etc.
I would not filter the query. Maybe you can loop all data and summarize them.
I would create an empty object. While going through data, you can summarize the data to the object;
before lop

let emptyCat = {};

in the for loop

const categoryName = ....fields.DI_itemCategory
emptyCat[categoryName] = emptyCat[categoryName] || { sum: 0, count: 0 };
emptyCat[categoryName].sum += yourValue;
emptyCat[categoryName].count++;
// console.log('emptyCat ', emptyCat);

So at the end of the loop you have an object with summaries and counts. And you can process the values.
Best regards
Michal