I have a page that displays all of my Budgets and have successfully aggregated the item amounts for the dataset. Unfortunately I am having difficulty displaying the result in Text at the bottom of the page. Here’s what I have so far…
import wixData from ‘wix-data’;
$w.onReady( function () {
//REPEATER CALCULATED FIELDS
$w(‘#ApprovedBudgetDataset’).onReady( ()=> {
$w(‘#repeater1’).forEachItem(updateRepeaterItem);
});
//AGGREGATIONS let filter = wixData.filter().eq(“Status”, “Approved”);
wixData.aggregate(“Budgets”)
.filter(filter)
.limit(1000)
.sum(“ApprovedItemAmount”)
.run()
.then( (results) => { let TotalItemAmount = results.items[0];
console.log(TotalItemAmount);
$w(‘#TotalItemAmount’).text = results.items[0].toString();
});
});
The console confirms the result is correct, and I believe I need a Return in there somewhere. Any guidance would be greatly appreciated.
It looks like you just need to make one little tweak to the assignment line by specifying the summed field name in the item. It’s probably always the same name for a sum: totalSum. To verify, click on the three dots in the console.log. Here’s what mine says:
Thank you for the response @tony-brunsman . Unfortunately I am still have the same issue where the value is not displayed in the input element on the page. Is there something else that could be preventing the value to be displayed?
@tony-brunsman Thank you. I cannot get it to work. Should I be putting this code on the page code, or somewhere else? does the input element need to be connected? Not sure what else to try. I appreciate your help.
@cale Having it in the button click event is fine. The data is loaded at that point, so it should work. Are you still seeing the same thing in the console?