Page 2 of 2

Create a Total from database items

Posted: Fri Dec 13, 2013 6:02 pm
by Nathan Grossman

Thank you. This worked perfectly and I was able to solve my problem


Create a Total from database items

Posted: Sat Jun 14, 2014 7:04 am
by Lonlon

I tried the server code above and it works.

May I know how to filter the amount rather than get the total value of all entry it will filter the value inputed by specific userID. Thank you.


Create a Total from database items

Posted: Sat Jun 14, 2014 9:03 am
by obullei

Hello Lonlon!

Please look here: http://devcenter.appery.io/documentat...

Here you will find information, that you need.


Create a Total from database items

Posted: Sat Jun 14, 2014 9:34 am
by Lonlon

Hi Arina,

Is it for server code? Do you have sample code like what Maryna Brodina gave.

Thank you.


Create a Total from database items

Posted: Sun Jun 15, 2014 6:42 pm
by Alena Prykhodko

Hello Lonlon,

Please read more about passing parameters to the script for Get method here http://devcenter.appery.io/documentat... (if you want to use Server Code)
Also you can retrieve filtered data with Database Query Service (http://devcenter.appery.io/documentat..., you can find more about queries here http://devcenter.appery.io/documentat...)


Create a Total from database items

Posted: Mon Jun 16, 2014 9:53 pm
by Lonlon

Hi Arina,

I included additional variable params as a criteria. It works!

var DB_id='xxxxxxxxxxxxxxxxxx',
collectionName='test',
columnName = 'amount',
location = request.get("locationId");

var params = {}; //Define parameters object
params.criteria = { 'location': locationId //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[columnName]);
if (value) {
sum += value;
}
}
response.success({totalSum: sum}, "application/json");
} catch (e) {
response.success({message: e.message, code: e.code}, "application/json");
}


Create a Total from database items

Posted: Mon Jun 16, 2014 10:06 pm
by Alena Prykhodko

Thank you for sharing that :)