Trying to use a server code script to add up a column (counts) for the current user for the last 7 days as well as the last 30 days. Have made a number of attempts (reviewing documentation and other community threads) with no luck so I am pasting my original script which successfully sums up all steps for the current user.
Thanks in advance for any suggestions.
var DB_id='xxxx',
collectionName='Counts',
columnNameCounts = 'counts',
username = request.get("username");
var params = {}; //Define parameters object
params.criteria = { 'username': username //Query criteria:
}
try {
query = Collection.query(DB_id, collectionName, params);
var i, len, value, sum = 0;
for(i = 0, len = query.length; i < len; i++) {
value = parseFloat(query[columnNameCounts]);
if (value) {
sum += value;
}
}
response.success({totalSum: sum}, "application/json");
} catch (e) {
response.success({message: e.message, code: e.code}, "application/json");
}